Beispiel #1
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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)
            # return redirect(url_for('index'))
        else:
            flash('Wrong username or password', 'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('chat'))
    form = LoginForm()
    if form.validate_on_submit():
        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')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('chat')
        return redirect(next_page)

    return render_template('login.html', title='Sign In', form=form)
Beispiel #3
0
def login():
    form = LoginForm()
    title = "Login Page"
    if form.validate_on_submit():
        try:
            user = User.query.filter_by(username=form.username.data).first()
            if user is None or not user.check_password(form.password.data):
                message = Markup(f"Invalid Username or Password.")
                flash(message)
                return redirect(url_for('login'))
            else:
                login_user(user=user, remember=form.remember_me.data)
                return redirect(url_for('index'))
        except Exception as e:
            message = Markup(f"Error updating task: {e}")
            flash(message)
            return redirect(url_for('login'))

    return render_template("login.html", title=title, form=form)