Zionetrix::Git
Repositories
Help
Report an Issue
MyCoServer
Code
Commits
Branches
Tags
Search
Tree:
c5dae5e
Branches
Tags
master
MyCoServer
mycoserver
controllers.py
Add subscribe method
Benjamin Renard
commited
c5dae5e
at 2014-01-18 19:14:09
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: ret=req.ctx.db.sync_group(data['email'],data['groups']) return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')]) else: 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), ('GET', '^/sync$', sync), )