Пример #1
0
def signin():
    if current_user.is_authenticated:
        return redirect(url_for('main.main'))

    form = LoginForm()
    if form.validate_on_submit():
        user = form.get_user()
        if user:
            login_user(user)
            return redirect(url_for('main.main'))
    else:
        flash_errors(form)
    return render_template("signin.html", form=form)
Пример #2
0
    def post(self, request):
        form = LoginForm(request, data=request.POST)

        if form.is_valid():
            # Check where should the user be redirected
            next_redirect = request.POST.get('next', '')
            if not is_safe_url(url=next_redirect,
                               allowed_hosts=[request.get_host()]):
                next_redirect = reverse('/')

            auth_login(request, form.get_user())
            messages.info(request, 'Logged in as {}.'.format(request.user))
            return HttpResponseRedirect(next_redirect)

        return render(request, self.template, {'form': form})