77 lines
2.0 KiB
Python
77 lines
2.0 KiB
Python
from flask import Blueprint, request
|
||
|
||
from Modules.AdminUser.UserImpl import UserImpl, EmailVcodeCheckerImpl
|
||
from Modules.AdminUser.UserUtils import UserUtils
|
||
from Utils.ErrorUtil import AttrCheckError
|
||
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
|