Move hostKey handling to a separate function
This commit is contained in:
parent
ce6433b9ba
commit
765cce3d74
@ -380,6 +380,21 @@ class SyncApp(object):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def operation_hostKey(self, username, password):
|
||||||
|
if not self.user_manager.authenticate(username, password):
|
||||||
|
return
|
||||||
|
|
||||||
|
dirname = self.user_manager.username2dirname(username)
|
||||||
|
if dirname is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
hkey = self.generateHostKey(username)
|
||||||
|
user_path = os.path.join(self.data_root, dirname)
|
||||||
|
session = self.create_session(username, user_path)
|
||||||
|
self.session_manager.save(hkey, session)
|
||||||
|
|
||||||
|
return hkey
|
||||||
|
|
||||||
def operation_upload(self, col, data, session):
|
def operation_upload(self, col, data, session):
|
||||||
# Verify integrity of the received database file before replacing our
|
# Verify integrity of the received database file before replacing our
|
||||||
# existing db.
|
# existing db.
|
||||||
@ -461,26 +476,12 @@ class SyncApp(object):
|
|||||||
raise HTTPNotFound()
|
raise HTTPNotFound()
|
||||||
|
|
||||||
if url == 'hostKey':
|
if url == 'hostKey':
|
||||||
try:
|
hkey = self.operation_hostKey(data.get("u"), data.get("p"))
|
||||||
u = data['u']
|
if hkey:
|
||||||
p = data['p']
|
|
||||||
except KeyError:
|
|
||||||
raise HTTPForbidden('Must pass username and password')
|
|
||||||
if self.user_manager.authenticate(u, p):
|
|
||||||
dirname = self.user_manager.username2dirname(u)
|
|
||||||
if dirname is None:
|
|
||||||
raise HTTPForbidden()
|
|
||||||
|
|
||||||
hkey = self.generateHostKey(u)
|
|
||||||
user_path = os.path.join(self.data_root, dirname)
|
|
||||||
session = self.create_session(u, user_path)
|
|
||||||
self.session_manager.save(hkey, session)
|
|
||||||
|
|
||||||
result = {'key': hkey}
|
|
||||||
return Response(
|
return Response(
|
||||||
status='200 OK',
|
status='200 OK',
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
body=json.dumps(result))
|
body=json.dumps({'key': hkey}))
|
||||||
else:
|
else:
|
||||||
# TODO: do I have to pass 'null' for the client to receive None?
|
# TODO: do I have to pass 'null' for the client to receive None?
|
||||||
raise HTTPForbidden('null')
|
raise HTTPForbidden('null')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user