PHP-CS-Fixer run
This commit is contained in:
@ -13,16 +13,15 @@ namespace Da\User\Validator;
|
||||
|
||||
use Da\TwoFA\Exception\InvalidSecretKeyException;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Service\TwoFactorEmailCodeGeneratorService;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Service\TwoFactorEmailCodeGeneratorService;
|
||||
|
||||
|
||||
class TwoFactorEmailValidator extends TwoFactorCodeValidator
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
|
||||
protected $user;
|
||||
protected $code;
|
||||
protected $cycles;
|
||||
@ -31,9 +30,9 @@ class TwoFactorEmailValidator extends TwoFactorCodeValidator
|
||||
/**
|
||||
* TwoFactorCodeValidator constructor.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @param string $code
|
||||
* @param int $cycles
|
||||
* @param int $cycles
|
||||
*/
|
||||
public function __construct(User $user, $code, $cycles = 0)
|
||||
{
|
||||
@ -50,21 +49,22 @@ class TwoFactorEmailValidator extends TwoFactorCodeValidator
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if(is_null($this->code) || $this->code == '' )
|
||||
if (is_null($this->code) || $this->code == '') {
|
||||
return false;
|
||||
}
|
||||
$emailCodeTime = new \DateTime(Yii::$app->session->get("email_code_time"));
|
||||
$currentTime = new \DateTime('now');
|
||||
$interval = $currentTime->getTimestamp()-$emailCodeTime->getTimestamp();
|
||||
|
||||
$interval = $currentTime->getTimestamp() - $emailCodeTime->getTimestamp();
|
||||
|
||||
$module = Yii::$app->getModule('user');
|
||||
$validators = $module->twoFactorAuthenticationValidators;
|
||||
$codeDurationTime = ArrayHelper::getValue($validators,$this->type.'.codeDurationTime', 300);
|
||||
|
||||
if($interval > $codeDurationTime ){
|
||||
$codeDurationTime = ArrayHelper::getValue($validators, $this->type.'.codeDurationTime', 300);
|
||||
|
||||
if ($interval > $codeDurationTime) {
|
||||
return false;
|
||||
}
|
||||
$emailCode = Yii::$app->session->get("email_code");
|
||||
return $this->code==$emailCode;
|
||||
return $this->code == $emailCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,29 +86,31 @@ class TwoFactorEmailValidator extends TwoFactorCodeValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @param mixed $codeDurationTime
|
||||
* @return string
|
||||
*/
|
||||
public function getUnsuccessMessage($codeDurationTime)
|
||||
{
|
||||
return Yii::t('usuario', 'Please, enter the right code. The code is valid for {0} seconds. If you want to get a new code, please close this window and repeat the enabling request.', [$codeDurationTime]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @param mixed $codeDurationTime
|
||||
* @return string
|
||||
*/
|
||||
public function getUnsuccessLoginMessage($codeDurationTime)
|
||||
{
|
||||
return Yii::t('usuario', 'Please, enter the right code. The code is valid for {0} seconds. If you want to get a new code, please click on \'Cancel\' and repeat the login request.', [$codeDurationTime]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function generateCode()
|
||||
{
|
||||
return $this->make(TwoFactorEmailCodeGeneratorService::class,$this->user)->run();
|
||||
return $this->make(TwoFactorEmailCodeGeneratorService::class, $this->user)->run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user