summaryrefslogtreecommitdiff
path: root/server/handlers.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/handlers.py')
-rw-r--r--server/handlers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/server/handlers.py b/server/handlers.py
index a7f4f76..a7e0fef 100644
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -55,6 +55,28 @@ class Login(CodeqService):
request.reply({'code': 0, 'message': 'OK', 'sid':session.get_sid(), 'settings':settings})
+class Signup(CodeqService):
+ session_is_optional = True
+
+ def process(self, request):
+ 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'})
+ else:
+ try:
+ server.user_session.signup(username, password)
+ except UserExists:
+ request.reply({'code': 3, 'message': 'Username already exists'})
+ except SignupFailed:
+ request.reply({'code': 4, 'message': 'Signn up failed'})
+ else:
+ request.reply({'code': 0, 'message': 'OK'})
+
+
class ChangePassword(CodeqService):
def process(self, request):
js = request.data
@@ -260,6 +282,7 @@ class EndProblem(CodeqService):
incoming_handlers = {
'list_problems': ProblemList(),
'login': Login(),
+ 'signup': Signup(),
'change_password': ChangePassword(),
'get_problem': GetProblem(),
'logout': None,