PHP-CS-Fixer run
This commit is contained in:
@ -27,9 +27,9 @@ use yii\base\Event as YiiEvent;
|
||||
use yii\base\Exception;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\console\Application as ConsoleApplication;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\i18n\PhpMessageSource;
|
||||
use yii\web\Application as WebApplication;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* Bootstrap class of the yii2-usuario extension. Configures container services, initializes translations,
|
||||
@ -134,7 +134,7 @@ class Bootstrap implements BootstrapInterface
|
||||
if (in_array($name, ['User', 'Profile', 'Token', 'SocialNetworkAccount', 'SessionHistory'])) {
|
||||
$di->set(
|
||||
"Da\\User\\Query\\{$name}Query",
|
||||
function() use($model) {
|
||||
function () use ($model) {
|
||||
return $model::find();
|
||||
}
|
||||
);
|
||||
@ -168,34 +168,36 @@ class Bootstrap implements BootstrapInterface
|
||||
// Initialize array of two factor authentication validators available
|
||||
$defaultTwoFactorAuthenticationValidators =
|
||||
[
|
||||
'google-authenticator'=>[
|
||||
'class'=>\Da\User\Validator\TwoFactorCodeValidator::class,
|
||||
'description'=>Yii::t('usuario', 'Google Authenticator'),
|
||||
'configurationUrl'=>'user/settings/two-factor',
|
||||
'enabled'=>true
|
||||
'google-authenticator' => [
|
||||
'class' => \Da\User\Validator\TwoFactorCodeValidator::class,
|
||||
'description' => Yii::t('usuario', 'Google Authenticator'),
|
||||
'configurationUrl' => 'user/settings/two-factor',
|
||||
'enabled' => true
|
||||
],
|
||||
'email'=>[
|
||||
'class'=>\Da\User\Validator\TwoFactorEmailValidator::class,
|
||||
'description'=>Yii::t('usuario', 'Email'),
|
||||
'configurationUrl'=>'user/settings/two-factor-email',
|
||||
'email' => [
|
||||
'class' => \Da\User\Validator\TwoFactorEmailValidator::class,
|
||||
'description' => Yii::t('usuario', 'Email'),
|
||||
'configurationUrl' => 'user/settings/two-factor-email',
|
||||
// Time duration of the code in seconds
|
||||
'codeDurationTime'=>300,
|
||||
'enabled'=>true
|
||||
'codeDurationTime' => 300,
|
||||
'enabled' => true
|
||||
],
|
||||
'sms'=>[
|
||||
'class'=>\Da\User\Validator\TwoFactorTextMessageValidator::class,
|
||||
'description'=>Yii::t('usuario', 'Text message'),
|
||||
'configurationUrl'=>'user/settings/two-factor-sms',
|
||||
'sms' => [
|
||||
'class' => \Da\User\Validator\TwoFactorTextMessageValidator::class,
|
||||
'description' => Yii::t('usuario', 'Text message'),
|
||||
'configurationUrl' => 'user/settings/two-factor-sms',
|
||||
// component for sending sms
|
||||
'smsSender'=>'smsSender',
|
||||
'smsSender' => 'smsSender',
|
||||
// Time duration of the code in seconds
|
||||
'codeDurationTime'=>300,
|
||||
'enabled'=>true
|
||||
'codeDurationTime' => 300,
|
||||
'enabled' => true
|
||||
]
|
||||
];
|
||||
|
||||
$app->getModule('user')->twoFactorAuthenticationValidators = ArrayHelper::merge(
|
||||
$defaultTwoFactorAuthenticationValidators, $app->getModule('user')->twoFactorAuthenticationValidators);
|
||||
$defaultTwoFactorAuthenticationValidators,
|
||||
$app->getModule('user')->twoFactorAuthenticationValidators
|
||||
);
|
||||
|
||||
if ($app instanceof WebApplication) {
|
||||
// override Yii
|
||||
@ -208,11 +210,6 @@ class Bootstrap implements BootstrapInterface
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception $e) {
|
||||
die($e);
|
||||
}
|
||||
|
||||
@ -357,6 +357,7 @@ class AdminController extends Controller
|
||||
|
||||
/**
|
||||
* Display list session history
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function actionSessionHistory($id)
|
||||
{
|
||||
@ -376,6 +377,7 @@ class AdminController extends Controller
|
||||
|
||||
/**
|
||||
* Terminate all session user
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function actionTerminateSessions($id)
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
@ -15,6 +15,7 @@ use Da\User\Contracts\AuthClientInterface;
|
||||
use Da\User\Event\FormEvent;
|
||||
use Da\User\Event\UserEvent;
|
||||
use Da\User\Form\LoginForm;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Query\SocialNetworkAccountQuery;
|
||||
use Da\User\Service\SocialNetworkAccountConnectService;
|
||||
use Da\User\Service\SocialNetworkAuthenticateService;
|
||||
@ -22,7 +23,6 @@ use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Da\User\Validator\TwoFactorEmailValidator;
|
||||
use Da\User\Validator\TwoFactorTextMessageValidator;
|
||||
use Da\User\Model\User;
|
||||
use Yii;
|
||||
use yii\authclient\AuthAction;
|
||||
use yii\base\InvalidConfigException;
|
||||
@ -30,10 +30,10 @@ use yii\base\InvalidParamException;
|
||||
use yii\base\Module;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class SecurityController extends Controller
|
||||
{
|
||||
@ -216,24 +216,22 @@ class SecurityController extends Controller
|
||||
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$module = Yii::$app->getModule('user');
|
||||
$validators = $module->twoFactorAuthenticationValidators;
|
||||
$credentials=Yii::$app->session->get('credentials');
|
||||
$login= $credentials['login'];
|
||||
$user = User::findOne(['email'=>$login]);
|
||||
if( $user==null){
|
||||
$user = User::findOne(['username'=>$login]);
|
||||
$credentials = Yii::$app->session->get('credentials');
|
||||
$login = $credentials['login'];
|
||||
$user = User::findOne(['email' => $login]);
|
||||
if ($user == null) {
|
||||
$user = User::findOne(['username' => $login]);
|
||||
}
|
||||
$tfType = $user->getAuthTfType();
|
||||
|
||||
$class = ArrayHelper::getValue($validators,$tfType.'.class');
|
||||
$class = ArrayHelper::getValue($validators, $tfType.'.class');
|
||||
$object = $this
|
||||
->make($class, [$user, null, $this->module->twoFactorAuthenticationCycles]);
|
||||
|
||||
$object->generateCode();
|
||||
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
@ -273,5 +271,4 @@ class SecurityController extends Controller
|
||||
|
||||
$this->make(SocialNetworkAccountConnectService::class, [$this, $client])->run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
@ -29,8 +29,8 @@ use Da\User\Query\UserQuery;
|
||||
use Da\User\Search\SessionHistorySearch;
|
||||
use Da\User\Service\EmailChangeService;
|
||||
use Da\User\Service\SessionHistory\TerminateUserSessionsService;
|
||||
use Da\User\Service\TwoFactorQrCodeUriGeneratorService;
|
||||
use Da\User\Service\TwoFactorEmailCodeGeneratorService;
|
||||
use Da\User\Service\TwoFactorQrCodeUriGeneratorService;
|
||||
use Da\User\Service\TwoFactorSmsCodeGeneratorService;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
@ -453,7 +453,7 @@ class SettingsController extends Controller
|
||||
|
||||
public function actionTwoFactor($id)
|
||||
{
|
||||
$choice=Yii::$app->request->post('choice');
|
||||
$choice = Yii::$app->request->post('choice');
|
||||
/** @var User $user */
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
@ -470,7 +470,7 @@ class SettingsController extends Controller
|
||||
return $this->renderAjax('two-factor-email', ['id' => $id, 'code' => $emailCode]);
|
||||
case 'sms':
|
||||
// get mobile phone, if exists
|
||||
$mobilePhone=$user->getAuthTfMobilePhone();
|
||||
$mobilePhone = $user->getAuthTfMobilePhone();
|
||||
$smsCode = $this->make(TwoFactorSmsCodeGeneratorService::class, [$user])->run();
|
||||
return $this->renderAjax('two-factor-sms', ['id' => $id, 'code' => $smsCode, 'mobilePhone' => $mobilePhone]);
|
||||
}
|
||||
@ -564,6 +564,41 @@ class SettingsController extends Controller
|
||||
return $this->redirect(['session-history']);
|
||||
}
|
||||
|
||||
public function actionTwoFactorMobilePhone($id)
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
if (null === $user) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => Yii::t('usuario', 'User not found.')
|
||||
];
|
||||
}
|
||||
$mobilePhone = Yii::$app->request->get('mobilephone');
|
||||
$currentMobilePhone = $user->getAuthTfMobilePhone();
|
||||
$success = false;
|
||||
if ($currentMobilePhone == $mobilePhone) {
|
||||
$success = true;
|
||||
} else {
|
||||
$success = $user->updateAttributes(['auth_tf_mobile_phone' => $mobilePhone]);
|
||||
$success = $success && $this->make(TwoFactorSmsCodeGeneratorService::class, [$user])->run();
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $success,
|
||||
'message' => $success
|
||||
? Yii::t('usuario', 'Mobile phone number successfully enabled.')
|
||||
: Yii::t('usuario', 'Error while enabling SMS two factor authentication. Please reload the page.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @throws ForbiddenHttpException
|
||||
@ -593,39 +628,4 @@ class SettingsController extends Controller
|
||||
$account->delete();
|
||||
$this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_DISCONNECT, $event);
|
||||
}
|
||||
|
||||
public function actionTwoFactorMobilePhone($id)
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
if (null === $user) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => Yii::t('usuario', 'User not found.')
|
||||
];
|
||||
}
|
||||
$mobilePhone = Yii::$app->request->get('mobilephone');
|
||||
$currentMobilePhone = $user->getAuthTfMobilePhone();
|
||||
$success=false;
|
||||
if ($currentMobilePhone==$mobilePhone) {
|
||||
$success=true;
|
||||
} else {
|
||||
$success = $user->updateAttributes(['auth_tf_mobile_phone' => $mobilePhone]);
|
||||
$success = $success && $this->make(TwoFactorSmsCodeGeneratorService::class, [$user])->run();
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $success,
|
||||
'message' => $success
|
||||
? Yii::t('usuario', 'Mobile phone number successfully enabled.')
|
||||
: Yii::t('usuario', 'Error while enabling SMS two factor authentication. Please reload the page.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ class MailFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @param String $code
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
|
||||
@ -13,10 +13,9 @@ namespace Da\User\Filter;
|
||||
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Module;
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\ActionFilter;
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
|
||||
|
||||
class TwoFactorAuthenticationEnforceFilter extends ActionFilter
|
||||
{
|
||||
@ -40,9 +39,9 @@ class TwoFactorAuthenticationEnforceFilter extends ActionFilter
|
||||
|
||||
$permissions = $module->twoFactorAuthenticationForcedPermissions;
|
||||
$itemsByUser = array_keys($this->getAuthManager()->getItemsByUser(Yii::$app->user->identity->id));
|
||||
if(!empty(array_intersect($permissions, $itemsByUser))){
|
||||
if (!empty(array_intersect($permissions, $itemsByUser))) {
|
||||
Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your role requires 2FA, you won\'t be able to use the application until you enable it'));
|
||||
return Yii::$app->response->redirect(['/user/settings/account'])->send();
|
||||
return Yii::$app->response->redirect(['/user/settings/account'])->send();
|
||||
}
|
||||
|
||||
return parent::beforeAction($action);
|
||||
|
||||
@ -14,8 +14,8 @@ namespace Da\User\Form;
|
||||
use Da\User\Helper\SecurityHelper;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Query\UserQuery;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Da\User\Validator\TwoFactorCodeValidator;
|
||||
use Da\User\Validator\TwoFactorEmailValidator;
|
||||
use Da\User\Validator\TwoFactorTextMessageValidator;
|
||||
@ -112,16 +112,15 @@ class LoginForm extends Model
|
||||
'twoFactorAuthenticationCodeValidate' => [
|
||||
'twoFactorAuthenticationCode',
|
||||
function ($attribute) {
|
||||
|
||||
if ($this->user === null ) {
|
||||
if ($this->user === null) {
|
||||
$this->addError($attribute, Yii::t('usuario', 'Invalid two factor authentication code'));
|
||||
}else{
|
||||
} else {
|
||||
$module = Yii::$app->getModule('user');
|
||||
$validators = $module->twoFactorAuthenticationValidators;
|
||||
$type = $this->user->auth_tf_type;
|
||||
$class = ArrayHelper::getValue($validators,$type.'.class');
|
||||
$codeDurationTime = ArrayHelper::getValue($validators,$type.'.codeDurationTime', 300);
|
||||
$validator = $this
|
||||
$class = ArrayHelper::getValue($validators, $type.'.class');
|
||||
$codeDurationTime = ArrayHelper::getValue($validators, $type.'.codeDurationTime', 300);
|
||||
$validator = $this
|
||||
->make($class, [$this->user, $this->twoFactorAuthenticationCode, $this->module->twoFactorAuthenticationCycles]);
|
||||
$success = $validator->validate();
|
||||
if (!$success) {
|
||||
|
||||
@ -14,7 +14,6 @@ namespace Da\User\Migration\Session;
|
||||
use Da\User\Helper\MigrationHelper;
|
||||
use yii\db\Migration;
|
||||
|
||||
|
||||
class m000000_000001_create_session_history_table extends Migration
|
||||
{
|
||||
const SESSION_HISTORY_TABLE = '{{%session_history}}';
|
||||
|
||||
@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Migration;
|
||||
|
||||
use yii\db\Migration;
|
||||
@ -16,7 +25,6 @@ class m000000_000010_add_auth_tf_type_auth_tf_mobile_phone_columns_to_user_table
|
||||
{
|
||||
$this->addColumn('{{%user}}', 'auth_tf_type', $this->string(20)->after('auth_tf_enabled')->null());
|
||||
$this->addColumn('{{%user}}', 'auth_tf_mobile_phone', $this->string(20)->after('auth_tf_type')->null());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -16,16 +16,16 @@ use Da\User\Query\SessionHistoryQuery;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* @property int $user_id
|
||||
* @property int $user_id
|
||||
* @property string $session_id
|
||||
* @property string $user_agent
|
||||
* @property string $ip
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
*
|
||||
* @property User $user
|
||||
* @property bool $isActive
|
||||
|
||||
@ -36,30 +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 $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 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
|
||||
{
|
||||
|
||||
@ -24,17 +24,17 @@ class Module extends BaseModule
|
||||
{
|
||||
/**
|
||||
* @var bool Enable the 'session history' function
|
||||
* Using with {@see SessionHistoryDecorator}
|
||||
* Using with {@see SessionHistoryDecorator}
|
||||
*/
|
||||
public $enableSessionHistory = false;
|
||||
/**
|
||||
* @var int|bool The number of 'session history' records will be stored for user
|
||||
* if equals false records will not be deleted
|
||||
* if equals false records will not be deleted
|
||||
*/
|
||||
public $numberSessionHistory = false;
|
||||
/**
|
||||
* @var int|bool The time after which the expired 'session history' will be deleted
|
||||
* if equals false records will not be deleted
|
||||
* if equals false records will not be deleted
|
||||
*/
|
||||
public $timeoutSessionHistory = false;
|
||||
/**
|
||||
@ -96,9 +96,9 @@ class Module extends BaseModule
|
||||
* @var bool whether to enable two factor authentication or not
|
||||
*/
|
||||
public $enableTwoFactorAuthentication = false;
|
||||
/**
|
||||
* @var array list of permissions for which two factor authentication is mandatory
|
||||
*/
|
||||
/**
|
||||
* @var array list of permissions for which two factor authentication is mandatory
|
||||
*/
|
||||
public $twoFactorAuthenticationForcedPermissions = [];
|
||||
/**
|
||||
* @var array list of channels for two factor authentication availables
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
namespace Da\User\Query;
|
||||
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use yii\web\Session;
|
||||
use Yii;
|
||||
use yii\web\Session;
|
||||
|
||||
class SessionHistoryCondition
|
||||
{
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
namespace Da\User\Query;
|
||||
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use yii\db\ActiveQuery;
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
class SessionHistoryQuery extends ActiveQuery
|
||||
{
|
||||
@ -34,7 +34,6 @@ class SessionHistoryQuery extends ActiveQuery
|
||||
return $this->andWhere($this->getCondition()->inactive($userId));
|
||||
}
|
||||
|
||||
|
||||
public function whereExpired($userId)
|
||||
{
|
||||
return $this->andWhere($this->getCondition()->expired($userId));
|
||||
|
||||
@ -17,7 +17,6 @@ use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
|
||||
class SessionHistorySearch extends SessionHistory
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Da\User\Service\SessionHistory;
|
||||
|
||||
|
||||
use yii\web\DbSession;
|
||||
|
||||
class DBTerminateSessionsService implements TerminateSessionsServiceInterface
|
||||
|
||||
@ -16,9 +16,9 @@ use Da\User\Query\SessionHistoryCondition;
|
||||
use Da\User\Query\SessionHistoryQuery;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\InvalidArgumentException as BaseInvalidArgumentException;
|
||||
use yii\db\Exception;
|
||||
use yii\web\Session;
|
||||
use yii\base\InvalidArgumentException as BaseInvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Decorator for the {@see Session} class for storing the 'session history'
|
||||
@ -255,7 +255,6 @@ class SessionHistoryDecorator extends Session
|
||||
return $result;
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -404,9 +403,9 @@ class SessionHistoryDecorator extends Session
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return bool
|
||||
* @param string $id
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
protected function unbindSessionHistory($id)
|
||||
{
|
||||
@ -419,9 +418,9 @@ class SessionHistoryDecorator extends Session
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $userId
|
||||
* @return bool
|
||||
* @param int $userId
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
protected function displacementHistory($userId)
|
||||
{
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Da\User\Service\SessionHistory;
|
||||
|
||||
|
||||
class TerminateSessionsService implements TerminateSessionsServiceInterface
|
||||
{
|
||||
protected $sessionIds;
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Da\User\Service\SessionHistory;
|
||||
|
||||
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
|
||||
interface TerminateSessionsServiceInterface extends ServiceInterface
|
||||
|
||||
@ -11,15 +11,14 @@
|
||||
|
||||
namespace Da\User\Service\SessionHistory;
|
||||
|
||||
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
use Da\User\Event\SessionEvent;
|
||||
use Da\User\Model\SessionHistory;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use yii\web\Session;
|
||||
use Yii;
|
||||
use yii\web\Session;
|
||||
|
||||
class TerminateUserSessionsService implements ServiceInterface
|
||||
{
|
||||
@ -68,7 +67,7 @@ class TerminateUserSessionsService implements ServiceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param int $userId
|
||||
* @return User
|
||||
*/
|
||||
protected function getUser($userId)
|
||||
|
||||
@ -13,9 +13,8 @@ namespace Da\User\Service;
|
||||
|
||||
use Da\TwoFA\Manager;
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Factory\MailFactory;
|
||||
|
||||
use Da\User\Model\User;
|
||||
use Yii;
|
||||
|
||||
class TwoFactorEmailCodeGeneratorService implements ServiceInterface
|
||||
@ -51,14 +50,14 @@ class TwoFactorEmailCodeGeneratorService implements ServiceInterface
|
||||
// send email
|
||||
$mailService = MailFactory::makeTwoFactorCodeMailerService($user, $code);
|
||||
// check the sending emailYii::t(
|
||||
if(!$mailService->run()){
|
||||
Yii::$app->session->addFlash('error', Yii::t('usuario','The email sending failed, please check your configuration.'));
|
||||
if (!$mailService->run()) {
|
||||
Yii::$app->session->addFlash('error', Yii::t('usuario', 'The email sending failed, please check your configuration.'));
|
||||
return false;
|
||||
}else{
|
||||
// put key in session
|
||||
Yii::$app->session->set("email_code_time", date('Y-m-d H:i:s'));
|
||||
Yii::$app->session->set("email_code", $code);
|
||||
}
|
||||
// put key in session
|
||||
Yii::$app->session->set("email_code_time", date('Y-m-d H:i:s'));
|
||||
Yii::$app->session->set("email_code", $code);
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,13 +13,12 @@ namespace Da\User\Service;
|
||||
|
||||
use Da\TwoFA\Manager;
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Factory\MailFactory;
|
||||
use yii\di\Instance;
|
||||
use Da\User\Model\User;
|
||||
use yetopen\smssender\SmsSenderInterface;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
use Yii;
|
||||
use yii\di\Instance;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class TwoFactorSmsCodeGeneratorService implements ServiceInterface
|
||||
{
|
||||
@ -49,7 +48,7 @@ class TwoFactorSmsCodeGeneratorService implements ServiceInterface
|
||||
$this->type = 'sms';
|
||||
$module = Yii::$app->getModule('user');
|
||||
$validators = $module->twoFactorAuthenticationValidators;
|
||||
$smsSender = ArrayHelper::getValue($validators,'sms'.'.smsSender');
|
||||
$smsSender = ArrayHelper::getValue($validators, 'sms'.'.smsSender');
|
||||
$this->smsSender = Instance::ensure($smsSender, SmsSenderInterface::class);
|
||||
}
|
||||
|
||||
@ -63,19 +62,19 @@ class TwoFactorSmsCodeGeneratorService implements ServiceInterface
|
||||
$code = str_pad($code, 6, 0, STR_PAD_LEFT);
|
||||
// get the mobile phone of the user
|
||||
$user = $this->user;
|
||||
$mobilePhone=$user->getAuthTfMobilePhone();
|
||||
$mobilePhone = $user->getAuthTfMobilePhone();
|
||||
|
||||
if( null===$mobilePhone || $mobilePhone=='' ){
|
||||
if (null === $mobilePhone || $mobilePhone == '') {
|
||||
return false;
|
||||
}
|
||||
// send sms
|
||||
$success = $this->smsSender->send($mobilePhone, $code);
|
||||
if($success){
|
||||
if ($success) {
|
||||
// put key in session
|
||||
Yii::$app->session->set("sms_code_time", date('Y-m-d H:i:s'));
|
||||
Yii::$app->session->set("sms_code_time", date('Y-m-d H:i:s'));
|
||||
Yii::$app->session->set("sms_code", $code);
|
||||
}else{
|
||||
Yii::$app->session->addFlash('error', Yii::t('usuario','The sms sending failed, please check your configuration.'));
|
||||
} else {
|
||||
Yii::$app->session->addFlash('error', Yii::t('usuario', 'The sms sending failed, please check your configuration.'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,11 +13,10 @@ 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
|
||||
{
|
||||
@ -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);
|
||||
$codeDurationTime = ArrayHelper::getValue($validators, $this->type.'.codeDurationTime', 300);
|
||||
|
||||
if($interval > $codeDurationTime ){
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,11 +13,10 @@ 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
|
||||
{
|
||||
@ -51,20 +50,21 @@ class TwoFactorTextMessageValidator extends TwoFactorCodeValidator
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if(is_null($this->code) || $this->code == '' )
|
||||
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);
|
||||
$codeDurationTime = ArrayHelper::getValue($validators, $this->type.'.codeDurationTime', 300);
|
||||
|
||||
if($interval > $codeDurationTime ){
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ class SessionStatusWidget extends Widget
|
||||
* Returns available auth items to be attached to the user.
|
||||
*
|
||||
* @param int|null type of auth items or null to return all
|
||||
* @param null|mixed $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user