reg/views.py
changeset 9 e29ecb7819e7
parent 8 e2699e042129
child 10 c52d170969f0
equal deleted inserted replaced
8:e2699e042129 9:e29ecb7819e7
   114     except Event.DoesNotExist:
   114     except Event.DoesNotExist:
   115         return HttpResponse("F off")
   115         return HttpResponse("F off")
   116 
   116 
   117     return HttpResponse(str(event))
   117     return HttpResponse(str(event))
   118 
   118 
       
   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