def login_handler(request): """Login handler. """ if request.user.is_authenticated(): return HttpResponseRedirect(reverse('account.views.index')) if request.method == 'GET': form = forms.LoginForm() else: form = forms.LoginForm(request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) if 'next' in request.GET: return HttpResponseRedirect(request.GET['next']) return HttpResponseRedirect(reverse('account.views.index')) else: messages.add_message(request, messages.ERROR, "Account disabled.") else: messages.add_message(request, messages.ERROR, "Login failed.") return render_to_response('account/login.html', { \ 'form': form, \ }, context_instance=RequestContext(request))
def auth_login(request): if request.method == 'POST': next = request.POST.get('next', '/') remember = request.POST.get("remerberme") form = forms.LoginForm(data=request.POST) if form.is_valid(): user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user is not None: login(request, user) response = redirect(next) if remember: response.set_cookie('username', form.cleaned_data['username'], 7*24*3600) else: response.delete_cookie('username') return response else: print(form.errors) else: next = request.GET.get('next', '/') if 'username' in request.COOKIES: username = request.COOKIES.get('username') checked = 'checked' else: username = '' checked = '' form = forms.LoginForm({'username': username}) return render(request, 'account/login.html', { 'form': form, 'username': username, 'next':next, 'checked':checked})
def post(self, request, org_short_name): org_found = get_object_or_404(account_model.Organization, org_short_name=org_short_name) form = account_form.LoginForm(request.POST or None) err_msg = None if form.is_valid(): user = form.login_request() user_org = user.org if user_org == org_found: if user: login(request, user) if user_org.enrollment_closed: return redirect('home:enrollment-closed') else: return redirect('home:enrolment-form2') else: err_msg = "This user is not associated with {}!".format( org_short_name) variables = { 'form': form, 'org_found': org_found, 'err_msg': err_msg, } return render(request, self.template_name, variables)
def get(self, request): form = account_form.LoginForm() variables = { 'form': form, } return render(request, self.template_name, variables)
def show_login_page(request): template = 'account/login.html' form = forms.LoginForm() return render( request, template, { 'form': form, }, )
def get(self, request, org_short_name): org_found = get_object_or_404(account_model.Organization, org_short_name=org_short_name) form = account_form.LoginForm() variables = { 'form': form, 'org_found': org_found, } return render(request, self.template_name, variables)
def Login(request): if request.method == 'GET': return render(request, 'login.html') else: obj = forms.LoginForm(request.POST) if obj.is_valid(): obj = obj.cleaned_data user = authenticate(request, username=obj['username'], password=obj['password']) userid = User.objects.filter( username=obj['username']).values()[0]['id'] if user is not None: print(userid) login(request, user) return redirect('/booth/') else: return render(request, 'login.html', { 'msg': 'User name or password is wrong, please try again' }) else: return render(request, 'login.html', {'obj': obj})
def login(request): if request.method == 'GET': return show_login_page(request) elif request.method == 'POST': form = forms.LoginForm(request.POST) if not form.is_valid(): return show_login_page(request) username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') try: user = auth.authenticate(username=username, password=password) except User.DoesNotExist: return show_login_page(request) if user is None: return show_login_page(request) elif user.is_active: auth.login(request, user) return HttpResponseRedirect("/jobs/") else: return show_login_page(request)
def post(self, request): form = account_form.LoginForm(request.POST or None) err_msg = None if form.is_valid(): user = form.login_request() is_super_user = user.is_superuser if is_super_user: if user: login(request, user) return redirect('staff:staff-home') else: err_msg = "You are not allowed to login!" variables = { 'form': form, 'err_msg': err_msg, } return render(request, self.template_name, variables)
def create_login_form(): return forms.LoginForm()