summaryrefslogtreecommitdiffstats
path: root/app/session.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-01-13 15:17:50 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-01-13 15:17:50 -0500
commit0e2b321e6f5ab5983bc3428aa455dac7012c36ee (patch)
treec3919a284cf13ddcb66a6f482b1c9bbd9f34fc9b /app/session.go
parent97558f6a6ec4c53fa69035fb430ead209d9c222d (diff)
downloadchat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.tar.gz
chat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.tar.bz2
chat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.zip
Refactor and migrate more functions out of api into app package (#5063)
Diffstat (limited to 'app/session.go')
-rw-r--r--app/session.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/session.go b/app/session.go
index 29c961e81..3bb167891 100644
--- a/app/session.go
+++ b/app/session.go
@@ -92,3 +92,55 @@ func InvalidateAllCaches() {
func SessionCacheLength() int {
return sessionCache.Len()
}
+
+func RevokeSessionsForDeviceId(userId string, deviceId string, currentSessionId 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.DeviceId == deviceId && session.Id != currentSessionId {
+ l4g.Debug(utils.T("api.user.login.revoking.app_error"), session.Id, userId)
+ if err := RevokeSession(session); err != nil {
+ // Soft error so we still remove the other sessions
+ l4g.Error(err.Error())
+ }
+ }
+ }
+ }
+
+ return nil
+}
+
+func RevokeSessionById(sessionId string) *model.AppError {
+ if result := <-Srv.Store.Session().Get(sessionId); result.Err != nil {
+ return result.Err
+ } else {
+ return RevokeSession(result.Data.(*model.Session))
+ }
+}
+
+func RevokeSession(session *model.Session) *model.AppError {
+ if session.IsOAuth {
+ if err := RevokeAccessToken(session.Token); err != nil {
+ return err
+ }
+ } else {
+ if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
+ return result.Err
+ }
+ }
+
+ RevokeWebrtcToken(session.Id)
+ RemoveAllSessionsForUserId(session.UserId)
+
+ return nil
+}
+
+func AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError {
+ if result := <-Srv.Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt); result.Err != nil {
+ return result.Err
+ }
+
+ return nil
+}