Пример #1
0
 def post(self, request, *args, **kwargs):
     form = ResetPasswordForm(request.POST)
     if form.is_valid():
         user = User.objects.get(pk=request.POST['user_id'])
         user.set_password(request.POST['password'])
         user.save()
         messages.success(request, 'Your password has been reset. Please log in again to continue.')
         return redirect(reverse(settings.PW_RESET_SUCCESS_REDIRECT))
     self.context.update({'form': form})
     return HttpResponse(self.template.render(self.context, request))
Пример #2
0
 def post(self, request, *args, **kwargs):
     form = ResetPasswordForm(request.POST)
     if form.is_valid():
         user = self.request.user
         user.set_password(request.POST['password'])
         user.save()
         messages.success(request, 'Your password has been reset. Please log in again to continue.')
         request.logout(user)
         return redirect(reverse('session_manager_login'))
     self.context.update({'form': form})
     return HttpResponse(self.template.render(self.context, request))
Пример #3
0
 def post(self, request, *args, **kwargs):
     form = ResetPasswordForm(request.POST)
     # if a valid token was given and the form is valid, reset user's password
     # and redirect to login
     if self.token:
         if self.token.is_valid:
             if form.is_valid():
                 user = SessionManager.get_user_by_id(request.POST['user_id'])
                 user.set_password(request.POST['password'])
                 user.save()
                 messages.success(request, 'Password reset. Please log in to continue.')
                 self.token.delete()
                 return redirect(reverse('session_manager_login'))
         else:
             messages.error(request, 'Token is expired.')
     else:
         messages.error(request, self.token_error_message)
     self.context.update({'form': form})
     return HttpResponse(self.template.render(self.context, request))
Пример #4
0
 def get(self, request, *args, **kwargs):
     # If we find a valid token, show the reset form with the user's ID passed to it
     if self.token:
         if self.token.is_valid:
             form = ResetPasswordForm(initial={'user_id': self.token.user.id})
             self.context.update({'form': form})
         else:
             messages.error(request, 'Token is expired.')
     else:
         messages.error(request, self.token_error_message)
     return HttpResponse(self.template.render(self.context, request))
Пример #5
0
 def get(self, request, *args, **kwargs):
     form = ResetPasswordForm(initial={'user_id': self.request.user.id})
     self.context.update({'form': form})
     return HttpResponse(self.template.render(self.context, request))