forked from HenryHu/pybbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserManager.py
59 lines (49 loc) · 1.49 KB
/
UserManager.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
from UCache import UCache
import User
import UserMemo
import json
from errors import *
class UserManager:
users = {}
@staticmethod
def HandleLogin(svc, username, passwd):
user = UserManager.LoadUser(username)
if (user == None):
raise Unauthorized('Login failed')
if (user.Authorize(passwd)):
session = Session(user, svc.client_address[0])
ret = {}
ret['session'] = session.GetID()
svc.writedata(json.dumps(ret))
else:
raise Unauthorized('Login failed')
@staticmethod
def LoadUser(user):
userec = UCache.GetUser(user)
if (userec == None):
return None
user = userec.userid
if (user not in UserManager.users):
ruser = UserManager.LoadNewUser(user)
if (ruser == None):
return None
UserManager.users[user] = ruser
return UserManager.users[user]
@staticmethod
def LoadUserByUid(uid):
userec = UCache.GetUserByUid(uid)
if userec is None:
return None
user = userec.userid
return UserManager.LoadUser(user)
@staticmethod
def LoadNewUser(user):
userec = UCache.GetUser(user)
if (userec == None):
return None
umemo = UserMemo.UserMemoMgr.LoadUsermemo(user)
if (umemo is None):
return None
ruser = User.User(user, userec, umemo)
return ruser
from Session import Session