zoukankan      html  css  js  c++  java
  • flask的登陆验证

    from flask import Blueprint, request, render_template,redirect, url_for
    from flask_login import login_user, logout_user
    from App.model.models import User
    
    api = Blueprint("user", __name__, url_prefix='')
    
    @api.route("/login", methods=['GET', "POST"])
    def login():
        if request.method == "GET":
            return render_template("login.html")
    
        else:
            username = request.form.get("username")
            password = request.form.get("password")
            if username is None or username == "":
                return render_template("login.html", message="用户名不能为空")
    
            if password is None or password == "":
                return render_template("login.html", message="密码不能为空")
            print("username:{}".format(username))
            print("password:{}".format(password))
    
            print(User.query.all())
            user = User.query.filter(User.username == username).first()
    
            if user is None:
                return render_template("login.html", message="该用户不存在")
            if user.password != password:
                return render_template("login.html", password="密码不正确")
            login_user(user)
            next = request.args.get("next")
            if next is None or next == "":
                return redirect(url_for('shop.shoplist'))
            return redirect(next)
    
    
    @api.route("/logout")
    def logout():
        logout_user()
        return redirect("/login")
    
    
    @api.route("/")
    def index():
        return redirect("/shop/list")
    

      

    全世界的程序员们联合起来吧!
  • 相关阅读:
    iOS 小技巧总结
    iOS 字符串常用编码互相转换
    iOS点击cell查看大图,点击大图还原小图
    Cocoapods配置
    匈牙利匹配
    ISAP网络流
    BZOJ 3262--陌上花开
    android应用找回签名问题jarsigner
    android定位混淆过后的crash问题
    axios++:防止重复提交全局统一拦截
  • 原文地址:https://www.cnblogs.com/chaojiyingxiong/p/15133092.html
Copyright © 2011-2022 走看看