python 03 - Flask认证模块 - 视图处理

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 03 - Flask认证模块 - 视图处理相关的知识,希望对你有一定的参考价值。

# coding: utf-8 
from auth import auth_bp
from flask.views import MethodView
from flask import render_template,flash,redirect,url_for,request
from flask_login import login_user,url_for,redirect
from .forms import RegisterForm, \
                    LoginForm, \
                    ResetPasswdForm, \
                    ForgetPasswordForm, \
                    ResetForgetPasswordForm
class Login(MethodView):
    def __init__(self,**kw):
        super(Login,self).__init__(**kw)
        self.form = LoginForm()

    def get(self):
        return render_template("auth/register.html",title="Register",form=self.form)
    
    def post(self):
        if self.form.validate_on_submit():
            email = self.form.email.data
            user = User.query.filter_by(email=email).first()
            if user is not None and user.verify_password(self.form.password.data):
                login_user(user)
                flash("Login Succeed!")
                next = request.args.get("next")
                if next is None or not next.startwith("/"):
                    next = url_for('index.index')
                return redirect(next)
        flash("invlida username or password")
        return render_template("auth/login.html",title="Login",form=self.form)

以上是关于python 03 - Flask认证模块 - 视图处理的主要内容,如果未能解决你的问题,请参考以下文章

python 04 - Flask认证模块 - 路由处理

python 07 - Flask认证模块 - 验证码/发送邮件

python 02-Flask认证模块 - 数据库设计

ldap+flask+python2实现统一认证里面的那些编码神坑

Flask+vue的Token认证

Python Flask框架-开发简单博客-认证蓝图