fix hardcoded urls in SocialNetworkAuthenticateService

This commit is contained in:
Elias Luhr
2024-03-07 18:52:38 +01:00
parent 5d8dadfaae
commit e6d696562b

View File

@ -19,12 +19,15 @@ use Da\User\Model\SocialNetworkAccount;
use Da\User\Model\User; use Da\User\Model\User;
use Da\User\Query\SocialNetworkAccountQuery; use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Query\UserQuery; use Da\User\Query\UserQuery;
use Da\User\Traits\ModuleAwareTrait;
use Yii; use Yii;
use yii\authclient\AuthAction; use yii\authclient\AuthAction;
use yii\helpers\Url; use yii\helpers\Url;
class SocialNetworkAuthenticateService implements ServiceInterface class SocialNetworkAuthenticateService implements ServiceInterface
{ {
use ModuleAwareTrait;
protected $controller; protected $controller;
protected $authAction; protected $authAction;
protected $client; protected $client;
@ -50,7 +53,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface
$account = $this->socialNetworkAccountQuery->whereClient($this->client)->one(); $account = $this->socialNetworkAccountQuery->whereClient($this->client)->one();
if (!$this->controller->module->enableSocialNetworkRegistration && ($account === null || $account->user === null)) { if (!$this->controller->module->enableSocialNetworkRegistration && ($account === null || $account->user === null)) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Registration on this website is disabled')); Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Registration on this website is disabled'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login'])); $this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));
return false; return false;
} }
@ -58,7 +61,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface
$account = $this->createAccount(); $account = $this->createAccount();
if (!$account) { if (!$account) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Unable to create an account.')); Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Unable to create an account.'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login'])); $this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));
return false; return false;
} }
@ -72,7 +75,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface
if ($account->user instanceof User) { if ($account->user instanceof User) {
if ($account->user->getIsBlocked()) { if ($account->user->getIsBlocked()) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Your account has been blocked.')); Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Your account has been blocked.'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login'])); $this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));
} else { } else {
$result = Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan); $result = Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan);
if ($result) { if ($result) {