Skip to content

Commit

Permalink
Merge branch '2amigos:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
niciz authored Dec 15, 2023
2 parents 2ca3499 + cb93930 commit ed5ae8f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## dev

- Fix: Two Factor Authentication - Filter - Blocks even when two factor authentication is enabled
- Fix: update Dutch (nl) translations (squio)
- Enh: possibility to limit the depth of the recursion when getting user ids from roles (mp1509)
- Fix: UserSearch avoid fields name conflict if joined with other tables (liviuk2)

## 1.6.1 March 4th, 2023

Expand Down
6 changes: 4 additions & 2 deletions src/User/Filter/TwoFactorAuthenticationEnforceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public function beforeAction($action)
}

$permissions = $module->twoFactorAuthenticationForcedPermissions;
$itemsByUser = array_keys($this->getAuthManager()->getItemsByUser(Yii::$app->user->identity->id));
if (!empty(array_intersect($permissions, $itemsByUser))) {

$user = Yii::$app->user->identity;
$itemsByUser = array_keys($this->getAuthManager()->getItemsByUser($user->id));
if (!empty(array_intersect($permissions, $itemsByUser)) && !$user->auth_tf_enabled) {
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();
}
Expand Down
18 changes: 12 additions & 6 deletions src/User/Search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

namespace Da\User\Search;

use Da\User\Model\User;
use Da\User\Query\UserQuery;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\data\ActiveDataProvider;

class UserSearch extends Model
{
use ContainerAwareTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -106,21 +110,23 @@ public function search($params)
return $dataProvider;
}

$userClass = $this->getClassMap()->get(User::class);

if ($this->created_at !== null) {
$date = strtotime($this->created_at);
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
$query->andFilterWhere(['between', $userClass::tableName().'.created_at', $date, $date + 3600 * 24]);
}

if ($this->last_login_at !== null) {
$date = strtotime($this->last_login_at);
$query->andFilterWhere(['between', 'last_login_at', $date, $date + 3600 * 24]);
$query->andFilterWhere(['between', $userClass::tableName().'.last_login_at', $date, $date + 3600 * 24]);
}

$query
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['registration_ip' => $this->registration_ip])
->andFilterWhere(['last_login_ip' => $this->last_login_ip]);
->andFilterWhere(['like', $userClass::tableName().'.username', $this->username])
->andFilterWhere(['like', $userClass::tableName().'.email', $this->email])
->andFilterWhere([$userClass::tableName().'.registration_ip' => $this->registration_ip])
->andFilterWhere([$userClass::tableName().'.last_login_ip' => $this->last_login_ip]);

return $dataProvider;
}
Expand Down
7 changes: 6 additions & 1 deletion src/User/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ public function getType()
*/
public function run()
{
return $this->mailer
$result = $this->mailer
->compose(['html' => $this->view, 'text' => "text/{$this->view}"], $this->params)
->setFrom($this->from)
->setTo($this->to)
->setSubject($this->subject)
->send();

if (!$result) {
Yii::error("Email sending failed to '{$this->to}'.", 'mailer');
}
return $result;
}
}
2 changes: 1 addition & 1 deletion src/User/Validator/TwoFactorEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ public function getUnsuccessLoginMessage($codeDurationTime)
*/
public function generateCode()
{
return $this->make(TwoFactorEmailCodeGeneratorService::class, $this->user)->run();
return $this->make(TwoFactorEmailCodeGeneratorService::class, [$this->user])->run();
}
}

0 comments on commit ed5ae8f

Please sign in to comment.