summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Zorko <robertz@gurucue.com>2015-09-29 15:31:42 +0200
committerRobert Zorko <robertz@gurucue.com>2015-09-29 15:31:42 +0200
commit4c376fb2adde669f34c4b17e059e65a174629b54 (patch)
tree9e6b0dabe34e8993d73d66fd4a754ad86494b4ca
parente58c8bd7ea894e28a23a68b664772314720cd879 (diff)
added settings to the user session and the login function now also returns those settings - currently only gui language is implemented. The create.sql script is updated for that change as well.
-rw-r--r--db/create.sql1
-rw-r--r--server/handlers.py3
-rw-r--r--server/user_session.py17
3 files changed, 15 insertions, 6 deletions
diff --git a/db/create.sql b/db/create.sql
index e720238..57c3647 100644
--- a/db/create.sql
+++ b/db/create.sql
@@ -33,6 +33,7 @@ create table codeq_user (
is_active bool not null,
date_joined timestamp not null,
last_login timestamp not null,
+ gui_lang varchar(2),
constraint codeq_user_pk primary key (id),
constraint codeq_user_uq1 unique (username)
);
diff --git a/server/handlers.py b/server/handlers.py
index 08994a0..997e2f2 100644
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -50,7 +50,8 @@ class Login(CodeqService):
else:
if request.session:
request.session.destroy()
- request.reply({'code': 0, 'message': 'OK', 'sid':session.get_sid()})
+ settings = session.get_settings()
+ request.reply({'code': 0, 'message': 'OK', 'sid':session.get_sid(), 'settings':settings})
class Activity(CodeqService):
diff --git a/server/user_session.py b/server/user_session.py
index 00ea039..6d5af47 100644
--- a/server/user_session.py
+++ b/server/user_session.py
@@ -26,13 +26,14 @@ class UserSession(object):
No properties are accessible; use getters and setters instead.
Values are passed by value instead of by reference (deep copy!).
"""
- def __init__(self, uid, username):
+ def __init__(self, uid, username, settings):
self._access_lock = threading.Lock()
self.sid = uuid.uuid4().hex
self.uid = uid
self.username = username
self.prolog_session = None
self.python_session = None
+ self.settings = settings
def destroy(self):
"""Destroys the session."""
@@ -53,6 +54,9 @@ class UserSession(object):
def get_uid(self):
return self.uid
+ def get_settings(self):
+ return self.settings
+
def get_prolog(self):
with self._access_lock:
if self.prolog_session is None:
@@ -159,13 +163,16 @@ def get_session_by_id(sid):
raise NoSuchSession('There is no session with SID {}'.format(sid))
return s
-def get_or_create_session(uid, username, sid=None):
+def get_or_create_session(uid, username, sid=None, lan=None):
with module_access_lock:
if sid is not None:
s = sessions.get(sid)
if s is not None:
return s
- s = UserSession(uid, username)
+ settings = {}
+ if lan is not None:
+ settings['lan'] = lan
+ s = UserSession(uid, username, settings)
sessions[s.sid] = s
return s
@@ -174,12 +181,12 @@ def authenticate_and_create_session(username, password):
try:
cur = conn.cursor()
try:
- cur.execute('select id, password from codeq_user where username = %s', (username,))
+ cur.execute('select id, password, gui_lang from codeq_user where username = %s', (username,))
row = cur.fetchone()
if row is None:
raise AuthenticationFailed('No such user: {}'.format(username))
if verify_password(password, row[1]):
- return get_or_create_session(row[0], username)
+ return get_or_create_session(row[0], username, None, row[2])
raise AuthenticationFailed('Password mismatch')
finally:
cur.close()