-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmodel.py
66 lines (55 loc) · 1.75 KB
/
model.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
from app_instance import logger
from tinydb import TinyDB, Query, where
# class People
# prop name:string 姓名
# prop email:string 邮箱地址
# prop token:string Token
# prop number:string 手机号码
# prop status:int 状态:
# 0: 初始值
# 1: 已发提醒邮件
# 2: 已更新name
# 3: 已生成证书图片
# 4: 已发送证书邮件
def gen_token(seed):
# pass
return seed
class EmailDuplicateException(Exception):
def __init__(self):
pass
def insert_people(email, name, number='', token=None):
db = TinyDB("data.json")
People = Query()
exist_list = db.search(People.email == email)
if len(exist_list):
logger.info('Duplicate entry for key email %s' % email)
db.close()
raise EmailDuplicateException()
if token:
logger.warning('It is not safe to specify the token value. '
'Just let it be None and it will be generated automatically')
else:
token = gen_token(email)
db.insert({"name": name, "email": email, "token": token, "number": number, "status": 0})
db.close()
def get_number(email):
db = TinyDB("data.json")
People = Query()
res = db.search(People.email == email)
db.close()
return res[0]["number"]
def update_status(email, status=1):
db = TinyDB("data.json")
People = Query()
db.update({'status': status}, where("email") == email)
db.close()
def update_name(email, name):
db = TinyDB("data.json")
People = Query()
db.update({'name': name}, where("email") == email)
db.close()
def update_status_and_token(email, status=1, token=""):
db = TinyDB("data.json")
People = Query()
db.update({'status': status,'token': token}, where("email") == email)
db.close()