Guest User

Untitled

a guest
Sep 2nd, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import logging
  2.  
  3. from pylons import request, response, session, tmpl_context as c, url
  4. from pylons.controllers.util import abort, redirect
  5.  
  6. from simplesite.lib.base import BaseController, render
  7.  
  8. import simplesite.lib.helpers as h
  9.  
  10. from authkit.authorize.pylons_adaptors import authorize
  11. from authkit.users.sqlalchemy_driver import UsersFromDatabase
  12. from simplesite.model import meta
  13. from pylons import request
  14. import formencode
  15. from formencode import htmlfill
  16. from pylons.decorators import validate
  17.  
  18. log = logging.getLogger(__name__)
  19.  
  20. class RegistrationForm(formencode.Schema):
  21. allow_extra_fields = True
  22. filter_extra_fields = True
  23. username = formencode.validators.String(not_empty=True)
  24. password = formencode.validators.String(not_empty=True)
  25.  
  26. class AccountController(BaseController):
  27.  
  28. def signin(self):
  29. if not request.environ.get('REMOTE_USER'):
  30. # This triggers the AuthKit middleware into displaying the sign-in form
  31. abort(401)
  32. else:
  33. return render('/derived/account/signedin.html')
  34.  
  35. def signout(self):
  36. # The actual removal of the AuthKit cookie occurs when the response passes
  37. # through the AuthKit middleware, we simply need to display a page
  38. # confirming the user is signed out
  39. return render('/derived/account/signedout.html')
  40.  
  41. def signinagain(self):
  42. request.environ['paste.auth_tkt.logout_user']()
  43. return render('/derived/account/signin.html').replace('%s', h.url('signin'))
  44.  
  45. @authorize(h.auth.has_delete_role)
  46. def register_form(self):
  47. return render('/derived/account/register.html')
  48.  
  49. def custom_formatter(error):
  50. return '<span class="error-message">%s</span><br />\n' % (
  51. htmlfill.html_quote(error)
  52. )
  53.  
  54. @validate(schema=RegistrationForm(), form='register_form', auto_error_formatter=custom_formatter)
  55. def register(self):
  56. users = request.environ['authkit.users']
  57. users.user_create(self.form_result['username'], password=self.form_result['password'])
  58. meta.Session.commit()
  59. return render('/derived/account/register.html')
Add Comment
Please, Sign In to add comment