Files
mattermost/app/command_logout.go

49 lines
1.3 KiB
Go
Raw Normal View History

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
2016-01-09 08:54:07 -06:00
package app
2016-01-09 08:54:07 -06:00
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"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,
AutoCompleteDesc: T("api.command_logout.desc"),
2016-01-09 08:54:07 -06:00
AutoCompleteHint: "",
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 {
FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_logout.fail_message")}
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
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
}