Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh: Check User Birthday field #89

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 8 additions & 1 deletion validators/AgeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Yii;
use yii\validators\Validator;
use humhub\modules\user\models\User;
use humhub\modules\user\models\Group;

/**
* AgeValidator validates that the given value represents an age greater than or equal to a specified minimum age.
Expand All @@ -18,7 +19,7 @@ class AgeValidator extends Validator
public $minimumAge;

/**
* {@inheritdoc}
* @inheritdoc
*/
public function init()
{
Expand All @@ -36,6 +37,12 @@ public function init()
*/
public function validateAttribute($model, $attribute)
{
// Check if the user is a member of the admin group
if (Group::getAdminGroup()->isMember($model)) {
ArchBlood marked this conversation as resolved.
Show resolved Hide resolved
// Skip validation for admin accounts
return;
}

$value = $model->$attribute;

if (!$value instanceof DateTime) {
Expand Down