diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-01-19 09:00:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-19 09:00:13 -0500 |
commit | d3a285e64d051aa8d5c4c9854597dfbcce107675 (patch) | |
tree | e16ca3d52b6347a754e506aa8cac7457c62d3639 /app/session.go | |
parent | 61b7226533568f3261fc233538ce998bb71a5345 (diff) | |
download | chat-d3a285e64d051aa8d5c4c9854597dfbcce107675.tar.gz chat-d3a285e64d051aa8d5c4c9854597dfbcce107675.tar.bz2 chat-d3a285e64d051aa8d5c4c9854597dfbcce107675.zip |
Migrate functions to app package (#5106)
* Refactor and move session logic into app package
* Refactor email functions into the app package
* Refactor password update into app package
* Migrate user functions to app package
* Move team functions into app package
* Migrate channel functions into app package
* Pass SiteURL through to app functions
* Update based on feedback
Diffstat (limited to 'app/session.go')
-rw-r--r-- | app/session.go | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/app/session.go b/app/session.go index 3bb167891..289bb6a2d 100644 --- a/app/session.go +++ b/app/session.go @@ -14,6 +14,18 @@ import ( var sessionCache *utils.Cache = utils.NewLru(model.SESSION_CACHE_SIZE) +func CreateSession(session *model.Session) (*model.Session, *model.AppError) { + if result := <-Srv.Store.Session().Save(session); result.Err != nil { + return nil, result.Err + } else { + session := result.Data.(*model.Session) + + AddSessionToCache(session) + + return session, nil + } +} + func GetSession(token string) (*model.Session, *model.AppError) { metrics := einterfaces.GetMetricsInterface() @@ -51,16 +63,48 @@ func GetSession(token string) (*model.Session, *model.AppError) { return session, nil } -func RemoveAllSessionsForUserId(userId string) { +func GetSessions(userId string) ([]*model.Session, *model.AppError) { + if result := <-Srv.Store.Session().GetSessions(userId); result.Err != nil { + return nil, result.Err + } else { + return result.Data.([]*model.Session), nil + } +} + +func RevokeAllSessions(userId string) *model.AppError { + if result := <-Srv.Store.Session().GetSessions(userId); result.Err != nil { + return result.Err + } else { + sessions := result.Data.([]*model.Session) + + for _, session := range sessions { + if session.IsOAuth { + RevokeAccessToken(session.Token) + } else { + if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil { + return result.Err + } + } + + RevokeWebrtcToken(session.Id) + } + } + + ClearSessionCacheForUser(userId) + + return nil +} + +func ClearSessionCacheForUser(userId string) { - RemoveAllSessionsForUserIdSkipClusterSend(userId) + ClearSessionCacheForUserSkipClusterSend(userId) if einterfaces.GetClusterInterface() != nil { - einterfaces.GetClusterInterface().RemoveAllSessionsForUserId(userId) + einterfaces.GetClusterInterface().ClearSessionCacheForUser(userId) } } -func RemoveAllSessionsForUserIdSkipClusterSend(userId string) { +func ClearSessionCacheForUserSkipClusterSend(userId string) { keys := sessionCache.Keys() for _, key := range keys { @@ -132,7 +176,7 @@ func RevokeSession(session *model.Session) *model.AppError { } RevokeWebrtcToken(session.Id) - RemoveAllSessionsForUserId(session.UserId) + ClearSessionCacheForUser(session.UserId) return nil } |