def user_login(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse("app_home")) if request.method == "POST": form = forms.LoginForm(request.POST) next_page = request.POST.get("next", "/") if form.is_valid(): email = form.cleaned_data["email"] password = form.cleaned_data["password"] user = auth.authenticate(email=email, password=password) if user: auth.login(request, user) if next_page == "/": return HttpResponseRedirect(reverse("user_dashboard")) return HttpResponseRedirect(next_page) else: messages.error( request, "Login failed, the email or password are invalid.") else: messages.error( request, "You need to provide both email and password to login.") else: form = forms.LoginForm() return render(request, "login.html", {"form": form})
def login(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) # if this is a POST request we need to process the form data if request.method == 'POST': form = forms.LoginForm(request.POST) next_ = request.GET.get('next', '/') if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = auth.authenticate(email=email, password=password) if user and user.is_active: auth.login(request, user) resp = HttpResponseRedirect(next_) c_domain = getattr(settings, 'LOGGED_IN_COOKIE_DOMAIN', getattr(settings, 'HACKATHON_DOMAIN', None)) c_key = getattr(settings, 'LOGGED_IN_COOKIE_KEY', None) if c_domain and c_key: try: resp.set_cookie(c_key, 'biene', domain=c_domain, max_age=settings.SESSION_COOKIE_AGE) except: # We don't care if this is not set, we are being cool here! pass return resp else: form.add_error(None, 'Incorrect username or password. Please try again.') else: form = forms.LoginForm() return render(request, 'login.html', {'form': form})
def login(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse("app_dashboard")) if request.method == "POST": form = forms.LoginForm(request.POST) next_page = request.GET.get("next", "/") if form.is_valid(): email = form.cleaned_data["email"] password = form.cleaned_data["password"] user = auth.authenticate(email=email, password=password) if user: auth.login(request, user) if next_page == "/": if user.is_organiser and is_application_to_review(user.id): event = get_next_or_past_event() return HttpResponseRedirect( reverse("event_applicationsreview", kwargs=dict(code=event.code))) return HttpResponseRedirect(reverse("app_dashboard")) return HttpResponseRedirect(next_page) else: messages.error( request, "Login failed, the email or password are invalid!") else: form = forms.LoginForm() return render(request, "login.html", {"form": form})
def login(request): if request.method == 'GET': context = {} login_form = forms.LoginForm() context['login_form'] = login_form context['return_to'] = request.META.get('HTTP_REFERER') context['user'] = request.user return render(request, 'login.html', context) else: login_form = forms.LoginForm(request.POST) if login_form.is_valid(): username = login_form.cleaned_data.get('username') password = login_form.cleaned_data.get('password') user = auth.authenticate(request, username=username, password=password) if user: auth.login(request, user) if request.POST.get('return_to') == 'None': return redirect('/') else: return redirect(request.POST.get('return_to')) else: login_form.add_error(None, '用户名或密码不正确') return render(request, 'login.html', {'login_form': login_form})
def require(request): if request.method == 'POST': form = forms.LoginForm(request.POST) username = request.POST.get('username') password = request.POST.get('password') user = authenticate(request, username=username, password=password) print(request.user.username) if user is not None: logging.info("login success") login(request, user) return HttpResponseRedirect('/online/') else: logging.info("login failed") form.add_error('username', "用户名或密码错误") return render(request, 'login.html', {'form': form}) else: logging.info("try to login") form = forms.LoginForm() return render(request, 'login.html', {'form': form})
def login_user(request): form = forms.LoginForm(request.POST or None) context = { "form": form } if form.is_valid(): username = form.cleaned_data.get("username") password = form.cleaned_data.get("password") user = authenticate(username=username, password=password) if user is None: messages.info(request, "Kullanıcı adı veya Parola Hatalı") return render(request, "user/login.html", context) messages.success(request, "Başarıyla Giriş Yaptınız") login(request, user) return redirect("index") return render(request, "user/login.html", context)
def Login(request): form = forms.LoginForm(request.POST or None) context = {"form": form} if form.is_valid( ): # istek POST ise login formun default clean metodu çağrılacak username = form.cleaned_data.get("username") password = form.cleaned_data.get("password") user = authenticate( username=username, password=password) # bilgiler doğru değilse none döner if user: login(request, user) messages.success(request, "Giriş Yapıldı...") return redirect("index") else: messages.success(request, "Yanlış Kullanıcı Adı Veya Parola...") return render(request, "login.html", context) return render(request, "login.html", context)