summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-07-21 08:36:11 -0800
committerJoram Wilander <jwawilander@gmail.com>2016-07-21 12:36:11 -0400
commit946302d9a29cbf5702da9e18a52b59864a18c69e (patch)
tree2cd2520fc57c2a0681cc938b5e1adcd7b01c8d44 /api
parentbfa04c0ab0eca5d812ad64e5f51e95ec458cf0d3 (diff)
downloadchat-946302d9a29cbf5702da9e18a52b59864a18c69e.tar.gz
chat-946302d9a29cbf5702da9e18a52b59864a18c69e.tar.bz2
chat-946302d9a29cbf5702da9e18a52b59864a18c69e.zip
PLT-3691 Fixing mobile session (#3652)
* PLT-3691 Fixing mobile session * Fixing unit tests
Diffstat (limited to 'api')
-rw-r--r--api/user.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/api/user.go b/api/user.go
index 7dd24fe1b..8cc4ed8dd 100644
--- a/api/user.go
+++ b/api/user.go
@@ -684,8 +684,29 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
}
sessionCache.Remove(c.Session.Token)
+ c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
- if result := <-Srv.Store.Session().UpdateDeviceId(c.Session.Id, deviceId); result.Err != nil {
+ maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
+
+ secure := false
+ if GetProtocol(r) == "https" {
+ secure = true
+ }
+
+ expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0)
+ sessionCookie := &http.Cookie{
+ Name: model.SESSION_COOKIE_TOKEN,
+ Value: c.Session.Token,
+ Path: "/",
+ MaxAge: maxAge,
+ Expires: expiresAt,
+ HttpOnly: true,
+ Secure: secure,
+ }
+
+ http.SetCookie(w, sessionCookie)
+
+ if result := <-Srv.Store.Session().UpdateDeviceId(c.Session.Id, deviceId, c.Session.ExpiresAt); result.Err != nil {
c.Err = result.Err
return
}