add check function for logged-in clients

This commit is contained in:
deflax 2016-05-21 18:56:46 +03:00
parent a5a1d943b0
commit 75fee82763
2 changed files with 17 additions and 3 deletions

View file

@ -66,7 +66,7 @@ def setencpasswd(clientemail, newpass):
#TODO: Send new email to the client to notify the password change. This time sending the password in plain text is not needed. #TODO: Send new email to the client to notify the password change. This time sending the password in plain text is not needed.
def check(clientid): def checkin(clientid):
""" return list of owned vmids if client id matches the client database. (logged-in users)""" """ return list of owned vmids if client id matches the client database. (logged-in users)"""
#1. search for the client #1. search for the client
try: try:

View file

@ -29,7 +29,7 @@ def welcome():
def selector(fn, req, vmid=0): def selector(fn, req, vmid=0):
""" try to exec commands """ """ try to exec commands """
json = req.context['doc'] json = req.context['doc']
print(json) print(json) #TODO: remove debug print
apipass = json['apikey'] apipass = json['apikey']
if apipass != config.get('general', 'apipass'): if apipass != config.get('general', 'apipass'):
status = falcon.HTTP_403 status = falcon.HTTP_403
@ -44,6 +44,10 @@ def selector(fn, req, vmid=0):
#logger.info('grid> access requested for {} with {}'.format(clientemail, passwd)) #logger.info('grid> access requested for {} with {}'.format(clientemail, passwd))
body = clientsdb.validate(clientemail, passwd) body = clientsdb.validate(clientemail, passwd)
elif fn == 'checkin':
clientid = json['clientid']
body = clientsdb.checkin(clientid)
elif fn == 'create': elif fn == 'create':
body = plugin.vmcreate(json) body = plugin.vmcreate(json)
@ -146,10 +150,17 @@ def max_body(limit):
class ValidateResource(object): class ValidateResource(object):
@falcon.before(max_body(64 * 1024)) @falcon.before(max_body(64 * 1024))
def on_post(self, req, resp): def on_post(self, req, resp):
""" get clientemail and password and compare it with the client db and returns a list of managed object IDs """ """ get clientemail and password, compare it with the client db and returns a list of managed objects """
resp.status, response = selector('validate', req) resp.status, response = selector('validate', req)
req.context['result'] = response req.context['result'] = response
class CheckInResource(object):
@falcon.before(max_body(64 * 1024))
def on_post(self, req, resp):
""" get client id, compare it with the client db and returns a list of managed objects """
resp.status, response = selector('checkin', req)
req.context['result'] = response
class CreateResource(object): class CreateResource(object):
@falcon.before(max_body(64 * 1024)) @falcon.before(max_body(64 * 1024))
def on_post(self, req, resp): def on_post(self, req, resp):
@ -234,6 +245,9 @@ wsgi_app = api = application = falcon.API(middleware=[
res_validate = ValidateResource() res_validate = ValidateResource()
api.add_route('/validate', res_validate) api.add_route('/validate', res_validate)
res_checkin = CheckInResource()
api.add_route('checkin', res_checkin)
res_create = CreateResource() res_create = CreateResource()
api.add_route('/create', res_create) api.add_route('/create', res_create)