예제 #1
0
def login():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate():
            found_user = User.query.filter_by(
                username=form.username.data).first()
            if found_user:
                is_authenticated = bcrypt.check_password_hash(
                    found_user.password, form.password.data)
                if is_authenticated:
                    login_user(found_user)
                    flash({
                        'text': "Hello, {}!".format(found_user.username),
                        'status': 'success'
                    })
                    return redirect(url_for('users.show', id=current_user.id))
                else:
                    flash({
                        'text': "Wrong password, please try again.",
                        'status': 'danger'
                    })
            else:
                flash({
                    'text': "Invalid username. Please try again",
                    'status': 'danger'
                })
            return render_template('users/login.html', form=form)
    return render_template('users/login.html', form=form)
예제 #2
0
def login():
    form = LoginForm()
    if request.method == "POST":
        if not form.errors:
            if form.validate():
                found_user = User.query.filter_by(
                    username=form.username.data).first()
                if found_user:
                    authenticated_user = bcrypt.check_password_hash(
                        found_user.password, form.password.data)
                    if authenticated_user:
                        login_user(found_user)
                        flash({
                            'text': "Hello, {}!".format(found_user.username),
                            'status': 'success'
                        })
                        return redirect(url_for('root'))
            flash({'text': "Try again", 'status': 'danger'})
            return render_template('users/login.html', form=form)
        flash({
            'text':
            str(list(form.errors.values())).replace('[', '').replace(']', ''),
            'status':
            'danger'
        })
        return render_template('users/login.html', form=form)
    return render_template('users/login.html', form=form)
예제 #3
0
파일: views.py 프로젝트: bigrobsf/hd
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        authenticated_user = User.authenticate(form.username.data, form.password.data)
        if authenticated_user:
            login_user(authenticated_user)
            return redirect(url_for('users.index'))
        else:
            flash('Invalid login. Please try again.')
            return redirect(url_for('users.login'))
    return render_template('users/login.html', form=form)
예제 #4
0
파일: views.py 프로젝트: JH--/my_rithm
def login_user():
    form = LoginForm(request.form)
    if form.validate():
        authenticated_user = User.authenticate(form.user_name.data,
                                               form.password.data)
        if authenticated_user:
            session["user_id"] = authenticated_user.id
            return redirect(url_for("users.show", id=authenticated_user.id))
        else:
            flash("Invalid Credentials!")
    return render_template("users/login.html", form=form)
예제 #5
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            user = User.authenticate(
                form.data['username'], form.data['password'])
            if user:
                login_user(user)
                flash("You are now logged in!")
                return redirect(url_for('users.users'))
        flash("Invalid Credentials")
    return render_template('users/login.html', form=form)
def login():
    login_form = LoginForm(request.form)
    if request.method == 'POST':
        if login_form.validate():
            user = User.authenticate(request.form.get('username'),
                                     request.form.get('password'))
            if user:
                login_user(user)
                flash('You successfully logged in!', 'alert-success')
                return redirect(url_for('exercises.index'))
        flash('Invalid credentials.', 'alert-warning')
        return redirect(url_for('root'))
    return redirect(url_for('root'))
예제 #7
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            logged_in_user = User.authenticate(form.username.data,
                                               form.password.data)
            if logged_in_user:
                login_user(logged_in_user)
                flash("You are now logged in!")
                return redirect(
                    url_for('locations.new', user_id=logged_in_user.id))
        flash("Invalid Login")
    return render_template('users/login.html', form=form)
예제 #8
0
def login():
    form = LoginForm()
    if request.method == "POST":
        if form.validate():
            found_user = User.authenticate(form.username.data,
                                           form.password.data)
            if found_user:
                login_user(found_user)
                flash({
                    'text': f"Hello, {found_user.username}!",
                    'status': 'success'
                })
                return redirect(url_for('root'))
            flash({'text': "Invalid credentials.", 'status': 'danger'})
            return render_template('users/login.html', form=form)
    return render_template('users/login.html', form=form)
예제 #9
0
def login():
    form = LoginForm()
    if request.method == "POST":
        if form.validate():
            found_user = User.query.filter_by(
                username=form.username.data).first()
            if found_user:
                is_authenticated = bcrypt.check_password_hash(
                    found_user.password, form.password.data)
                if is_authenticated:
                    login_user(found_user)
                    flash({
                        'text': "Hello, {}!".format(found_user.username),
                        'status': 'success'
                    })
                    return redirect(url_for('root'))
            flash({'text': "Invalid credentials.", 'status': 'danger'})
            return render_template('users/login.html', form=form)
    return render_template('users/login.html', form=form)
예제 #10
0
파일: views.py 프로젝트: akam/dota5stack
def login():
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate():
            found_user = User.query.filter(
                func.lower(User.username) == func.lower(
                    form.username.data)).first()
            if found_user:
                is_authenticated = bcrypt.check_password_hash(
                    found_user.password, form.password.data)
                if is_authenticated:
                    login_user(found_user)
                    flash({
                        'text': "Hello, {}!".format(found_user.username),
                        'status': 'success'
                    })
                    return redirect(url_for('root'))
            flash({
                'text': "Incorrect username or password",
                'status': 'warning'
            })
    return render_template('users/login.html', form=form)