Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

41 righe
1.0 KiB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
  3. from decorators import WSGISimpleAuth # decoratore ( singleton )
  4. auth = WSGISimpleAuth()
  5. @auth.require()
  6. def application( environ, start_response ):
  7. storage = environ['auth.storage']
  8. import cgi
  9. post_environ = environ.copy()
  10. post_environ['QUERY_STRING'] = ''
  11. post = cgi.FieldStorage(
  12. fp=environ['wsgi.input'],
  13. environ=post_environ,
  14. keep_blank_values=True
  15. )
  16. if 'password' in post:
  17. password = post['password'].value
  18. storage['permissions'] = [ 'auth' ]
  19. html = [
  20. "You are logged in, now you can see the <a href='/secret'>Secret</a> page.",
  21. ]
  22. else:
  23. storage['timeout'] = -1
  24. html = [
  25. "<form method='POST'>"
  26. "Password: <input type='password' value='' name='password' />",
  27. "<input type='submit'>",
  28. "</form>",
  29. ]
  30. start_response( '200 OK', [('content-type', 'text/html; charset=utf-8')] )
  31. return html