PLT-3691 Fixing mobile session (#3652)

* PLT-3691 Fixing mobile session

* Fixing unit tests
Этот коммит содержится в:
Corey Hulen
2016-07-21 08:36:11 -08:00
коммит произвёл Joram Wilander
родитель bfa04c0ab0
Коммит 946302d9a2
5 изменённых файлов: 32 добавлений и 7 удалений

Просмотреть файл

@@ -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
}