Esempio n. 1
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(eth_address=form.eth_address.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('event_index'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Esempio n. 2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():  # if GET it False
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')

    return render_template('login.html', form=form)
Esempio n. 3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = LoginForm()

    # if the data is valid then flash a success prompt
    if form.validate_on_submit():

        # get user email
        user = User.query.filter_by(email=form.email.data).first()

        # User initial page selected before login
        next_page = request.args.get("next")
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)

            # Redirect user to next page if there is any or just home if none
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash("Login failed. Please check your email and password",
                  "danger")
    return render_template('login.html', title="Login", form=form)