mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-10 18:07:28 +08:00
[Enhance] API user change
- Add a method of API to change the user's info
This commit is contained in:
@@ -70,11 +70,11 @@ def request_json_handle(request, required_keys=[], optional_keys=[]):
|
||||
json_data = loads(
|
||||
b64decode(request.args['query']).decode())
|
||||
else:
|
||||
return view(data, *args, **kwargs)
|
||||
json_data = {}
|
||||
|
||||
for key in required_keys:
|
||||
if key not in json_data:
|
||||
return error_return(PostError('Missing parameter: ' + key, api_error_code=-100))
|
||||
return error_return(PostError(f'Missing parameter: {key}', api_error_code=-100))
|
||||
data[key] = json_data[key]
|
||||
|
||||
for key in optional_keys:
|
||||
|
||||
@@ -6,21 +6,23 @@ default_error = ArcError('Unknown Error')
|
||||
|
||||
CODE_MSG = {
|
||||
0: '',
|
||||
-1: 'See status code',
|
||||
-1: 'See status code', # 基础错误
|
||||
-2: 'No data',
|
||||
-3: 'No data or user',
|
||||
-4: 'No user_id',
|
||||
-100: 'Wrong post data',
|
||||
-5: 'No user_id or user',
|
||||
-100: 'Wrong post data', # 1xx数据错误
|
||||
-101: 'Wrong data type',
|
||||
-102: 'Wrong query parameter',
|
||||
-103: 'Wrong sort parameter',
|
||||
-104: 'Wrong sort order parameter',
|
||||
-200: 'No permission',
|
||||
-200: 'No permission', # 2xx用户相关错误
|
||||
-201: 'Wrong username or password',
|
||||
-202: 'User is banned',
|
||||
-203: 'Username exists',
|
||||
-204: 'Email address exists',
|
||||
-205: 'Too many login attempts',
|
||||
-203: 'Too many login attempts',
|
||||
-210: 'Username exists',
|
||||
-211: 'Email address exists',
|
||||
-212: 'User code exists',
|
||||
-999: 'Unknown error'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from core.error import InputError, NoAccess, NoData
|
||||
from core.score import Potential, UserScoreList
|
||||
from core.sql import Connect, Query, Sql
|
||||
from core.user import UserInfo, UserRegister
|
||||
from core.user import UserChanger, UserInfo, UserRegister
|
||||
from core.api_user import APIUser
|
||||
from flask import Blueprint, request
|
||||
|
||||
@@ -76,6 +76,38 @@ def users_user_get(user, user_id):
|
||||
return success_return(u.to_dict())
|
||||
|
||||
|
||||
@bp.route('/<int:user_id>', methods=['PUT'])
|
||||
@role_required(request, ['change'])
|
||||
@request_json_handle(request, optional_keys=['name', 'password', 'user_code', 'ticket', 'email'])
|
||||
@api_try
|
||||
def users_user_put(data, user, user_id):
|
||||
'''修改一个用户'''
|
||||
with Connect() as c:
|
||||
u = UserChanger(c, user_id)
|
||||
r = {}
|
||||
r['user_id'] = user_id
|
||||
if 'name' in data:
|
||||
u.set_name(data['name'])
|
||||
r['name'] = u.name
|
||||
if 'password' in data:
|
||||
u.set_password(data['password'])
|
||||
r['password'] = u.hash_pwd
|
||||
if 'email' in data:
|
||||
u.set_email(data['email'])
|
||||
r['email'] = u.email
|
||||
if 'user_code' in data:
|
||||
u.set_user_code(data['user_code'])
|
||||
r['user_code'] = u.user_code
|
||||
if 'ticket' in data:
|
||||
if not isinstance(data['ticket'], int):
|
||||
raise InputError('Ticket must be int')
|
||||
u.ticket = data['ticket']
|
||||
r['ticket'] = u.ticket
|
||||
if r:
|
||||
u.update_columns(d=r)
|
||||
return success_return(r)
|
||||
|
||||
|
||||
@bp.route('/<int:user_id>/b30', methods=['GET'])
|
||||
@role_required(request, ['select', 'select_me'])
|
||||
@api_try
|
||||
|
||||
Reference in New Issue
Block a user