reg/views.py
changeset 9 e29ecb7819e7
parent 8 e2699e042129
child 10 c52d170969f0
--- a/reg/views.py	Fri Apr 09 16:51:56 2010 +0530
+++ b/reg/views.py	Mon Apr 12 02:57:25 2010 +0530
@@ -116,3 +116,53 @@
 
     return HttpResponse(str(event))
 
+def reset_password(request):
+    """ check for the existance of e-mail.
+    Then call the event.
+    """
+
+    user = request.user
+    if user.is_authenticated():
+        return redirect('/reg')
+
+    if request.method == "POST":
+        form = reg_forms.PasswordResetForm(request.POST)
+        if form.is_valid():
+            email = form.cleaned_data['email']
+            user = User.objects.get(email__iexact=email)
+            new_password = reg_events.reset_password(user)
+            return render_to_response('password_reset.html', {'new_password':new_password})
+        else:
+            return render_to_response('password_reset.html', {'form':form})
+    else:
+        form = reg_forms.PasswordResetForm()
+        return render_to_response('password_reset.html', {'form':form})
+
+def change_password(request):
+    """ check for the password and then set the new password.
+    """
+
+    user = request.user
+    if not user.is_authenticated():
+        return redirect('/reg')
+
+    if request.method == "POST":
+        data = request.POST.copy()
+        data.__setitem__('username', user.username)
+        form = reg_forms.PasswordChangeForm(data)
+        if form.is_valid():
+            new_password = form.cleaned_data['new_password']
+            reg_events.change_password(user, new_password)
+            return render_to_response('password_change.html', {'password_changed': True})
+        else:
+            return render_to_response('password_change.html', {'form':form})
+    else:
+        form = reg_forms.PasswordChangeForm()
+        return render_to_response('password_change.html', {'form':form})
+
+
+
+
+
+
+