guarantee-admin-api-v0.2/Modules/AdminUser/UserRoutes.py

78 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from flask import Blueprint, request
from Modules.AdminUser.UserImpl1 import UserImpl, EmailVcodeCheckerImpl
from Modules.AdminUser.UserUtils1 import UserUtils
from Utils.ErrorUtil import ReturnConditionCheckFailed, AttrCheckError
from Modules.AdminUser.UserImpl import UserLoginImpl, SendLoginVcodeEmailImpl
from Modules.AdminUser.UserAuthUtils import verify_token, authority_scope
user_route = Blueprint('user', __name__)
@user_route.route('/online_check', methods=['GET'])
@verify_token
def online_check_route(**kwargs):
"""
在线检查检查token是否有效
"""
return {"info": "正常"}, 200
@user_route.route('/create', methods=['POST'])
@verify_token
@authority_scope(['admin'])
def create_user_route(**kwargs):
"""新建用户"""
try:
req = request.json
impl = UserImpl()
impl.create(
req['email'],
req['name'],
UserUtils.decrypt_data(encrypt_msg=req['pwd']),
req['role']
)
return {"info": "用户创建成功"}, 200
except AssertionError as e:
return {"info": e.__str__()}, 202
except AttrCheckError as e:
return {"info": e.__str__()}, 202
@user_route.route('/login', methods=['POST'])
def login_route():
"""登录"""
try:
req = request.json
impl = UserImpl()
result = impl.login(
req['email'],
req['pwd'],
req['vcode']
)
return {"info": "登录成功", "result": result}, 200
except AssertionError as e:
return {"info": e.__str__()}, 202
except AttrCheckError as e:
return {"info": e.__str__()}, 202
@user_route.route('/send_vcode', methods=['POST'])
def send_vcode_to_user_route():
"""发送验证码"""
try:
req = request.json
obj = EmailVcodeCheckerImpl()
obj.email = req['email']
obj.send_vcode_email()
return {"info": "发送成功"}, 200
except AssertionError as e:
return {"info": e.__str__()}, 202
except AttrCheckError as e:
return {"info": e.__str__()}, 202