diff --git a/protected/humhub/components/captcha/AltchaCaptcha.php b/protected/humhub/components/captcha/AltchaCaptcha.php new file mode 100644 index 0000000000..1911529bf3 --- /dev/null +++ b/protected/humhub/components/captcha/AltchaCaptcha.php @@ -0,0 +1,23 @@ +getMessage()); } - $this->addError($model, $attribute, Yii::t('base', 'We couldn\'t verify that you\'re human. Please check the box again.')); + $this->addError( + $model, + $attribute, + Yii::t('base', 'We couldn\'t verify that you\'re human. Please check the box again.') + ); } public static function getHmacKey(): ?string diff --git a/protected/humhub/components/captcha/CaptchaInterface.php b/protected/humhub/components/captcha/CaptchaInterface.php new file mode 100644 index 0000000000..ada08756ef --- /dev/null +++ b/protected/humhub/components/captcha/CaptchaInterface.php @@ -0,0 +1,17 @@ + [ 'class' => \humhub\components\Response::class, ], + 'captcha' => [ +// 'class' => \humhub\components\captcha\AltchaCaptcha::class + 'class' => \humhub\components\captcha\YiiCaptcha::class + ], 'user' => [ 'class' => \humhub\modules\user\components\User::class, 'identityClass' => \humhub\modules\user\models\User::class, @@ -67,12 +71,6 @@ $config = [ ], ], ], - 'params' => [ - 'captcha' => [ - 'inputClass' => \humhub\captcha\AltchaCaptchaInput::class, // or \humhub\captcha\YiiCaptchaInput::class - 'validatorClass' => \humhub\captcha\AltchaCaptchaValidator::class, // or \humhub\captcha\YiiCaptchaValidator::class - ], - ], 'container' => [ 'definitions' => [ 'yii\web\Cookie' => ['\humhub\libs\CookieBuilder', 'build'], diff --git a/protected/humhub/controllers/CaptchaController.php b/protected/humhub/controllers/CaptchaController.php index 25914359fd..2e588c5c65 100644 --- a/protected/humhub/controllers/CaptchaController.php +++ b/protected/humhub/controllers/CaptchaController.php @@ -2,31 +2,44 @@ /** * @link https://www.humhub.org/ - * @copyright Copyright (c) 2017 HumHub GmbH & Co. KG + * @copyright Copyright (c) 2025 HumHub GmbH & Co. KG * @license https://www.humhub.com/licences */ namespace humhub\controllers; -use humhub\captcha\AltchaCaptchaAction; +use humhub\components\access\ControllerAccess; +use humhub\components\captcha\AltchaCaptcha; +use humhub\components\captcha\AltchaCaptchaAction; +use humhub\components\captcha\YiiCaptcha; use humhub\components\Controller; +use Yii; use yii\captcha\CaptchaAction; /** + * Controller for build-in captcha actions + * * @since 1.18 */ class CaptchaController extends Controller { + public $access = ControllerAccess::class; + public function actions() { - return [ - 'yii' => [ - 'class' => CaptchaAction::class, - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ], - 'altcha' => [ - 'class' => AltchaCaptchaAction::class, - ], - ]; + if (Yii::$app->captcha instanceof AltchaCaptcha) { + return [ + 'altcha' => [ + 'class' => AltchaCaptchaAction::class, + ], + ]; + } elseif (Yii::$app->captcha instanceof YiiCaptcha) { + return [ + 'yii' => [ + 'class' => CaptchaAction::class, + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, + ], + ]; + } } } diff --git a/protected/humhub/modules/user/controllers/AuthController.php b/protected/humhub/modules/user/controllers/AuthController.php index 4b255fb3a5..6ad3c47657 100644 --- a/protected/humhub/modules/user/controllers/AuthController.php +++ b/protected/humhub/modules/user/controllers/AuthController.php @@ -73,10 +73,6 @@ class AuthController extends Controller public function actions() { return [ - 'captcha' => [ // @deprecated since 1.18.0 - 'class' => CaptchaAction::class, - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ], 'external' => [ 'class' => AuthAction::class, 'successCallback' => [$this, 'onAuthSuccess'], diff --git a/protected/humhub/modules/user/models/Invite.php b/protected/humhub/modules/user/models/Invite.php index 5b30c359d0..acce0af427 100644 --- a/protected/humhub/modules/user/models/Invite.php +++ b/protected/humhub/modules/user/models/Invite.php @@ -82,7 +82,7 @@ class Invite extends ActiveRecord [['email'], 'required'], [['email'], 'unique', 'except' => self::SCENARIO_INVITE_BY_LINK_FORM], [['email'], 'email'], - [['captcha'], Yii::$app->params['captcha']['validatorClass'], 'on' => [self::SCENARIO_INVITE, self::SCENARIO_INVITE_BY_LINK_FORM]], + [['captcha'], Yii::$app->captcha->getValidatorClass(), 'on' => [self::SCENARIO_INVITE, self::SCENARIO_INVITE_BY_LINK_FORM]], ]; } diff --git a/protected/humhub/modules/user/models/forms/AccountRecoverPassword.php b/protected/humhub/modules/user/models/forms/AccountRecoverPassword.php index cdc88fd655..b0fd01b942 100644 --- a/protected/humhub/modules/user/models/forms/AccountRecoverPassword.php +++ b/protected/humhub/modules/user/models/forms/AccountRecoverPassword.php @@ -24,7 +24,7 @@ class AccountRecoverPassword extends Model return [ ['email', 'required'], ['email', 'email'], - ['captcha', Yii::$app->params['captcha']['validatorClass']], + ['captcha', Yii::$app->captcha->getValidatorClass()], ['email', 'verifyEmail'], ]; } diff --git a/protected/humhub/modules/user/views/auth/login.php b/protected/humhub/modules/user/views/auth/login.php index 42431d7c68..877a053bae 100644 --- a/protected/humhub/modules/user/views/auth/login.php +++ b/protected/humhub/modules/user/views/auth/login.php @@ -5,6 +5,7 @@ use humhub\modules\user\models\forms\Login; use humhub\modules\user\models\Invite; use humhub\modules\user\widgets\AuthChoice; use humhub\widgets\form\ActiveForm; +use humhub\widgets\form\CaptchaField; use humhub\widgets\SiteLogo; $this->pageTitle = Yii::t('UserModule.auth', 'Login'); @@ -107,7 +108,7 @@ $this->pageTitle = Yii::t('UserModule.auth', 'Login'); field($invite, 'email')->input('email', ['id' => 'register-email', 'placeholder' => $invite->getAttributeLabel('email'), 'aria-label' => $invite->getAttributeLabel('email')])->label(false); ?> showCaptureInRegisterForm()) : ?>
diff --git a/protected/humhub/modules/user/views/auth/login_modal.php b/protected/humhub/modules/user/views/auth/login_modal.php index 48655e59cf..83dca4886c 100644 --- a/protected/humhub/modules/user/views/auth/login_modal.php +++ b/protected/humhub/modules/user/views/auth/login_modal.php @@ -5,6 +5,7 @@ use humhub\modules\user\models\forms\Login; use humhub\modules\user\models\Invite; use humhub\modules\user\widgets\AuthChoice; use humhub\widgets\form\ActiveForm; +use humhub\widgets\form\CaptchaField; use humhub\widgets\modal\Modal; use yii\helpers\ArrayHelper; use yii\helpers\Url; @@ -122,7 +123,7 @@ use yii\helpers\Url; field($invite, 'email')->input('email', ['id' => 'register-email', 'placeholder' => $invite->getAttributeLabel('email')]); ?> showCaptureInRegisterForm()) : ?> - field($invite, 'captcha')->widget(Yii::$app->params['captcha']['inputClass'])->label(false) ?> + field($invite, 'captcha')->widget(CaptchaField::class)->label(false) ?>
diff --git a/protected/humhub/modules/user/views/password-recovery/index.php b/protected/humhub/modules/user/views/password-recovery/index.php index a7b5284573..81a4c14745 100644 --- a/protected/humhub/modules/user/views/password-recovery/index.php +++ b/protected/humhub/modules/user/views/password-recovery/index.php @@ -4,6 +4,7 @@ use humhub\helpers\Html; use humhub\modules\user\models\forms\AccountRecoverPassword; use humhub\widgets\bootstrap\Button; use humhub\widgets\form\ActiveForm; +use humhub\widgets\form\CaptchaField; use humhub\widgets\SiteLogo; use yii\helpers\Url; @@ -31,7 +32,7 @@ $this->pageTitle = Yii::t('UserModule.auth', 'Password recovery'); field($model, 'email')->textInput(['class' => 'form-control', 'id' => 'email_txt', 'placeholder' => Yii::t('UserModule.auth', 'Your email')])->label(false) ?>
- field($model, 'captcha')->widget(Yii::$app->params['captcha']['inputClass'])->label(false); + field($model, 'captcha')->widget(CaptchaField::class)->label(false); ?>
diff --git a/protected/humhub/modules/user/views/password-recovery/index_modal.php b/protected/humhub/modules/user/views/password-recovery/index_modal.php index fafea3ecba..de9ea7e7b2 100644 --- a/protected/humhub/modules/user/views/password-recovery/index_modal.php +++ b/protected/humhub/modules/user/views/password-recovery/index_modal.php @@ -2,6 +2,7 @@ use humhub\helpers\Html; use humhub\modules\user\models\forms\AccountRecoverPassword; +use humhub\widgets\form\CaptchaField; use humhub\widgets\modal\Modal; use yii\helpers\Url; @@ -22,7 +23,7 @@ use yii\helpers\Url;
- field($model, 'captcha')->widget(Yii::$app->params['captcha']['inputClass'])->label(false) ?> + field($model, 'captcha')->widget(CaptchaField::class)->label(false) ?>

