diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/handlers.py | 38 |
1 files 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): |