+

:4736 Function create_function() is deprecated [8192]

Last commit for mycoserver/controllers.py: 7f0735f4298871f1d265bbb561b5486232056a43

Add debug after sync group

Benjamin Renard [2014-08-17 18:55:43]
Add debug after sync group
  1. # -*- coding: utf-8 -*-
  2.  
  3.  
  4. import logging
  5.  
  6. from webob.dec import wsgify
  7.  
  8. from . import conv, router, templates, wsgi_helpers
  9.  
  10. import json
  11.  
  12. log = logging.getLogger(__name__)
  13.  
  14. @wsgify
  15. def home(req):
  16. return templates.render(req.ctx, '/home.mako', data={})
  17.  
  18. @wsgify
  19. def login(req):
  20. params = req.params
  21. log.debug(u'params = {}'.format(params))
  22. inputs = {
  23. 'email': params.get('email'),
  24. 'password': params.get('password'),
  25. }
  26. log.debug(u'inputs = {}'.format(inputs))
  27. data, errors = conv.inputs_to_login_data(inputs)
  28. if errors is not None:
  29. return wsgi_helpers.bad_request(req.ctx, comment=errors)
  30.  
  31. log.debug(u'data = {}'.format(data))
  32.  
  33. login_data=req.ctx.db.login(data['email'],data['password'])
  34. return wsgi_helpers.respond_json(req.ctx,login_data,headers=[('Access-Control-Allow-Origin','*')])
  35.  
  36. @wsgify
  37. def subscribe(req):
  38. params = req.params
  39. log.debug(u'params = {}'.format(params))
  40. inputs = {
  41. 'email': params.get('email'),
  42. 'name': params.get('name'),
  43. 'password': params.get('password'),
  44. }
  45. log.debug(u'inputs = {}'.format(inputs))
  46. data, errors = conv.inputs_to_subscribe_data(inputs)
  47. if errors is not None:
  48. return wsgi_helpers.bad_request(req.ctx, comment=errors)
  49.  
  50. log.debug(u'data = {}'.format(data))
  51.  
  52. login_data=req.ctx.db.subscribe(data['email'],data['name'],data['password'])
  53. return wsgi_helpers.respond_json(req.ctx,login_data,headers=[('Access-Control-Allow-Origin','*')])
  54.  
  55.  
  56. @wsgify
  57. def sync(req):
  58. params = req.params
  59. log.debug(u'params = {}'.format(params))
  60. inputs = {
  61. 'email': params.get('email'),
  62. 'password': params.get('password'),
  63. 'groups': params.get('groups')
  64. }
  65. log.debug(u'inputs = {}'.format(inputs))
  66. data, errors = conv.inputs_to_sync_data(inputs)
  67. if errors is not None or data['groups'] is None:
  68. return wsgi_helpers.bad_request(req.ctx, comment=errors)
  69.  
  70. data['groups']=json.loads(data['groups'])
  71.  
  72. log.debug(u'data = {}'.format(data))
  73.  
  74. login_data=req.ctx.db.login(data['email'],data['password'])
  75. if 'email' in login_data:
  76. log.debug(u'Login successful : sync groups')
  77. ret=req.ctx.db.sync_group(data['email'],data['groups'])
  78. log.debug("After sync : %s" % ret)
  79. return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')])
  80. else:
  81. log.debug(u'Login error : return login error')
  82. return wsgi_helpers.respond_json(
  83. req.ctx,
  84. login_data,
  85. headers=[('Access-Control-Allow-Origin','*')]
  86. )
  87.  
  88. def make_router():
  89. return router.make_router(
  90. ('GET', '^/$', home),
  91. ('GET', '^/login$', login),
  92. ('GET', '^/subscribe$', subscribe),
  93. ('POST', '^/sync$', sync),
  94. )