Python flask实战订餐系统微信小程序-20登录接口的初步实现

wechat xuhss 640℃ 0评论

user.py:

# -*- coding: utf-8 -*-
from flask import Blueprint,render_template,request,jsonify

from common.models.User import User

route_user = Blueprint( 'user_page',__name__ )

@route_user.route( "/login", methods = ["GET", "POST"] )
def login():
    if request.method == "GET":
        return render_template( "user/login.html" )

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    resp = {'code':200, 'msg':'登录成功', 'data':{}}
    if login_name is None or len(login_name)<1:
        resp['code']=-1
        resp['msg']="请输入正确的登录用户名~"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd)<1:
        resp['code']=-1
        resp['msg']="请输入正确的登录密码~"
        return jsonify(resp)

    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码"
        return jsonify(resp)

    return login_name

数据库操作

mysql -uroot -p
use food_db
select * from user;

插入一条数据:

请将下面的SQL语句执行,然后默认登录账号是xuhss.com 密码是123456

INSERT INTO `user` (`uid`, `nickname`, `mobile`, `email`, `sex`, `avatar`, `login_name`, `login_pwd`, `login_salt`, `status`, `updated_time`, `created_time`)
VALUES
    (1, '虚幻私塾xuhss.com', '11012345679', 'xuhss@163.com', 1, '', 'xuhss.com', '816440c40b7a9d55ff9eb7b20760862c', 'cF3JfH5FJfQ8B2Ba', 1, '2021-03-15 14:08:18', '2021-03-15 14:08:18');

20210728195229 - Python flask实战订餐系统微信小程序-20登录接口的初步实现

转载请注明:xuhss » Python flask实战订餐系统微信小程序-20登录接口的初步实现

喜欢 (12)

您必须 登录 才能发表评论!