Skip to content

Commit

Permalink
started adding a logout mechanism #542
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Letter committed Nov 20, 2015
1 parent 14aded6 commit fe2a107
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def abspath(path):
dispatcher.connect("put-upload-file-part", "/uploads/:uid/files/:fid/parts/:pid", slycat.web.server.handlers.put_upload_file_part, conditions={"method" : ["PUT"]})
dispatcher.connect("post-upload-finshed", "/uploads/:uid/finished", slycat.web.server.handlers.post_upload_finished, conditions={"method" : ["POST"]})
dispatcher.connect("delete-upload", "/uploads/:uid", slycat.web.server.handlers.delete_upload, conditions={"method" : ["DELETE"]})
dispatcher.connect("logout", "/logout", slycat.web.server.handlers.logout, conditions={"method" : ["DELETE"]})

def log_configuration(tree, indent=""):
for key, value in sorted(tree.items()):
Expand Down
13 changes: 13 additions & 0 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,19 @@ def delete_upload(uid):
slycat.web.server.upload.delete_session(uid)
cherrypy.response.status = "204 Upload session deleted."

def logout():
# See if the client has a valid session.
if "slycatauth" in cherrypy.request.cookie:
sid = cherrypy.request.cookie["slycatauth"].value
couchdb = slycat.web.server.database.couchdb.connect()
session = couchdb.get("session", sid)
if session is not None:
cherrypy.response.status = "204 session deleted." + json.dumps(session) + str(couchdb.delete(session))
else:
cherrypy.response.status = "204 session not deleted." + json.dumps(session) + sid + str(session.get("_id") is sid) + ":::::" + session.get("_id") + ":::::" + sid
else:
cherrypy.response.status = "404 no auth found"

@cherrypy.tools.json_in(on = True)
def put_model_inputs(mid):
database = slycat.web.server.database.couchdb.connect()
Expand Down
5 changes: 5 additions & 0 deletions web-server/js/slycat-navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ define("slycat-navbar", ["slycat-server-root", "slycat-web-client", "slycat-chan
}

component.update_references();
component.sign_out = function()
{
window.alert("hello");
client.sign_out({success:function(){window.alert("you are logged out");},error: function(){window.alert("something went wrong");}})
}

},
template: { require: "text!" + server_root + "templates/slycat-navbar.html" }
Expand Down
19 changes: 19 additions & 0 deletions web-server/js/slycat-web-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,24 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se
});
}

module.sign_out = function(params)
{
$.ajax(
{
type: "DELETE",
url: server_root + "logout",
success: function()
{
if(params.success)
params.success();
},
error: function(request, status, reason_phrase)
{
if(params.error)
params.error(request, status, reason_phrase);
},
});
}

return module;
});

0 comments on commit fe2a107

Please sign in to comment.