Backup commit.
[TownSquare.git] / townsquare / model / user.py
blob04b3f137d9823303c0ba5056fa19513cf8b206f3
1 import logging, re, datetime, uuid, hashlib
2 from zlib import crc32
4 from pylons import session, app_globals as g
6 class InvalidAccount(Exception): pass
8 class User(object):
10 def __init__(self, acc):
11 if acc is None or len(acc._id) is 0 or len(acc.idname) is 0:
12 raise InvalidAccount
13 self.account = acc
15 @property
16 def id(self):
17 return str(self.account._id)
18 @property
19 def idname(self):
20 return self.account.idname
21 @property
22 def name(self):
23 return self.account.name
24 @property
25 def url(self):
26 return self.account.idname and '/user/' + self.account.idname or ''
29 def get_current_user():
30 acc_id = session.get('account.id')
31 if acc_id is not None and len(acc_id):
32 acc = g.db.col(Account).find_one(_id=acc_id)
33 return User(acc)
34 return None
36 def user_logged_in():
37 acc_id = session.get('account.id')
38 return acc_id is not None and len(acc_id) is not 0
40 def create_login_url(dest_url):
41 #TODO: implement the redirection parameterization
42 #TODO: session
43 return '/login'
45 def create_logout_url(dest_url):
46 return '/logout'