PLT-6492 Use new cookie to determine if user is logged in (#6317)

* Use new cookie to determine if user is logged in

* Add temporary code for 3.9 to prevent forced re-login
Этот коммит содержится в:
Joram Wilander
2017-05-04 16:36:31 -04:00
коммит произвёл GitHub
родитель 1838f6c25e
Коммит fe95276ba8
7 изменённых файлов: 39 добавлений и 12 удалений

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

@@ -185,6 +185,20 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
// TEMPORARY CODE FOR 3.9, REMOVE FOR 3.10
if cookie, err := r.Cookie(model.SESSION_COOKIE_TOKEN); err == nil && c.Session.UserId != "" {
if _, err = r.Cookie(model.SESSION_COOKIE_USER); err != nil {
http.SetCookie(w, &http.Cookie{
Name: model.SESSION_COOKIE_USER,
Value: c.Session.UserId,
Path: "/",
MaxAge: cookie.MaxAge,
Expires: cookie.Expires,
Secure: cookie.Secure,
})
}
}
if h.isApi || h.isTeamIndependent { if h.isApi || h.isTeamIndependent {
c.setTeamURL(c.GetSiteURLHeader(), false) c.setTeamURL(c.GetSiteURLHeader(), false)
c.Path = r.URL.Path c.Path = r.URL.Path
@@ -357,7 +371,15 @@ func (c *Context) RemoveSessionCookie(w http.ResponseWriter, r *http.Request) {
HttpOnly: true, HttpOnly: true,
} }
userCookie := &http.Cookie{
Name: model.SESSION_COOKIE_USER,
Value: "",
Path: "/",
MaxAge: -1,
}
http.SetCookie(w, cookie) http.SetCookie(w, cookie)
http.SetCookie(w, userCookie)
} }
func (c *Context) SetInvalidParam(where string, name string) { func (c *Context) SetInvalidParam(where string, name string) {

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

@@ -122,7 +122,17 @@ func DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId
Secure: secure, Secure: secure,
} }
userCookie := &http.Cookie{
Name: model.SESSION_COOKIE_USER,
Value: user.Id,
Path: "/",
MaxAge: maxAge,
Expires: expiresAt,
Secure: secure,
}
http.SetCookie(w, sessionCookie) http.SetCookie(w, sessionCookie)
http.SetCookie(w, userCookie)
return session, nil return session, nil
} }

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

@@ -11,6 +11,7 @@ import (
const ( const (
SESSION_COOKIE_TOKEN = "MMAUTHTOKEN" SESSION_COOKIE_TOKEN = "MMAUTHTOKEN"
SESSION_COOKIE_USER = "MMUSERID"
SESSION_CACHE_SIZE = 35000 SESSION_CACHE_SIZE = 35000
SESSION_PROP_PLATFORM = "platform" SESSION_PROP_PLATFORM = "platform"
SESSION_PROP_OS = "os" SESSION_PROP_OS = "os"

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

@@ -457,7 +457,7 @@ export function clientLogout(redirectTo = '/') {
ChannelStore.clear(); ChannelStore.clear();
stopPeriodicStatusUpdates(); stopPeriodicStatusUpdates();
WebsocketActions.close(); WebsocketActions.close();
localStorage.removeItem('currentUserId'); document.cookie = 'MMUSERID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.location.href = redirectTo; window.location.href = redirectTo;
} }

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

@@ -51,8 +51,6 @@ import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/te
export function loadMe(callback) { export function loadMe(callback) {
loadMeRedux()(dispatch, getState).then( loadMeRedux()(dispatch, getState).then(
() => { () => {
localStorage.setItem('currentUserId', UserStore.getCurrentId());
if (callback) { if (callback) {
callback(); callback();
} }
@@ -741,7 +739,6 @@ export function webLogin(loginId, password, token, success, error) {
login(loginId, password, token)(dispatch, getState).then( login(loginId, password, token)(dispatch, getState).then(
(ok) => { (ok) => {
if (ok && success) { if (ok && success) {
localStorage.setItem('currentUserId', UserStore.getCurrentId());
success(); success();
} else if (!ok && error) { } else if (!ok && error) {
const serverError = getState().requests.users.login.error; const serverError = getState().requests.users.login.error;

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

@@ -13,7 +13,6 @@ import PDFJS from 'pdfjs-dist';
import * as Websockets from 'actions/websocket_actions.jsx'; import * as Websockets from 'actions/websocket_actions.jsx';
import {loadMeAndConfig} from 'actions/user_actions.jsx'; import {loadMeAndConfig} from 'actions/user_actions.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as I18n from 'i18n/i18n.jsx'; import * as I18n from 'i18n/i18n.jsx';
// Import our styles // Import our styles
@@ -61,9 +60,7 @@ function preRenderSetup(callwhendone) {
setUrl(window.location.origin); setUrl(window.location.origin);
const currentUserId = localStorage.getItem('currentUserId'); if (document.cookie.indexOf('MMUSERID=') > -1) {
if (currentUserId) {
loadMeAndConfig(() => d1.resolve()); loadMeAndConfig(() => d1.resolve());
} else { } else {
getClientConfig()(store.dispatch, store.getState).then( getClientConfig()(store.dispatch, store.getState).then(
@@ -85,7 +82,7 @@ function preRenderSetup(callwhendone) {
() => { () => {
// Turn off to prevent getting stuck in a loop // Turn off to prevent getting stuck in a loop
$(window).off('beforeunload'); $(window).off('beforeunload');
if (UserStore.getCurrentUser()) { if (document.cookie.indexOf('MMUSERID=') > -1) {
viewChannel('', ChannelStore.getCurrentId() || '')(dispatch, getState); viewChannel('', ChannelStore.getCurrentId() || '')(dispatch, getState);
} }
Websockets.close(); Websockets.close();

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

@@ -77,6 +77,9 @@ export default function configureStore(initialState) {
persistor.purge(); persistor.purge();
document.cookie = 'MMUSERID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.location.href = '/';
store.dispatch(batchActions([ store.dispatch(batchActions([
{ {
type: General.OFFLINE_STORE_RESET, type: General.OFFLINE_STORE_RESET,
@@ -84,9 +87,6 @@ export default function configureStore(initialState) {
} }
])); ]));
localStorage.removeItem('currentUserId');
window.location.href = '/';
setTimeout(() => { setTimeout(() => {
purging = false; purging = false;
}, 500); }, 500);