From 75c7c2c984f8c29bb71466e962dc4aa784bdeb41 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Tue, 25 Oct 2016 19:38:44 +0200 Subject: [PATCH] More flexibility for custom AuthClients; also deny automatic authclient registration when disabled --- .../modules/user/authclient/AuthAction.php | 46 +++++++++++++++++++ .../authclient/interfaces/ApprovalBypass.php | 5 +- .../interfaces/StandaloneAuthClient.php | 31 +++++++++++++ .../user/controllers/AuthController.php | 9 +++- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 protected/humhub/modules/user/authclient/AuthAction.php create mode 100644 protected/humhub/modules/user/authclient/interfaces/StandaloneAuthClient.php diff --git a/protected/humhub/modules/user/authclient/AuthAction.php b/protected/humhub/modules/user/authclient/AuthAction.php new file mode 100644 index 0000000000..4631195511 --- /dev/null +++ b/protected/humhub/modules/user/authclient/AuthAction.php @@ -0,0 +1,46 @@ +authAction($this); + } + + return parent::auth($client); + } + + /** + * @inheritdoc + */ + public function authSuccess($client) + { + return parent::authSuccess($client); + } + +} diff --git a/protected/humhub/modules/user/authclient/interfaces/ApprovalBypass.php b/protected/humhub/modules/user/authclient/interfaces/ApprovalBypass.php index 2c96ca8a20..c0fa590738 100644 --- a/protected/humhub/modules/user/authclient/interfaces/ApprovalBypass.php +++ b/protected/humhub/modules/user/authclient/interfaces/ApprovalBypass.php @@ -9,8 +9,9 @@ namespace humhub\modules\user\authclient\interfaces; /** - * ApprovalBypass interface allow user approvals of an authclient - * + * ApprovalBypass interface allow automatic user approvals of an authclient. + * If registration is disabled, users can register via this authclient anyway. + * * @since 1.1 * @author luke */ diff --git a/protected/humhub/modules/user/authclient/interfaces/StandaloneAuthClient.php b/protected/humhub/modules/user/authclient/interfaces/StandaloneAuthClient.php new file mode 100644 index 0000000000..edb2156cbf --- /dev/null +++ b/protected/humhub/modules/user/authclient/interfaces/StandaloneAuthClient.php @@ -0,0 +1,31 @@ + 'yii\captcha\CaptchaAction', ], 'external' => [ - 'class' => 'yii\authclient\AuthAction', + 'class' => AuthAction::className(), 'successCallback' => [$this, 'onAuthSuccess'], ], ]; @@ -115,6 +117,11 @@ class AuthController extends Controller return $this->login($user, $authClient); } + if (!$authClient instanceof ApprovalBypass && !Yii::$app->getModule('user')->settings->get('auth.anonymousRegistration')) { + Yii::$app->session->setFlash('error', Yii::t('UserModule.base', "You're not registered.")); + return $this->redirect(['/user/auth/login']); + } + // Check if E-Mail is given if (!isset($attributes['email'])) { Yii::$app->session->setFlash('error', "Missing E-Mail Attribute from AuthClient.");