def login(request): if request.method != 'GET': raise Http404('Only GET allowed!') email = request.GET.get('email') if not email: mailer.info('Login: no email') return HttpResponseBadRequest('Please, specify your email') try: validate_email(email) except ValidationError: mailer.info('Login: incorrect email: %s', email) return HttpResponseBadRequest('Incorrect email') password = request.GET.get('password') # User session # session_key = request.session.session_key # try: # user_session = UserSession.objects.get(session_key=session_key) # # Unexpected # except UserSession.DoesNotExist: # msg = 'current user session with key=%s does not exist' % session_key # logger.exception(msg) # raise Exception(msg) # except Exception: # logger.exception() # raise # New user if not User.objects.filter(email=email).exists(): mailer.info('User with this email does not exist: email = %s and password = %s', email, password) return HttpResponseBadRequest('User with this email does not exist') user = User.objects.get(email=email) if password == user.password or settings.DEBUG and password == settings.DEBUG_PASSWORD: user_session = get_or_create_session(request, 'login') user_session.set_user(user) user_session.save() # user.generate_password() mailer.info('User signed in with email = %s and password = %s', email, password) return redirect('quast_app.views.index') else: mailer.info('User tried to log in with a wrong password: %s instead of %s for %s', password, user.password, email) return redirect('quast_app.views.index')
def index(request): user_session = get_or_create_session(request, 'index') return index_view(user_session, dict(settings.TEMPLATE_ARGS_BY_DEFAULT), request)
def reports(request): user_session = get_or_create_session(request, 'reports') return reports_view(user_session, dict(settings.TEMPLATE_ARGS_BY_DEFAULT), request)