Conversation
ArchBlood
left a comment
There was a problem hiding this comment.
Overall it now does work, although the following code should be done in a controller not the Events.php;
if ("user/auth/login" === Yii::$app->request->getPathInfo()) {
Yii::$app->getResponse()->redirect(['/user/password-recovery']);
}|
Here's an example AuthController.php<?php
namespace humhub\auth\basic\controllers;
use Yii;
use humhub\modules\user\controllers\AuthController as BaseAuthController;
class AuthController extends BaseAuthController
{
public function actionLogin()
{
// Call the parent action method to retain the base functionality
$result = parent::actionLogin();
// Perform your additional logic here
if ($this->shouldRedirectToRecovery()) {
Yii::$app->getResponse()->redirect(['/user/password-recovery'])->send();
Yii::$app->end();
}
return $result;
}
/**
* Example method to determine if redirection should occur
* Modify this method based on your specific conditions
*/
private function shouldRedirectToRecovery()
{
return ("user/auth/login" === Yii::$app->request->getPathInfo());
// Add more conditions as needed to determine when to redirect
}
}Events.php<?php
namespace humhub\auth\basic;
use Yii;
use humhub\components\Request;
use humhub\modules\user\models\forms\Login;
use humhub\auth\basic\controllers\AuthController;
use humhub\modules\user\services\AuthClientService;
use humhub\modules\user\authclient\AuthClientHelpers;
class Events
{
/**
* @param Event $event
*/
public static function onBeforeRequest($event)
{
if (!Yii::$app->has('request')) {
return;
}
$request = Yii::$app->request;
list($username, $password) = $request->getAuthCredentials();
$identity = Yii::$app->user->getIdentity();
if ($username != null && $password != null && $identity == null) {
$login = new Login;
if ($login->load(['username' => $username, 'password' => $password], '') && $login->validate()) {
if (version_compare(Yii::$app->version, '1.14', '>=')) {
$authClientService = new AuthClientService($login->authClient);
$user = $authClientService->getUser();
if ($user == null) {
$user = $authClientService->createUser($login->authClient);
}
if ($user != null) {
Yii::$app->user->login($user);
}
} else {
$user = AuthClientHelpers::getUserByAuthClient($login->authClient);
if ($user == null) {
$user = AuthClientHelpers::createUser($login->authClient);
}
if ($user != null) {
Yii::$app->user->login($user);
}
}
}
}
$authController = new AuthController('auth', Yii::$app->getModule('user'));
$authController->actionLogin();
}
} |
|
Hi @sebmennetrier , |
Would not be better if you fork the code and apply your own fix ? Thx |
I no longer have a client that uses the module, so maintaining it through a fork doesn't make much sense for me at this time. |
|
@sebmennetrier Can you merge this PR and release a new version please? |
Seems like even I haven't been able to get any answers back from the developer(s) (i.e. #8) about the current status of development on this or any other modules they maintain, and I can't just maintain the project due to a no license clause. |
Try to fix issue #5