diff --git a/protected/humhub/modules/user/views/registration/byLink.php b/protected/humhub/modules/user/views/registration/byLink.php index 7aed3814a2..d9bf91f1c1 100644 --- a/protected/humhub/modules/user/views/registration/byLink.php +++ b/protected/humhub/modules/user/views/registration/byLink.php @@ -4,6 +4,7 @@ use humhub\helpers\Html; use humhub\modules\user\models\Invite; use humhub\modules\user\widgets\AuthChoice; use humhub\widgets\form\ActiveForm; +use humhub\widgets\form\CaptchaField; use humhub\widgets\SiteLogo; /** @@ -42,7 +43,7 @@ $this->pageTitle = Yii::t('UserModule.auth', 'Create Account'); field($invite, 'email')->input('email', ['id' => 'register-email', 'placeholder' => $invite->getAttributeLabel('email'), 'aria-label' => $invite->getAttributeLabel('email')])->label(false); ?> showCaptureInRegisterForm()) : ?>
diff --git a/protected/humhub/widgets/form/CaptchaField.php b/protected/humhub/widgets/form/CaptchaField.php new file mode 100644 index 0000000000..c32a8778a4 --- /dev/null +++ b/protected/humhub/widgets/form/CaptchaField.php @@ -0,0 +1,21 @@ +captcha->createInputWidget($config); + } +}