#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @Date:2022/07/19 16:34:34 ''' from flask import jsonify, request, Blueprint, g from Common.auth import token_auth from Common.Utils import Utils from db_logic.user import BllUser user_router = Blueprint('user', __name__) @user_router.route("/login", methods=["POST"]) # @token_auth.login_required def user_login(): user_name = request.values.get("user_name") password = request.values.get('password') # user_name = body.user_name # password = body.password user_obj = BllUser().login(user_name=user_name, password=password) if user_obj: return jsonify(Utils.true_return(msg="登陆成功", data={"token":user_obj})) else: return jsonify(Utils.false_return(status=201, msg="登陆失败")) # 修改密码,根据token获取用户信息,接受老密码进行校验,新密码写入 @user_router.route("/update_password", methods=["POST"]) @token_auth.login_required def user_update_password(): old_password = request.values.get("old_password") new_password = request.values.get("new_password") # user_id = g.current_user.use msg_bool, msg_token = BllUser().update_password(g.current_user, old_password=old_password, new_password=new_password) if msg_bool: return jsonify(Utils.true_return(data={"token": msg_token})) else: return jsonify(Utils.false_return(msg=msg_token)) @user_router.route("/get_user_power", methods=["GET"]) @token_auth.login_required def get_user_power(): print(g.current_user.user_id) return jsonify(Utils.true_return())