github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/command_logout.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/model"
     8  	goi18n "github.com/nicksnyder/go-i18n/i18n"
     9  )
    10  
    11  type LogoutProvider struct {
    12  }
    13  
    14  const (
    15  	CMD_LOGOUT = "logout"
    16  )
    17  
    18  func init() {
    19  	RegisterCommandProvider(&LogoutProvider{})
    20  }
    21  
    22  func (me *LogoutProvider) GetTrigger() string {
    23  	return CMD_LOGOUT
    24  }
    25  
    26  func (me *LogoutProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
    27  	return &model.Command{
    28  		Trigger:          CMD_LOGOUT,
    29  		AutoComplete:     true,
    30  		AutoCompleteDesc: T("api.command_logout.desc"),
    31  		AutoCompleteHint: "",
    32  		DisplayName:      T("api.command_logout.name"),
    33  	}
    34  }
    35  
    36  func (me *LogoutProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
    37  	FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_logout.fail_message")}
    38  	SUCCESS := &model.CommandResponse{GotoLocation: "/login"}
    39  
    40  	// We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out
    41  	if args.Session.Id != "" {
    42  		if err := a.RevokeSessionById(args.Session.Id); err != nil {
    43  			return FAIL
    44  		}
    45  		return SUCCESS
    46  	}
    47  	return FAIL
    48  }