user_update.py
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from app.util.component.ApiTemplate import ApiTemplate
from app.models import SM3
from .models import *
from app.models import AESHelper
class Api(ApiTemplate):
api_name = "更新用户信息"
def para_check(self):
if not self.para.get("guid"):
raise Exception("guid is null")
return super().para_check()
def process(self):
res = {}
res["result"] = False
try:
user_guid = int(self.para.get("guid"))
obj_value = {"company": "company", "email": "email",
"position": "position", "phone": "phone", "displayname": "displayname"}
userinfo = User.query.filter_by(id=user_guid)
if not userinfo.one_or_none():
res["msg"] = "数据不存在"
else:
# 更新密码要求同时输入pwd/newPwd/reNewPwd
if self.para.__contains__("pwd") or self.para.__contains__("newPwd") or self.para.__contains__("reNewPwd"):
password = SM3.encode(
AESHelper.decode(self.para.get("pwd")))
new_password = SM3.encode(
AESHelper.decode(self.para.get("newPwd")))
re_new_password = SM3.encode(
AESHelper.decode(self.para.get("reNewPwd")))
# validate pwd
if not password:
res["result"] = False
res["msg"] = "无原密码"
return res
if new_password != re_new_password:
res["result"] = False
res["msg"] = "两次输入密码不一致"
return res
if userinfo.first().password != password:
res["result"] = False
res["msg"] = "原密码输入错误"
return res
# 更新密码
userinfo.update({"password": new_password})
# 更新用户基本信息
for key in obj_value:
if self.para.__contains__(obj_value[key]):
value = AESHelper.decode(self.para.get(obj_value[key]))
value = "" if value == "None" or value == "none" else value
userinfo.update({key: value})
db.session.commit()
res["result"] = True
res["msg"] = "更新用户信息成功"
except Exception as e:
db.session.rollback()
raise e
return res
api_doc = {
"tags": ["认证接口"],
"parameters": [
{"name": "guid",
"in": "formData",
"type": "string",
"description": "用户id",
"required": "true"},
{"name": "pwd",
"in": "formData",
"type": "string",
"description": "密码",
"required": ""},
{"name": "newPwd",
"in": "formData",
"type": "string",
"description": "密码",
"required": ""},
{"name": "reNewPwd",
"in": "formData",
"type": "string",
"description": "密码",
"required": ""},
{"name": "company",
"in": "formData",
"type": "string",
"description": "单位",
"required": ""},
{"name": "email",
"in": "formData",
"type": "string",
"description": "邮件",
"required": ""},
{"name": "phone",
"in": "formData",
"type": "string",
"description": "电话",
"required": ""},
{"name": "position",
"in": "formData",
"type": "string",
"description": "职位",
"required": ""},
{"name": "displayname",
"in": "formData",
"type": "string",
"description": "别名",
"required": ""},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}