-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserManager.py
35 lines (29 loc) · 1.26 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
import hashlib
import RandomStringGenerator
from User import User
def findUserById(session, id):
return session.query(User).filter_by(id=id).first()
def findUserByName(session, name):
return session.query(User).filter_by(name=name).first()
def validateUser(session, user):
userFromDB = findUserByName(session, user.name)
user.password = unicode(hashlib.pbkdf2_hmac('sha256', user.password, userFromDB.salt, 100000), 'unicode-escape')
if (userFromDB != None and user.password == userFromDB.password):
return userFromDB
else:
return None
def removeChatChannelIdForUser(session, userId):
session.query(User).filter_by(id=userId).update({User.currentChatChannelId: None})
session.commit()
def registerNewUser(session, user):
if findUserByName(session, user.name) == None:
user.salt = RandomStringGenerator.generateString()
user.password = unicode(hashlib.pbkdf2_hmac('sha256', user.password, user.salt, 100000), 'unicode-escape')
session.add(user)
session.commit()
return True
else:
return False
def enterChatChannel(session, user, channel_id):
session.query(User).filter_by(id=user.id).update({User.currentChatChannelId: channel_id})
session.commit()