Пример #1
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            return reditect(request.args.get("next") or url_for("main.index"))
        flash("Invalid username or password")
    return render_template("auth/login.html", form=form)
Пример #2
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, username=form.username.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, "Confirm Your Account", "auth/email/confirm", user=user, token=token)
        flash("A confirmation email has been sent to you by email.")
        return reditect(url_for("main.index"))
    return render_template("auth/register.html", form=form)
Пример #3
0
def logout():
    logout_user()
    flash("You have been logged out.")
    return reditect(url_for("main.index"))