Add subscribe method
This commit is contained in:
parent
149c349cdd
commit
c5dae5ef45
3 changed files with 45 additions and 0 deletions
|
@ -33,6 +33,26 @@ def login(req):
|
|||
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
|
||||
|
@ -66,5 +86,6 @@ def make_router():
|
|||
return router.make_router(
|
||||
('GET', '^/$', home),
|
||||
('GET', '^/login$', login),
|
||||
('GET', '^/subscribe$', subscribe),
|
||||
('GET', '^/sync$', sync),
|
||||
)
|
||||
|
|
|
@ -12,6 +12,16 @@ inputs_to_login_data = struct(
|
|||
drop_none_values=False,
|
||||
)
|
||||
|
||||
inputs_to_subscribe_data = struct(
|
||||
{
|
||||
'email': pipe(cleanup_line, empty_to_none),
|
||||
'name': pipe(cleanup_line, empty_to_none),
|
||||
'password': pipe(cleanup_line, empty_to_none),
|
||||
},
|
||||
default='drop',
|
||||
drop_none_values=False,
|
||||
)
|
||||
|
||||
inputs_to_sync_data = struct(
|
||||
{
|
||||
'email': pipe(cleanup_line, empty_to_none),
|
||||
|
|
|
@ -56,6 +56,20 @@ class DB(object):
|
|||
return { 'loginerror': 'Utilisateur inconnu' }
|
||||
return { 'loginerror': 'Erreur inconnu' }
|
||||
|
||||
def subscribe(self,email,name,password):
|
||||
ret=self.select("SELECT count(*) as count FROM users WHERE email='%s'" % (email))
|
||||
log.debug(ret)
|
||||
if ret[0][0]!=0:
|
||||
return {'subscribeerror': u'Cette adresse mail est déjà associés a un compte !'}
|
||||
else:
|
||||
if self.do_sql("INSERT INTO users (email,name,password) VALUES ('%s','%s','%s')" % (email,name,password)):
|
||||
return {
|
||||
'email': email,
|
||||
'name': name,
|
||||
'password': password
|
||||
}
|
||||
return {'subscribeerror': u'Une erreur est survenue durant votre inscription :('}
|
||||
|
||||
def sync_group(self,email,groups):
|
||||
db_groups=self.get_group(email)
|
||||
json_group=json.dumps(groups)
|
||||
|
|
Loading…
Reference in a new issue