/
account.py
191 lines (181 loc) · 7.97 KB
/
account.py
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#-*- coding: utf-8 -*-
import MySQLdb
import re
import data
import cnsort
#检查新建帐户信息是否合法
def account_check(account_name, account_sex, account_username, account_work, account_position, account_phone,account_address,account_email,account_department, account_power):
check_result = ""
if len(account_username)==0:
check_result = "请填写 账号名"
return check_result
elif account_name != "user" and account_name !="admin":
check_result = "请选择账号权限"
return check_result
elif len(account_work)==0:
check_result = "请填写 工号"
return check_result
elif len(account_position)==0:
check_result = "请填写职位"
return check_result
elif len(account_phone)!=11 or re.match("[0-9]{11}",account_phone) == None:
check_result = "请检查手机号"
return check_result
elif len(account_address) == 0:
check_result = "请输入住址"
return check_result
elif len(account_email)<8 or re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", account_email) == None:
check_result = "请检查邮箱格式是否正确"
return check_result
elif account_department == 0:
check_result = "请选择所属科室"
return check_result
elif account_power/1000<1 or account_power/1000>3:
check_result = "请选择任务权限"
return check_result
elif account_power%1000/100<1 or account_power%1000/100>3:
check_result = "请选择日程权限"
return check_result
elif account_power%100/10<1 or account_power%100/10>2:
check_result = "请选择修改已保存任务权限"
return check_result
elif account_power%10<1 or account_power%10>2:
check_result = "请选择附件管理权限"
return check_result
else:
check_result = "no error"
return check_result
return "未知错误"
def account_save(account_name, account_sex, account_username, account_work, account_position, account_phone,account_address,account_email,account_department, account_power):
#存储账号信息
#设置默认密码user:123456, admin: admin
if account_name == 'user':
account_password = data.md5('123456')
elif account_name == 'admin':
account_password = data.md5('admin')
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("insert into ACCOUNT \
(account_password, account_name, account_sex, account_username, account_work, account_position, account_phone,account_address,account_email,account_department, account_power)\
value ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');\
"%(account_password, account_name.encode('utf-8'), account_sex.encode('utf-8'), account_username.encode('utf-8'), account_work.encode('utf-8'), account_position.encode('utf-8'), account_phone.encode('utf-8'),account_address.encode('utf-8'),account_email.encode('utf-8'),account_department.encode('utf-8'),account_power))
conn.commit()
conn.close()
def account_list(account_department = '*'):
#搜索对应科室部门的所有账号
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
if account_department != '*':
account_department = int(account_department)
cursor.execute("select * from ACCOUNT where account_department='%s';"%account_department)
elif account_department =='*':
cursor.execute("select account_username from ACCOUNT where account_name='user';")
account_username = cursor.fetchall()
a = []
for i in range(len(account_username)):
a.append(account_username[i]['account_username'])
a = cnsort.cnsort(a)
conn.close()
return a
def account_list_view(account_department = '*'):
#搜索对应科室部门的所有账号
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
if account_department != '*':
cursor.execute("select * from ACCOUNT where account_department='%s';"%account_department)
elif account_department =='*':
cursor.execute("select * from ACCOUNT where account_name='user';")
a = cursor.fetchall()
conn.close()
return a
def account_view(account_id):
#搜索对应account_id所对应的信息
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("select * from ACCOUNT where account_id='%s';"%account_id)
a = cursor.fetchall()
conn.close()
return a
def account_structure(account_name, account_username, account_work, account_email, account_phone, account_position, account_department, account_power):
"'将账户信息存储在字典中'"
a = ({\
'account_name': account_name, \
'account_username': account_username, \
'account_work': account_work, \
'account_email': account_email, \
'account_phone': account_phone, \
'account_position': account_position, \
'account_department': account_department, \
'account_power': account_power \
},)
return a
def account_delete(account_id):
#删除对应account_id的全部信息
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("delete from ACCOUNT where account_id = '%s';"%account_id)
conn.commit()
conn.close()
return "账号删除成功"
def account_update(account_name, account_sex, account_username, account_work, account_position, account_phone,account_address,account_email,account_department, account_power,account_id):
#跟新account_id 对应账号的信息
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("update ACCOUNT set \
account_name = '%s', \
account_sex = '%s',\
account_username = '%s', \
account_work = '%s', \
account_email = '%s', \
account_phone = '%s', \
account_position = '%s', \
account_department = '%s', \
account_address = '%s',\
account_power = '%s' \
where account_id = '%s';"%(account_name.encode('utf-8'), account_sex.encode('utf-8'), account_username.encode('utf-8'), account_work.encode('utf-8'), account_email.encode('utf-8'), account_phone.encode('utf-8'), account_position.encode('utf-8'), account_department.encode('utf-8'),account_address.encode('utf-8'), account_power, account_id))
conn.commit()
conn.close()
def get_account_info(user):
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("SELECT * FROM ACCOUNT WHERE account_username='%s'"%user)
account_info = cursor.fetchone()
return account_info
def save_info(user, args):
c = data.SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute("update ACCOUNT SET \
account_username='%s', \
account_sex = '%s',\
account_phone='%s', \
account_email='%s', \
account_address = '%s'\
WHERE account_id = %s\
;"% (args.username, args.account_sex,args.phone,\
args.email,str(args.account_address).encode('utf-8'), args.id))
conn.commit()
if args.get('oldpasswd'):
if args.get('newpassword1') == args.get('newpassword2'):
passwd = data.checkin(user)
newpassword1 = data.md5(args.get('newpassword1'))
oldpasswd = data.md5(args.get('oldpasswd'))
if oldpasswd == passwd[0]['account_password']:
cursor.execute("update ACCOUNT SET \
account_password = '%s'\
WHERE account_id = '%s'"\
%(newpassword1, args.get('id')))
conn.commit()
else:
return False
else:
return False
conn.close()
return True