首次完成数据库登录,注册验证。首次完成,migrate_manager.py迁移多个数据库
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
from route.public import public
|
||||
from route.auth import auth
|
||||
from route.admin import admin
|
||||
|
||||
__all__ = ['public', 'auth', 'admin']
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
from flask import Blueprint, request, render_template
|
||||
|
||||
admin = Blueprint('admin', __name__, url_prefix='/admin')
|
||||
|
||||
|
||||
@admin.route('/', methods=['GET', 'POST'])
|
||||
def admin_index():
|
||||
if request.method == "POST":
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
return render_template("admin/admin_index.html")
|
||||
@@ -0,0 +1,34 @@
|
||||
from flask import Blueprint, request, render_template
|
||||
from model.db import db
|
||||
from model.User import User
|
||||
|
||||
auth = Blueprint('auth', __name__)
|
||||
|
||||
|
||||
@auth.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
user = db.session.execute(db.select(User).where(User.username == username)).scalar()
|
||||
if user is None:
|
||||
return "Username or Password is incorrect"
|
||||
if user.password != password:
|
||||
return "Username or Password is incorrect"
|
||||
# 登录成功
|
||||
return f"Login Successful {username}:{password}"
|
||||
|
||||
return render_template("public/user/login.html")
|
||||
|
||||
|
||||
@auth.route('/register', methods=["POST", "GET"])
|
||||
def register():
|
||||
if request.method == "POST":
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
email = request.form["email"]
|
||||
# return f"Register Successful {username}:{password}:{email}"
|
||||
new_user = User(username=username, password=password, email=email)
|
||||
db.session.add(new_user)
|
||||
db.session.commit()
|
||||
return render_template("public/user/register.html")
|
||||
@@ -0,0 +1,21 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
public = Blueprint('public', __name__)
|
||||
|
||||
|
||||
@public.route('/')
|
||||
def index():
|
||||
return render_template("public/index.html")
|
||||
|
||||
|
||||
@public.route('/about')
|
||||
def about():
|
||||
return render_template("public/about.html")
|
||||
|
||||
@public.route("/terms")
|
||||
def terms():
|
||||
return "terms Page"
|
||||
|
||||
@public.route("/privacy")
|
||||
def privacy():
|
||||
return "privacy Page"
|
||||
Reference in New Issue
Block a user