apipublic.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. import tg
  3. import repoze.who.api
  4. from tg import _compat
  5. from pboard.lib import base as plb
  6. from pboard.lib import dbapi as pld
  7. from pboard import model as pm
  8. from pboard.model import data as pmd
  9. from pboard.model import serializers as pms
  10. from tg.i18n import ugettext as _
  11. class PODPublicApiController(plb.BaseController):
  12. @tg.expose()
  13. def create_account(self, email='', password='', retyped_password='', real_name='', **kw):
  14. if email=='' or password=='' or retyped_password=='':
  15. tg.flash(_('Account creation error: please fill all the fields'), 'error')
  16. tg.redirect(tg.lurl('/'))
  17. elif password!=retyped_password:
  18. tg.flash(_('Account creation error: passwords do not match'), 'error')
  19. tg.redirect(tg.lurl('/'))
  20. else:
  21. loExistingUser = pld.PODStaticController.getUserByEmailAddress(email)
  22. if loExistingUser!=None:
  23. tg.flash(_('Account creation error: account already exist: %s') % (email), 'error')
  24. tg.redirect(tg.lurl('/'))
  25. loNewAccount = pld.PODStaticController.createNewUser(real_name if real_name!='' else email, email, password, [])
  26. tg.flash(_('Account successfully created: %s') % (email), 'info')
  27. who_api = repoze.who.api.get_api(tg.request.environ)
  28. creds = {}
  29. creds['login'] = email
  30. creds['password'] = password
  31. authenticated, headers = who_api.login(creds)
  32. tg.response.headers = headers
  33. tg.redirect(tg.lurl('/'))