author | nishanth |
Mon, 12 Apr 2010 02:57:25 +0530 | |
changeset 9 | e29ecb7819e7 |
parent 8 | e2699e042129 |
child 10 | c52d170969f0 |
permissions | -rw-r--r-- |
4 | 1 |
from django.contrib.auth.models import User |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
2 |
from django.contrib.auth import authenticate, login, logout |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
3 |
from django.contrib.auth.decorators import login_required |
2 | 4 |
|
4 | 5 |
from django.shortcuts import render_to_response, redirect |
6 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
7 |
from workshop.reg.models import Event |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
8 |
from workshop.reg import forms as reg_forms |
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
9 |
from workshop.reg import events as reg_events |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
10 |
|
4 | 11 |
from django.http import HttpResponse |
12 |
||
13 |
def homepage(request): |
|
14 |
""" see if the user is active. |
|
15 |
If not, only show the re send activation email link. |
|
16 |
else show all the options in homepage. |
|
17 |
""" |
|
18 |
||
19 |
user = request.user |
|
20 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
21 |
events = Event.objects.all()[:10] |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
22 |
|
4 | 23 |
|
24 |
def user_login(request): |
|
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
25 |
""" get the user object from e-mail and then check for password. |
2 | 26 |
""" |
27 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
28 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
29 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
30 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
31 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
32 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
33 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
34 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
35 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
36 |
password = form.cleaned_data['password'] |
4 | 37 |
username = User.objects.get(email__iexact=email).username |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
38 |
|
4 | 39 |
user = authenticate(username=username, password=password) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
40 |
login(request, user) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
41 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
42 |
else: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
43 |
return render_to_response('login.html', {'form':form}) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
44 |
else: |
4 | 45 |
form = reg_forms.LoginForm() |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
46 |
return render_to_response('login.html', {'form':form}) |
4 | 47 |
|
48 |
def user_logout(request): |
|
49 |
""" simply logout the user and redirect to homepage. |
|
50 |
""" |
|
51 |
||
52 |
logout(request) |
|
53 |
return redirect('/reg') |
|
54 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
55 |
def user_register(request): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
56 |
""" take the credentials like name, college and gender here itself. |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
57 |
""" |
4 | 58 |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
59 |
if request.method == "POST": |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
60 |
form = reg_forms.RegisterForm(request.POST) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
61 |
if form.is_valid(): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
62 |
data = form.cleaned_data |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
63 |
reg_events.create_user(email=data['email'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
64 |
password=data['password'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
65 |
firstname=data['first_name'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
66 |
lastname=data['last_name'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
67 |
gender=data['gender'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
68 |
profession=data['profession'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
69 |
affiliated_to=data['affiliated_to'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
70 |
interests=data['interests'] |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
71 |
) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
72 |
return render_to_response('account_created.html') |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
73 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
74 |
return render_to_response('register.html', {'form':form}) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
75 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
76 |
form = reg_forms.RegisterForm() |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
77 |
return render_to_response('register.html', {'form':form}) |
8 | 78 |
|
79 |
def create_event(request): |
|
80 |
""" see if the user is a staff and only then let him do it. |
|
81 |
""" |
|
82 |
||
83 |
user = request.user |
|
84 |
if user.is_authenticated() and user.is_staff: |
|
85 |
if request.method == "POST": |
|
86 |
form = reg_forms.EventCreateForm(request.POST) |
|
87 |
if form.is_valid(): |
|
88 |
data = form.cleaned_data |
|
89 |
new_event = reg_events.create_event(title=data['title'], |
|
90 |
description=data['description'], |
|
91 |
start_date=data['start_date'], |
|
92 |
stop_date=data['stop_date'], |
|
93 |
created_by=user, |
|
94 |
) |
|
95 |
event_url = "/reg/event/view/%s"%(new_event.key) |
|
96 |
return redirect(event_url) |
|
97 |
else: |
|
98 |
return render_to_response('event_create.html', {'form':form}) |
|
99 |
else: |
|
100 |
form = reg_forms.EventCreateForm() |
|
101 |
return render_to_response('event_create.html', {'form':form}) |
|
102 |
else: |
|
103 |
return redirect('/reg') |
|
104 |
||
105 |
def view_event(request, key): |
|
106 |
""" get the event by its key and display it. |
|
107 |
""" |
|
108 |
||
109 |
user = request.user |
|
110 |
is_guest = False if user.is_authenticated() else True |
|
111 |
||
112 |
try: |
|
113 |
event = Event.objects.get(key__iexact=key) |
|
114 |
except Event.DoesNotExist: |
|
115 |
return HttpResponse("F off") |
|
116 |
||
117 |
return HttpResponse(str(event)) |
|
118 |
||
9 | 119 |
def reset_password(request): |
120 |
""" check for the existance of e-mail. |
|
121 |
Then call the event. |
|
122 |
""" |
|
123 |
||
124 |
user = request.user |
|
125 |
if user.is_authenticated(): |
|
126 |
return redirect('/reg') |
|
127 |
||
128 |
if request.method == "POST": |
|
129 |
form = reg_forms.PasswordResetForm(request.POST) |
|
130 |
if form.is_valid(): |
|
131 |
email = form.cleaned_data['email'] |
|
132 |
user = User.objects.get(email__iexact=email) |
|
133 |
new_password = reg_events.reset_password(user) |
|
134 |
return render_to_response('password_reset.html', {'new_password':new_password}) |
|
135 |
else: |
|
136 |
return render_to_response('password_reset.html', {'form':form}) |
|
137 |
else: |
|
138 |
form = reg_forms.PasswordResetForm() |
|
139 |
return render_to_response('password_reset.html', {'form':form}) |
|
140 |
||
141 |
def change_password(request): |
|
142 |
""" check for the password and then set the new password. |
|
143 |
""" |
|
144 |
||
145 |
user = request.user |
|
146 |
if not user.is_authenticated(): |
|
147 |
return redirect('/reg') |
|
148 |
||
149 |
if request.method == "POST": |
|
150 |
data = request.POST.copy() |
|
151 |
data.__setitem__('username', user.username) |
|
152 |
form = reg_forms.PasswordChangeForm(data) |
|
153 |
if form.is_valid(): |
|
154 |
new_password = form.cleaned_data['new_password'] |
|
155 |
reg_events.change_password(user, new_password) |
|
156 |
return render_to_response('password_change.html', {'password_changed': True}) |
|
157 |
else: |
|
158 |
return render_to_response('password_change.html', {'form':form}) |
|
159 |
else: |
|
160 |
form = reg_forms.PasswordChangeForm() |
|
161 |
return render_to_response('password_change.html', {'form':form}) |
|
162 |
||
163 |
||
164 |
||
165 |
||
166 |
||
167 |
||
168 |