2019-11-29 12:59:40 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2016-01-09 08:54:07 -06:00
|
|
|
|
2017-03-13 09:23:16 -04:00
|
|
|
package app
|
2016-01-09 08:54:07 -06:00
|
|
|
|
|
|
|
|
import (
|
2019-04-23 09:33:42 -04:00
|
|
|
goi18n "github.com/mattermost/go-i18n/i18n"
|
2019-11-28 14:39:38 +01:00
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
2016-01-09 08:54:07 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type LogoutProvider struct {
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 18:52:43 -08:00
|
|
|
const (
|
|
|
|
|
CMD_LOGOUT = "logout"
|
|
|
|
|
)
|
|
|
|
|
|
2016-01-09 08:54:07 -06:00
|
|
|
func init() {
|
|
|
|
|
RegisterCommandProvider(&LogoutProvider{})
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 18:52:43 -08:00
|
|
|
func (me *LogoutProvider) GetTrigger() string {
|
|
|
|
|
return CMD_LOGOUT
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 14:46:20 -06:00
|
|
|
func (me *LogoutProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
|
2016-01-09 08:54:07 -06:00
|
|
|
return &model.Command{
|
2016-02-01 18:52:43 -08:00
|
|
|
Trigger: CMD_LOGOUT,
|
2016-01-09 08:54:07 -06:00
|
|
|
AutoComplete: true,
|
2017-03-13 09:23:16 -04:00
|
|
|
AutoCompleteDesc: T("api.command_logout.desc"),
|
2016-01-09 08:54:07 -06:00
|
|
|
AutoCompleteHint: "",
|
2017-03-13 09:23:16 -04:00
|
|
|
DisplayName: T("api.command_logout.name"),
|
2016-01-09 08:54:07 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 12:01:44 -05:00
|
|
|
func (me *LogoutProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
2017-03-13 09:23:16 -04:00
|
|
|
FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_logout.fail_message")}
|
2016-12-30 13:12:43 -05:00
|
|
|
SUCCESS := &model.CommandResponse{GotoLocation: "/login"}
|
2016-05-06 12:08:49 -04:00
|
|
|
|
|
|
|
|
// We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out
|
2017-03-13 09:23:16 -04:00
|
|
|
if args.Session.Id != "" {
|
2017-09-14 12:01:44 -05:00
|
|
|
if err := a.RevokeSessionById(args.Session.Id); err != nil {
|
2016-05-06 12:08:49 -04:00
|
|
|
return FAIL
|
|
|
|
|
}
|
|
|
|
|
return SUCCESS
|
|
|
|
|
}
|
|
|
|
|
return FAIL
|
2016-01-09 08:54:07 -06:00
|
|
|
}
|