From 575c459059d6f847eb49935f4680da1981a0dbaf Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 25 Feb 2016 17:41:11 +0100 Subject: Simplify server.handlers.Login --- server/handlers.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/server/handlers.py b/server/handlers.py index 2e15a0e..b59b282 100644 --- a/server/handlers.py +++ b/server/handlers.py @@ -54,29 +54,23 @@ class Login(CodeqService): js = request.data username = js.get('username') password = js.get('password') - if username is None: - request.reply({'code': 1, 'message': 'Username was not provided'}) - elif password is None: - request.reply({'code': 2, 'message': 'Password was not provided'}) + try: + name, email, is_admin, date_joined, last_login = request.session.login(username, password) + except AuthenticationFailed: + request.reply({'code': 1, 'message': 'Wrong username or password'}) else: - session = request.session - try: - name, email, is_admin, date_joined, last_login = session.login(username, password) - except AuthenticationFailed: - request.reply({'code': 3, 'message': 'Username or password do not match'}) - else: - settings = session.get_settings() - request.reply({ - 'code': 0, - 'message': 'OK', - 'username': username, - 'name': name, - 'email': email, - 'admin': is_admin, - 'joined': date_joined.isoformat(), - 'last-login': last_login.isoformat(), - 'settings': settings - }) + settings = request.session.get_settings() + request.reply({ + 'code': 0, + 'message': 'OK', + 'username': username, + 'name': name, + 'email': email, + 'admin': is_admin, + 'joined': date_joined.isoformat(), + 'last-login': last_login.isoformat(), + 'settings': settings + }) class Logout(CodeqService): -- cgit v1.2.1