Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import functools
  2. import urllib
  3. import urlparse
  4. # taken from tornado.web.authenticated
  5.  
  6. def authenticated_plus(extra_check):
  7. """Decorate methods with this to require that the user be logged in."""
  8. def wrap(method):
  9. @functools.wraps(method)
  10. def wrapper(self, *args, **kwargs):
  11. if not (self.current_user and extra_check(self.current_user)):
  12. if self.request.method in ("GET", "HEAD"):
  13. url = self.get_login_url()
  14. if "?" not in url:
  15. if urlparse.urlsplit(url).scheme:
  16. # if login url is absolute, make next absolute too
  17. next_url = self.request.full_url()
  18. else:
  19. next_url = self.request.uri
  20. url += "?" + urllib.urlencode(dict(next=next_url))
  21. self.redirect(url)
  22. return
  23. raise HTTPError(403)
  24. return method(self, *args, **kwargs)
  25. return wrapper
  26. return wrap
Add Comment
Please, Sign In to add comment