comparison libervia.tac @ 66:9d8e79ac4c9c

Login/Register box: integration of Adrien Vigneron's design
author Goffi <goffi@goffi.org>
date Wed, 15 Jun 2011 00:52:02 +0200
parents 80c490e6a1a7
children b096facaa5b3
comparison
equal deleted inserted replaced
65:8f421a12b8f9 66:9d8e79ac4c9c
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 """ 4 """
5 Libervia: a Salut à Toi frontend 5 Libervia: a Salut à Toi frontend
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) 6 Copyright (C) 2011 Jérôme Poisson <goffi@goffi.org>
7 7
8 This program is free software: you can redistribute it and/or modify 8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by 9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or 10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
311 - BAD REQUEST: something is wrong in the request (bad arguments, profile_key for login) 311 - BAD REQUEST: something is wrong in the request (bad arguments, profile_key for login)
312 - AUTH ERROR: either the profile or the password is wrong 312 - AUTH ERROR: either the profile or the password is wrong
313 - ALREADY WAITING: a request has already be made for this profile 313 - ALREADY WAITING: a request has already be made for this profile
314 - server.NOT_DONE_YET: the profile is being processed, the return value will be given by self._logged or self._logginError 314 - server.NOT_DONE_YET: the profile is being processed, the return value will be given by self._logged or self._logginError
315 """ 315 """
316 if 'new_account' in request.args:
317 return self._registerNewAccount(request.args)
318
319 try: 316 try:
320 _login = request.args['login'][0] 317 if request.args['submit_type'][0] == 'login':
321 if _login.startswith('@'): 318 _login = request.args['login'][0]
322 raise Exception('No profile_key allowed') 319 if _login.startswith('@'):
323 _pass = request.args['password'][0] 320 raise Exception('No profile_key allowed')
321 _pass = request.args['login_password'][0]
322
323 elif request.args['submit_type'][0] == 'register':
324 return self._registerNewAccount(request.args)
325
326 else:
327 raise Exception('Unknown submit type')
324 except KeyError: 328 except KeyError:
325 return "BAD REQUEST" 329 return "BAD REQUEST"
326 330
327 _profile_check = self.sat_host.bridge.getProfileName(_login) 331 _profile_check = self.sat_host.bridge.getProfileName(_login)
328 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login) 332 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login)
357 @param args: dict of args as given by the form 361 @param args: dict of args as given by the form
358 @return: "REGISTRATION" in case of success""" 362 @return: "REGISTRATION" in case of success"""
359 #TODO: must be moved in SàT core 363 #TODO: must be moved in SàT core
360 364
361 try: 365 try:
362 profile = login = args['login'][0] 366 profile = login = args['register_login'][0]
367 password = request.args['register_password'][0] #FIXME: password is ignored so far
363 email = args['email'][0] 368 email = args['email'][0]
364 except KeyError: 369 except KeyError:
365 return "BAD REQUEST" 370 return "BAD REQUEST"
366 if not re.match(r'^[a-z0-9_-]+$', login, re.IGNORECASE) or \ 371 if not re.match(r'^[a-z0-9_-]+$', login, re.IGNORECASE) or \
367 not re.match(r'^.+@.+\..+', email, re.IGNORECASE): 372 not re.match(r'^.+@.+\..+', email, re.IGNORECASE):