From d23ca07133e9bc5eed14d87af563471b4ef963cd Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Mon, 30 Jul 2018 20:55:38 +0200 Subject: Login Hooks (#9177) Tests; gofmt --- app/login.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/login.go') 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 } -- cgit v1.2.3-1-g7c22