summaryrefslogtreecommitdiff
path: root/server/user_session.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/user_session.py')
-rw-r--r--server/user_session.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/server/user_session.py b/server/user_session.py
index d80cedd..55f4853 100644
--- a/server/user_session.py
+++ b/server/user_session.py
@@ -7,7 +7,7 @@ import base64
import random
import db
import server
-from errors.session import NoSuchSession, AuthenticationFailed
+from errors.session import NoSuchSession, AuthenticationFailed, PasswordChangeFailed
import psycopg2.extras
__all__ = ['get_session_by_id', 'get_or_create_session', 'UserSession']
@@ -167,6 +167,22 @@ class UserSession(object):
finally:
db.return_connection(conn)
+ def change_password(self, password):
+ conn = db.get_connection()
+ try:
+ cur = conn.cursor()
+ try:
+ cur.execute('update codeq_user set password = %s where id = %s', (encrypt_password(password), self.uid,))
+ affected = cur.rowcount
+ if affected is None:
+ raise PasswordChangeFailed('Password change failed')
+ finally:
+ cur.close()
+ finally:
+ conn.commit()
+ db.return_connection(conn)
+
+
def send(self, json_obj):
"""Sends a message to the user.
@@ -223,6 +239,7 @@ def authenticate_and_create_session(username, password):
conn.commit()
db.return_connection(conn)
+
def verify_password(plain_password, encrypted_password):
elts = encrypted_password.split('$')
if len(elts) != 4: