-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiki_db.py
38 lines (29 loc) · 927 Bytes
/
wiki_db.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
from google.appengine.ext import db
import utils
class User(db.Model):
name = db.StringProperty(required = True)
pw_hash = db.StringProperty(required = True)
email = db.StringProperty()
@classmethod
def by_id(cls,uid):
return User.get_by_id(uid)
@classmethod
def by_name(cls,name):
u = User.all().filter('name = ',name).get()
return u
@classmethod
def register(cls,name,pw,email=None):
pw_hash = utils.make_pw_hash(name,pw)
return User(name=name,pw_hash=pw_hash,email=email)
@classmethod
def login(cls,name,pw):
u = cls.by_name(name)
if u and utils.valid_pw(name,pw,u.pw_hash):
return u
class Page(db.Model):
page_id = db.StringProperty(required = True)
html = db.TextProperty()
@classmethod
def by_page_id(cls,name):
p = Page.all().filter('page_id = ',name).get()
return p