From 2a91e5e031d9490f8364d55cb023d384d56f047f Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 30 Dec 2016 13:12:43 -0500 Subject: Clean up /logout command flow and errors (#4918) --- api/command_logout.go | 2 +- i18n/en.json | 4 ---- webapp/actions/global_actions.jsx | 22 +++++++++++++--------- webapp/components/create_post.jsx | 5 +++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/api/command_logout.go b/api/command_logout.go index 474f0b58e..00375bb58 100644 --- a/api/command_logout.go +++ b/api/command_logout.go @@ -34,7 +34,7 @@ func (me *LogoutProvider) GetCommand(c *Context) *model.Command { func (me *LogoutProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse { FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.fail_message")} - SUCCESS := &model.CommandResponse{GotoLocation: "/", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")} + SUCCESS := &model.CommandResponse{GotoLocation: "/login"} // We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out if c.Session.Id != "" { diff --git a/i18n/en.json b/i18n/en.json index 1744f02b1..96961718e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -571,10 +571,6 @@ "id": "api.command_logout.name", "translation": "logout" }, - { - "id": "api.command_logout.success_message", - "translation": "Logging out..." - }, { "id": "api.command_me.desc", "translation": "Do an action" diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index 5ee1e16a5..f1714def2 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -476,15 +476,7 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr BrowserStore.signalLogout(); } - BrowserStore.clear(); - ErrorStore.clearLastError(); - PreferenceStore.clear(); - UserStore.clear(); - TeamStore.clear(); - newLocalizationSelected(global.window.mm_config.DefaultClientLocale); - stopPeriodicStatusUpdates(); - WebsocketActions.close(); - browserHistory.push(redirectTo); + clientLogout(redirectTo); }, () => { browserHistory.push(redirectTo); @@ -492,6 +484,18 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr ); } +export function clientLogout(redirectTo = '/') { + BrowserStore.clear(); + ErrorStore.clearLastError(); + PreferenceStore.clear(); + UserStore.clear(); + TeamStore.clear(); + newLocalizationSelected(global.window.mm_config.DefaultClientLocale); + stopPeriodicStatusUpdates(); + WebsocketActions.close(); + browserHistory.push(redirectTo); +} + export function emitSearchMentionsEvent(user) { let terms = ''; if (user.notify_props && user.notify_props.mention_keys) { diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx index 8e75b6070..13a8c729f 100644 --- a/webapp/components/create_post.jsx +++ b/webapp/components/create_post.jsx @@ -125,6 +125,11 @@ export default class CreatePost extends React.Component { (data) => { this.setState({submitting: false}); + if (post.message.trim() === '/logout') { + GlobalActions.clientLogout(data.goto_location); + return; + } + if (data.goto_location && data.goto_location.length > 0) { browserHistory.push(data.goto_location); } -- cgit v1.2.3-1-g7c22