From f4583b830a658c844c895339a666f0878e179441 Mon Sep 17 00:00:00 2001 From: lukeIam Date: Mon, 29 Dec 2014 20:45:46 +0100 Subject: [PATCH] [Server] Allow multiple sessions with one user --- ServerLib/CWebservice.cs | 6 ++++++ ServerLib/ICWebservice.cs | 5 +++++ ServerLib/SessionControl.cs | 10 +++++++++- Vocaluxe/Website/js/main.js | 18 +++++++++++------- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ServerLib/CWebservice.cs b/ServerLib/CWebservice.cs index 42ed7c70..abefcf53 100644 --- a/ServerLib/CWebservice.cs +++ b/ServerLib/CWebservice.cs @@ -173,6 +173,12 @@ namespace ServerLib return sessionId; } + public void Logout() + { + Guid sessionKey = _GetSession(); + CSessionControl.InvalidateSessions(sessionKey); + } + public Stream Index() { if (WebOperationContext.Current != null) diff --git a/ServerLib/ICWebservice.cs b/ServerLib/ICWebservice.cs index d13eb95d..27d68081 100644 --- a/ServerLib/ICWebservice.cs +++ b/ServerLib/ICWebservice.cs @@ -71,6 +71,11 @@ namespace ServerLib UriTemplate = "/login?username={username}&password={password}")] Guid Login(string username, string password); + [OperationContract, WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/logout")] + void Logout(); + [OperationContract, WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "")] diff --git a/ServerLib/SessionControl.cs b/ServerLib/SessionControl.cs index 80bd2e66..d16f50a5 100644 --- a/ServerLib/SessionControl.cs +++ b/ServerLib/SessionControl.cs @@ -34,7 +34,7 @@ namespace ServerLib int id = _GetProfileIdFormUsername(userName); EUserRoles roles = _GetUserRoles(id); CSession session = new CSession(newId, id, roles); - InvalidateSessions(id); + //InvalidateSessions(id); _ActiveSessions.Add(newId, session); return newId; @@ -63,6 +63,14 @@ namespace ServerLib _ActiveSessions.Remove(s.Key); } + internal static void InvalidateSessions(Guid sessionId) + { + if (_ActiveSessions.ContainsKey(sessionId)) + { + _ActiveSessions.Remove(sessionId); + } + } + internal static bool RequestRight(Guid sessionId, EUserRights requestedRight) { return ((CUserRoleControl.GetUserRightsFromUserRole(_ActiveSessions[sessionId].Roles) diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index 2b211fcd..49aec6f1 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -1412,16 +1412,20 @@ }; this.logout = function () { - t.ownProfileId = -1; + request({ + url: "logout" + }, "noOverlay").always(function () { + t.ownProfileId = -1; - t.sessionId = ""; + t.sessionId = ""; - pageHandler.reset(); + pageHandler.reset(); - if (window.localStorage) { - window.localStorage.setItem("VocaluxeSessionKey", ""); - } - $.mobile.changePage("#login", { transition: "slidefade" }); + if (window.localStorage) { + window.localStorage.setItem("VocaluxeSessionKey", ""); + } + $.mobile.changePage("#login", { transition: "slidefade" }); + }); };