app.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:chat_api 作者: hriks 项目源码 文件源码
def login():
    form = LoginForm()
    # Shows login form

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if user.confirmed_email:
                if check_password_hash(user.password, form.password.data):
                    login_user(
                        user,
                        remember=form.remember.data
                    )
                    admin = User.query.filter_by(
                        username=str(user.username)
                    ).first()
                    admin.is_active = True
                    db.session.commit()
                    session['logged'] = 'YES'
                    if current_user:
                        hriks(
                            'SUCCESS! Welcome, you are logged in %s' % (
                                user.username
                            )
                        )
                        return redirect(url_for('index'))
                    return redirect(url_for('login'))
        hriks(
            'WARNING! Invalid Combination,\
            Please check username and password'
        )
        return render_template('login.html', form=form)

    return render_template('login.html', form=form)


# This is Signup form route, it accepts both GET and POST
# request. It renders signup form page using GET and submit
# form using POST request.
# This method also send confirm mail to user
# clicking on which user needs to verify his identity
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号