diff options
author | Corey Hulen <corey@hulen.com> | 2015-10-22 21:35:29 -0700 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-10-22 21:35:29 -0700 |
commit | 6a1934192f9e58b73bebdb4cfba555b281c81f13 (patch) | |
tree | 22f29ee70d3e87ec1cd0cfe50ba8442123105733 /api/user.go | |
parent | 5ecf45e109a5910959e0cc6927b826ce5a406a7d (diff) | |
parent | 7384b0791e54b0fd980ce8c321566c2c42289c02 (diff) | |
download | chat-6a1934192f9e58b73bebdb4cfba555b281c81f13.tar.gz chat-6a1934192f9e58b73bebdb4cfba555b281c81f13.tar.bz2 chat-6a1934192f9e58b73bebdb4cfba555b281c81f13.zip |
Merge pull request #1129 from mattermost/PLT-44
PLT-44 Inital support for multi-tab multi-team login
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/api/user.go b/api/user.go index 0c7278711..aec975524 100644 --- a/api/user.go +++ b/api/user.go @@ -428,43 +428,23 @@ func Login(c *Context, w http.ResponseWriter, r *http.Request, user *model.User, } w.Header().Set(model.HEADER_TOKEN, session.Token) - sessionCookie := &http.Cookie{ - Name: model.SESSION_TOKEN, - Value: session.Token, - Path: "/", - MaxAge: maxAge, - HttpOnly: true, - } - - http.SetCookie(w, sessionCookie) + tokens := GetMultiSessionCookieTokens(r) multiToken := "" - if originalMultiSessionCookie, err := r.Cookie(model.MULTI_SESSION_TOKEN); err == nil { - multiToken = originalMultiSessionCookie.Value - } - - // Attempt to clean all the old tokens or duplicate tokens - if len(multiToken) > 0 { - tokens := strings.Split(multiToken, " ") - - multiToken = "" - seen := make(map[string]string) - seen[session.TeamId] = session.TeamId - for _, token := range tokens { - if sr := <-Srv.Store.Session().Get(token); sr.Err == nil { - s := sr.Data.(*model.Session) - if !s.IsExpired() && seen[s.TeamId] == "" { - multiToken += " " + token - seen[s.TeamId] = s.TeamId - } - } + seen := make(map[string]string) + seen[session.TeamId] = session.TeamId + for _, token := range tokens { + s := GetSession(token) + if s != nil && !s.IsExpired() && seen[s.TeamId] == "" { + multiToken += " " + token + seen[s.TeamId] = s.TeamId } } - multiToken = strings.TrimSpace(session.Token + " " + multiToken) + multiToken = strings.TrimSpace(multiToken + " " + session.Token) multiSessionCookie := &http.Cookie{ - Name: model.MULTI_SESSION_TOKEN, + Name: model.SESSION_COOKIE_TOKEN, Value: multiToken, Path: "/", MaxAge: maxAge, |