-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
53 lines (43 loc) · 1.41 KB
/
model.py
File metadata and controls
53 lines (43 loc) · 1.41 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
# -*- encoding=utf-8 -*-
import web, datetime
import hashlib
db = web.database(dbn='mysql', db='lunch', user='root', pw='wickilaformysql')
def valid_user(user,pwd):
v = {"username":user,"password":hashlib.sha1(pwd).hexdigest()}
users = db.query('select * from user where username=$username and password=$password', v)
if len(users) > 0:
return users[0]
return None
def get_posts():
return db.select('entries', order='id DESC')
def get_post(id):
try:
return db.select('user', where='id=$id', vars=locals())[0]
except IndexError:
return None
def get_user(username):
users = db.select('user',where='username=$username',vars=locals())
if len(users) > 0:
return users[0]
else:
return None
def new_post(title, text):
db.insert('entries',title=title,content=text,posted_on=datetime.datetime.utcnow())
def del_post(id):
db.delete('entries', where="id=$id", vars=locals())
def update_post(id,title,text):
db.update('entries',where="id=$id", vars=locals(), title=title, content=text)
def update_user(username, mobile, adress1, adress2):
db.update('user', where='username=$username', vars=locals(), mobile=mobile, adress1=adress1.encode(), adress2=adress2.encode())
class user():
"""用戶信息"""
def __init__(self,username,email):
self.username = username
self.email = email
self.name = ""
self.gender = 0
self.mark = ""
self.mobile = ""
self.telephone = ""
self.adress1 = ""
self.adress2 = ""