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.
 
 
 
 
 

48 lines
1.7 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, DBSession
  5. import datetime
  6. @view_config(route_name='auth', match_param="action=login", renderer="jm2l:templates/login.mako")
  7. def login(request):
  8. return {}
  9. @view_config(route_name='bymail', renderer="string")
  10. def bymail(request):
  11. myhash = request.matchdict.get('hash', "")
  12. user = User.by_hash(myhash)
  13. if user:
  14. user.last_logged=datetime.datetime.now()
  15. DBSession.merge(user)
  16. headers = remember(request, user.uid)
  17. return HTTPFound(location=request.route_url('jm2l'),
  18. headers=headers)
  19. else:
  20. headers = forget(request)
  21. return HTTPFound(location=request.route_url('auth', action='login'),
  22. headers=headers)
  23. @view_config(route_name='auth', match_param="action=in", renderer="string",
  24. request_method="POST")
  25. @view_config(route_name='auth', match_param="action=out", renderer="string")
  26. def sign_in_out(request):
  27. username = request.POST.get('username')
  28. if username:
  29. user = User.by_name(username)
  30. if user and user.verify_password(request.POST.get('password')):
  31. user.last_logged=datetime.datetime.now()
  32. DBSession.merge(user)
  33. headers = remember(request, user.uid)
  34. return HTTPFound(location=request.route_url('jm2l'),
  35. headers=headers)
  36. else:
  37. headers = forget(request)
  38. else:
  39. headers = forget(request)
  40. return HTTPFound(location=request.route_url('home'),
  41. headers=headers)