diff options
author | Daniel Schalla <daniel@schalla.me> | 2018-07-30 20:55:38 +0200 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-07-30 11:55:38 -0700 |
commit | d23ca07133e9bc5eed14d87af563471b4ef963cd (patch) | |
tree | ae01bb8f09600110c22a5f881be24e8d6f204986 /app/login.go | |
parent | 08e54ed8244e2ec9a278d16f80d5ed2a8e2964f4 (diff) | |
download | chat-d23ca07133e9bc5eed14d87af563471b4ef963cd.tar.gz chat-d23ca07133e9bc5eed14d87af563471b4ef963cd.tar.bz2 chat-d23ca07133e9bc5eed14d87af563471b4ef963cd.zip |
Login Hooks (#9177)
Tests; gofmt
Diffstat (limited to 'app/login.go')
-rw-r--r-- | app/login.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/login.go b/app/login.go index d3d2a423e..0d22f2635 100644 --- a/app/login.go +++ b/app/login.go @@ -11,6 +11,7 @@ import ( "github.com/avct/uasurfer" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" "github.com/mattermost/mattermost-server/store" ) @@ -65,6 +66,27 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken string, l return nil, err } + if a.PluginsReady() { + var rejectionReason string + pluginContext := &plugin.Context{} + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + rejectionReason = hooks.UserWillLogIn(pluginContext, user) + return rejectionReason == "" + }, plugin.UserWillLogInId) + + if rejectionReason != "" { + return nil, model.NewAppError("AuthenticateUserForLogin", "Login rejected by plugin: "+rejectionReason, nil, "", http.StatusBadRequest) + } + + a.Go(func() { + pluginContext := &plugin.Context{} + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + hooks.UserHasLoggedIn(pluginContext, user) + return true + }, plugin.UserHasLoggedInId) + }) + } + return user, nil } |