2016-01-09 08:54:07 -06:00
|
|
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/mattermost/platform/model"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (me *LogoutProvider) GetCommand(c *Context) *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,
|
2016-02-01 18:52:43 -08:00
|
|
|
AutoCompleteDesc: c.T("api.command_logout.desc"),
|
2016-01-09 08:54:07 -06:00
|
|
|
AutoCompleteHint: "",
|
2016-02-01 18:52:43 -08:00
|
|
|
DisplayName: c.T("api.command_logout.name"),
|
2016-01-09 08:54:07 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-10 13:35:16 +09:00
|
|
|
func (me *LogoutProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
2016-05-06 12:08:49 -04:00
|
|
|
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")}
|
|
|
|
|
|
|
|
|
|
// 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 != "" {
|
|
|
|
|
RevokeSessionById(c, c.Session.Id)
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return FAIL
|
|
|
|
|
}
|
|
|
|
|
return SUCCESS
|
|
|
|
|
}
|
|
|
|
|
return FAIL
|
2016-01-09 08:54:07 -06:00
|
|
|
}
|