Example #1
0
def login():
    if current_user.is_authenticated:
        current_app.logger.info(
            "User is authenticated. Redirect to main page.")

        return redirect(url_for("main.index"))

    form = LoginForm()

    if form.validate_on_submit():
        current_app.logger.info(
            "POST Request hit at /login and form has been validated")
        current_app.logger.info("Checking password...")

        user = User.query.filter_by(username=form.username.data).first()

        if user is not None and bcrypt.check_password_hash(
                user.password, form.password.data):
            current_app.logger.info("Logging in user...")
            login_user(user)

            current_app.logger.info("User logged in")

            return redirect(url_for("users.account"))

    return render_template("login.html", title="Login", form=form)
Example #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        print(user)
        if user is not None and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user)
            return redirect(url_for('users.account'))
    return render_template('login.html', form=form)
Example #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()

        if user is not None and user.confirmed == True and \
        bcrypt.check_password_hash(user.password, form.password.data) and form.otp.data == pyotp.TOTP(user.otp_secret).now():
            login_user(user)
            return redirect(url_for('main.index', username=form.username.data))

    return render_template('login.html', form=form)
Example #4
0
def login():
    form = LoginForm()
    #if all the fields are filled and submitted
    if form.validate_on_submit():
        #search for the user in database
        user = User.query.filter_by(email=form.email.data).first()
        #if the the decrypt password is same as the form submitted password,login;else not
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            #If there is a next page request, redirect to next page
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('main.home'))
        else:   
            flash('Login Unsuccessful. Please check username and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Example #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main_bp.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)

            # this pushes the user to the page they were trying to click on
            # before getting force redirected to the login page
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('main_bp.home'))
        else:
            flash('Login Unsuccessful. Please check username and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Example #6
0
def login():
    form = LoginForm()

    return 'Login'