Zionetrix::Git
Repositories
Help
Report an Issue
MyCoServer
Code
Commits
Branches
Tags
Search
Tree:
e8a355c
Branches
Tags
master
MyCoServer
mycoserver
controllers.py
Use POST instead GET to sync groups
Benjamin Renard
commited
e8a355c
at 2014-01-27 22:55:06
controllers.py
Blame
History
Raw
# -*- coding: utf-8 -*- import logging from webob.dec import wsgify from . import conv, router, templates, wsgi_helpers import json log = logging.getLogger(__name__) @wsgify def home(req): return templates.render(req.ctx, '/home.mako', data={}) @wsgify def login(req): params = req.params log.debug(u'params = {}'.format(params)) inputs = { 'email': params.get('email'), 'password': params.get('password'), } log.debug(u'inputs = {}'.format(inputs)) data, errors = conv.inputs_to_login_data(inputs) if errors is not None: return wsgi_helpers.bad_request(req.ctx, comment=errors) log.debug(u'data = {}'.format(data)) login_data=req.ctx.db.login(data['email'],data['password']) return wsgi_helpers.respond_json(req.ctx,login_data,headers=[('Access-Control-Allow-Origin','*')]) @wsgify def subscribe(req): params = req.params log.debug(u'params = {}'.format(params)) inputs = { 'email': params.get('email'), 'name': params.get('name'), 'password': params.get('password'), } log.debug(u'inputs = {}'.format(inputs)) data, errors = conv.inputs_to_subscribe_data(inputs) if errors is not None: return wsgi_helpers.bad_request(req.ctx, comment=errors) log.debug(u'data = {}'.format(data)) login_data=req.ctx.db.subscribe(data['email'],data['name'],data['password']) return wsgi_helpers.respond_json(req.ctx,login_data,headers=[('Access-Control-Allow-Origin','*')]) @wsgify def sync(req): params = req.params log.debug(u'params = {}'.format(params)) inputs = { 'email': params.get('email'), 'password': params.get('password'), 'groups': params.get('groups') } log.debug(u'inputs = {}'.format(inputs)) data, errors = conv.inputs_to_sync_data(inputs) if errors is not None or data['groups'] is None: return wsgi_helpers.bad_request(req.ctx, comment=errors) data['groups']=json.loads(data['groups']) log.debug(u'data = {}'.format(data)) login_data=req.ctx.db.login(data['email'],data['password']) if 'email' in login_data: log.debug(u'Login successful : sync groups') ret=req.ctx.db.sync_group(data['email'],data['groups']) return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')]) else: log.debug(u'Login error : return login error') return wsgi_helpers.respond_json( req.ctx, login_data, headers=[('Access-Control-Allow-Origin','*')] ) def make_router(): return router.make_router( ('GET', '^/$', home), ('GET', '^/login$', login), ('GET', '^/subscribe$', subscribe), ('POST', '^/sync$', sync), )