summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-01-06 16:13:10 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2016-01-06 16:13:10 -0500
commit5bcb9f1c50ed9c319d2a21f2ecb4816c51d18b40 (patch)
treeb24590d93e46414e849ef4af7cefe54b8b7061d7 /api
parent5855b5e4590889944e4a408f7185f84779fc701a (diff)
parent214c6bc15ed1d0c9f94d0f0545d3f95241893cdc (diff)
downloadchat-5bcb9f1c50ed9c319d2a21f2ecb4816c51d18b40.tar.gz
chat-5bcb9f1c50ed9c319d2a21f2ecb4816c51d18b40.tar.bz2
chat-5bcb9f1c50ed9c319d2a21f2ecb4816c51d18b40.zip
Merge pull request #1813 from mattermost/PLT-1558
PLT-1558 adding session length to config file
Diffstat (limited to 'api')
-rw-r--r--api/context.go9
-rw-r--r--api/user.go8
2 files changed, 12 insertions, 5 deletions
diff --git a/api/context.go b/api/context.go
index a6f9bc1e1..b39f03a7d 100644
--- a/api/context.go
+++ b/api/context.go
@@ -523,6 +523,13 @@ func GetSession(token string) *model.Session {
l4g.Error("Invalid session token=" + token + ", err=" + sessionResult.Err.DetailedError)
} else {
session = sessionResult.Data.(*model.Session)
+
+ if session.IsExpired() {
+ return nil
+ } else {
+ AddSessionToCache(session)
+ return session
+ }
}
}
@@ -553,5 +560,5 @@ func FindMultiSessionForTeamId(r *http.Request, teamId string) (int64, *model.Se
}
func AddSessionToCache(session *model.Session) {
- sessionCache.Add(session.Token, session)
+ sessionCache.AddWithExpiresInSecs(session.Token, session, int64(*utils.Cfg.ServiceSettings.SessionCacheInMinutes*60))
}
diff --git a/api/user.go b/api/user.go
index 42a65c934..d4c7fcaf5 100644
--- a/api/user.go
+++ b/api/user.go
@@ -492,11 +492,11 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User,
session := &model.Session{UserId: user.Id, TeamId: user.TeamId, Roles: user.Roles, DeviceId: deviceId, IsOAuth: false}
- maxAge := model.SESSION_TIME_WEB_IN_SECS
+ maxAge := *utils.Cfg.ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
if len(deviceId) > 0 {
- session.SetExpireInDays(model.SESSION_TIME_MOBILE_IN_DAYS)
- maxAge = model.SESSION_TIME_MOBILE_IN_SECS
+ session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
+ maxAge = *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
// A special case where we logout of all other sessions with the same Id
if result := <-Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
@@ -518,7 +518,7 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User,
}
} else {
- session.SetExpireInDays(model.SESSION_TIME_WEB_IN_DAYS)
+ session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthWebInDays)
}
ua := user_agent.New(r.UserAgent())