No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from .base import get_response
  20. from ...exceptions import *
  21. from ...client import WebUiClient as WebUiClient
  22. from lodel.context import LodelContext
  23. LodelContext.expose_modules(globals(), {'lodel.logger': 'logger'})
  24. LodelContext.expose_dyncode(globals(), 'dyncode')
  25. ##@brief These functions are called by the rules defined in ../urls.py
  26. ## Their goal is to handle the user authentication
  27. ##@brief Controller's function to login a user, the corresponding form is in interface/users
  28. # @param request : the request (get or post)
  29. # @note the response is given in a html page called in get_response_function
  30. def signin(request):
  31. msg=''
  32. # The form send the login and password, we can authenticate the user
  33. if request.method == 'POST':
  34. login = request.form['inputLogin']
  35. WebUiClient.authenticate(login, request.form['inputPassword'])
  36. # We get the informations about the user
  37. uid=WebUiClient['__auth_user_infos']['uid']
  38. leoclass=WebUiClient['__auth_user_infos']['leoclass']
  39. query_filter=list()
  40. query_filter.append((leoclass.uid_fieldname()[0],'=', uid))
  41. user = leoclass.get(query_filter)
  42. return get_response('users/welcome.html', username = user[0].data('login'))
  43. else:
  44. return get_response('users/signin.html')
  45. ##@brief Controller's function to logout a user
  46. # @param request : the request (get or post)
  47. # @note the response is given in the login html page
  48. def signout(request):
  49. WebUiClient.destroy()
  50. return get_response('users/signin.html')