PHP-CS-Fixer run

This commit is contained in:
Lorenzo Milesi
2022-08-15 08:16:03 +02:00
parent 7fb900dfe1
commit ca84ceca4b
26 changed files with 233 additions and 234 deletions

View File

@ -15,8 +15,8 @@ use Da\TwoFA\Exception\InvalidSecretKeyException;
use Da\TwoFA\Manager;
use Da\User\Contracts\ValidatorInterface;
use Da\User\Model\User;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Service\TwoFactorQrCodeUriGeneratorService;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
class TwoFactorCodeValidator implements ValidatorInterface
@ -61,18 +61,19 @@ class TwoFactorCodeValidator implements ValidatorInterface
return false;
}
/**
* @return string
*
*/
/**
* @return string
*
*/
public function getSuccessMessage()
{
return Yii::t('usuario', 'Two factor authentication successfully enabled.');
}
/**
* @return string
*
* @param mixed $codeDurationTime
* @return string
*/
public function getUnsuccessMessage($codeDurationTime)
{
@ -80,20 +81,21 @@ class TwoFactorCodeValidator implements ValidatorInterface
}
/**
* @return string
*
* @param mixed $codeDurationTime
* @return string
*/
public function getUnsuccessLoginMessage($codeDurationTime)
{
return Yii::t('usuario', 'Verification failed. Please, enter new code.');
}
/**
* @return string
*
*/
/**
* @return string
*
*/
public function generateCode()
{
return $this->make(TwoFactorQrCodeUriGeneratorService::class,[$this->user])->run();
return $this->make(TwoFactorQrCodeUriGeneratorService::class, [$this->user])->run();
}
}

View File

@ -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();
}
}

View File

@ -13,16 +13,15 @@ namespace Da\User\Validator;
use Da\TwoFA\Exception\InvalidSecretKeyException;
use Da\User\Model\User;
use Da\User\Service\TwoFactorSmsCodeGeneratorService;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
use yii\helpers\ArrayHelper;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Service\TwoFactorSmsCodeGeneratorService;
class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
{
use ContainerAwareTrait;
protected $user;
protected $code;
protected $cycles;
@ -38,7 +37,7 @@ class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
public function __construct(User $user, $code, $cycles = 0)
{
$this->user = $user;
$this->code = $code;
$this->cycles = $cycles;
$this->type = 'sms';
@ -51,20 +50,21 @@ class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
*/
public function validate()
{
if(is_null($this->code) || $this->code == '' )
return false;
if (is_null($this->code) || $this->code == '') {
return false;
}
$smsCodeTime = new \DateTime(Yii::$app->session->get("sms_code_time"));
$currentTime = new \DateTime('now');
$interval = $currentTime->getTimestamp()-$smsCodeTime->getTimestamp();
$interval = $currentTime->getTimestamp() - $smsCodeTime->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;
}
$smsCode = Yii::$app->session->get("sms_code");
return $this->code==$smsCode;
return $this->code == $smsCode;
}
/**
@ -77,8 +77,9 @@ class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
}
/**
* @return string
*
* @param mixed $codeDurationTime
* @return string
*/
public function getUnsuccessMessage($codeDurationTime)
{
@ -86,21 +87,22 @@ class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
}
/**
* @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()
{
$object = $this->make(TwoFactorSmsCodeGeneratorService::class,[$this->user]);
$object = $this->make(TwoFactorSmsCodeGeneratorService::class, [$this->user]);
return $object->run();
}
}