Merge branch '2fa-channels-email-sms' of https://github.com/acordeddu/yii2-usuario into acordeddu-2fa-channels-email-sms

This commit is contained in:
Lorenzo Milesi
2022-08-12 09:46:32 +02:00
51 changed files with 1498 additions and 126 deletions

View File

@ -36,28 +36,30 @@ use yii\web\IdentityInterface;
* @property bool $gdpr_consent whether user has consent personal data processing
*
* Database fields:
* @property int $id
* @property string $username
* @property string $email
* @property string $unconfirmed_email
* @property string $password_hash
* @property string $auth_key
* @property string $auth_tf_key
* @property int $auth_tf_enabled
* @property string $registration_ip
* @property int $confirmed_at
* @property int $blocked_at
* @property int $flags
* @property int $created_at
* @property int $updated_at
* @property int $last_login_at
* @property int $gdpr_consent_date date of agreement of data processing
* @property string $last_login_ip
* @property int $password_changed_at
* @property int $password_age
* Defined relations:
* @property int $id
* @property string $username
* @property string $email
* @property string $unconfirmed_email
* @property string $password_hash
* @property string $auth_key
* @property string $auth_tf_key
* @property int $auth_tf_enabled
* @property string $auth_tf_type
* @property string $auth_tf_mobile_phone
* @property string $registration_ip
* @property int $confirmed_at
* @property int $blocked_at
* @property int $flags
* @property int $created_at
* @property int $updated_at
* @property int $last_login_at
* @property int $gdpr_consent_date date of agreement of data processing
* @property string $last_login_ip
* @property int $password_changed_at
* @property int $password_age
* Defined relations:
* @property SocialNetworkAccount[] $socialNetworkAccounts
* @property Profile $profile
* @property Profile $profile
*/
class User extends ActiveRecord implements IdentityInterface
{
@ -248,7 +250,9 @@ class User extends ActiveRecord implements IdentityInterface
// two factor auth rules
'twoFactorSecretTrim' => ['auth_tf_key', 'trim'],
'twoFactorSecretLength' => ['auth_tf_key', 'string', 'max' => 16],
'twoFactorEnabledNumber' => ['auth_tf_enabled', 'boolean']
'twoFactorEnabledNumber' => ['auth_tf_enabled', 'boolean'],
'twoFactorTypeLength' => ['auth_tf_type', 'string', 'max' => 20],
'twoFactorMobilePhoneLength' => ['auth_tf_mobile_phone', 'string', 'max' => 20],
];
}
@ -361,4 +365,22 @@ class User extends ActiveRecord implements IdentityInterface
return $d->diff(new \DateTime(), true)->format("%a");
}
/**
* Returns authentication two factor type enabled for the user
* @return integer
*/
public function getAuthTfType()
{
return $this->getAttribute('auth_tf_type');
}
/**
* Returns the mobile phone number used for sms authentication two factor for the user
* @return string
*/
public function getAuthTfMobilePhone()
{
return $this->getAttribute('auth_tf_mobile_phone');
}
}