Le repo des sources pour le site web des JM2L
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.
 
 
 
 
 

43 line
1.5 KiB

  1. from pyramid.view import view_config
  2. from pyramid.security import remember, forget
  3. from pyramid.httpexceptions import HTTPFound
  4. from .models import User
  5. @view_config(route_name='auth', match_param="action=login", renderer="jm2l:templates/login.mako")
  6. def login(request):
  7. return {}
  8. @view_config(route_name='bymail', renderer="string")
  9. def bymail(request):
  10. myhash = request.matchdict.get('hash', "")
  11. user = User.by_hash(myhash)
  12. if user:
  13. headers = remember(request, user.uid)
  14. return HTTPFound(location=request.route_url('jm2l'),
  15. headers=headers)
  16. else:
  17. headers = forget(request)
  18. return HTTPFound(location=request.route_url('auth', action='login'),
  19. headers=headers)
  20. @view_config(route_name='auth', match_param="action=in", renderer="string",
  21. request_method="POST")
  22. @view_config(route_name='auth', match_param="action=out", renderer="string")
  23. def sign_in_out(request):
  24. username = request.POST.get('username')
  25. if username:
  26. user = User.by_name(username)
  27. if user and user.verify_password(request.POST.get('password')):
  28. headers = remember(request, user.uid)
  29. return HTTPFound(location=request.route_url('jm2l'),
  30. headers=headers)
  31. else:
  32. headers = forget(request)
  33. else:
  34. headers = forget(request)
  35. return HTTPFound(location=request.route_url('home'),
  36. headers=headers)