Beispiel #1
0
 def post(self, request, *args, **kwargs):
     # we should only get here if they submitted the form instead of a token in the URL
     # standard Django form handling here
     form = LoginUserForm(request.POST)
     if form.is_valid():
         user, error_reason = SessionManager.check_user_login(
             username_or_email=request.POST['username_or_email'],
             password=request.POST['password'])
         if not user:
             messages.error(request, error_reason)
             self.context.update({
                 'form': form,
             })
             return HttpResponse(self.template.render(
                 self.context, request))
         else:
             login(request, user)
             messages.success(request, 'Log in successful.')
             request.session['user_is_authenticated'] = True
             if request.session.get('login_redirect_from'):
                 return redirect(request.session.get('login_redirect_from'))
             else:
                 return redirect(reverse(settings.LOGIN_SUCCESS_REDIRECT))
     else:
         messages.error(
             request, 'Something went wrong. Please correct errors below.')
         self.context.update({
             'form': form,
         })
         return HttpResponse(self.template.render(self.context, request))
Beispiel #2
0
 def post(self, request, *args, **kwargs):
     # we should only get here if they submitted the form instead of a token in the URL
     # standard Django form handling here
     if 'password' not in request.POST:
         self.login_stage = 2
         self.context.update({'login_stage': self.login_stage})
         form = LoginEmailForm(request.POST)
         if form.is_valid():
             user = SessionManager.get_user_by_username_or_email(request.POST['email'])
             if not user:
                 messages.error(request, 'Could not find account with that email address.')
             elif not user.password:
                 messages.error(
                     request,
                     (
                         "It looks like you haven't completed your yet. "
                         "If your registration link was lost or is expired, you can "
                         "request a new one."
                     )
                 )
                 self.template = loader.get_template('session_manager/default.html')
                 self.context.update({
                     'form': RegistrationLinkForm(initial={'email': user.email}),
                     'submit_text': 'Re-send Registration Link',
                     'form_action': reverse('session_manager_send_registration_link'),
                     'email': user.email,
                 })
                 return HttpResponse(self.template.render(self.context, request))
             else:
                 self.context.update({
                     'form': LoginPasswordForm(initial={'email': user.email}),
                     'email': user.email,
                 })
                 return HttpResponse(self.template.render(self.context, request))
         else:
             messages.error(request, 'Something went wrong. Please correct errors below.')
             self.context.update({
                 'form': form,
             })
             return HttpResponse(self.template.render(self.context, request))
     else:
         self.login_stage = 3
         self.context.update({'login_stage': self.login_stage})
         form = LoginPasswordForm(request.POST)
         if form.is_valid():
             user, error_reason = SessionManager.check_user_login(
                 username_or_email=request.POST['email'],
                 password=request.POST['password']
             )
             if not user:
                 messages.error(request, error_reason)
                 self.context.update({
                     'form': form,
                 })
                 return HttpResponse(self.template.render(self.context, request))
             else:
                 login(request, user)
                 request.session['user_is_authenticated'] = True
                 if settings.DISPLAY_AUTH_SUCCESS_MESSAGES:
                     messages.success(request, 'Log in successful.')
                 return redirect(reverse(settings.LOGIN_SUCCESS_REDIRECT))
     return HttpResponse(self.template.render(self.context, request))