LoginForm identity override is not possible
What steps will reproduce the problem?
I needed to override the identity class that the LoginForm::validatePassword() is using ($user)
My point is I wanted to change User::ValidatePassword() to add an LDAP based password check
What is the expected result?
I expected when I add a dependency injection to change '\luya\admin\models\User' to my customer 'app\components\User' which extends the luya User and alter the password validation
What do you get instead? (A Screenshot can help us a lot!)
Always the luya code User model is loaded because the LoginForm::getUser() is returning an object based on
$this->_user = User::findByEmail($this->email);
I prose to update the getUser() to this instead :
/**
* @return boolean|User
*/
public function getUser()
{
if (!$this->_user) {
$class = Yii::$app->adminuser->identityClass;
$this->_user = $class::findByEmail($this->email);
// $this->_user = User::findByEmail($this->email); /* this is the current way of returning the user object */
}
return $this->_user;
}
this way, If I define a customer admin user class where I update the identity class to my own, it will work.
LUYA Check ouput (run this script and post the result: luyacheck.php)
Additional infos
| Q | A |
|---|---|
| LUYA Version | |
| PHP Version | |
| Platform | Apache/XAMPP/MAMPP/etc. |
| Operating system | Windows/Linux Server/OSX/etc. |
But you could override the adminuser component, not?
this is what the adminuser component looks like:
'adminuser' => [
'class' => AdminUser::class,
'defaultLanguage' => $this->interfaceLanguage,
]
if override of the adminuser component would be an acceptable solution, i would make you a working example.
HI Nadar,
I did indeed overrided the adminuser class inorder to change the $identityClass
namespace app\components;
use luya\admin\components\AdminUser as LuyaAdminUser;
/**
* Description of custom AdminUser
*/
class AdminUser extends LuyaAdminUser
{
public $identityClass = 'app\components\User';
and in my app\components\User class extends the luya User model class to override validatePassword()
namespace app\components;
class User extends \luya\admin\models\User
{
public function validatePassword($password)
{
// return Yii::$app->security->validatePassword($password . $this->password_salt, $this->password);
return someOtherLogicPasswordValidation($this);
}
by doing so I was expecting the luya\admin\models\LoginForm::validatePassword() will invoke my new user validatePaswword() function.
if (!$user || !$user->validatePassword($this->password)) {
BTY, tried adding this in the config file but the default User model class is being still used...
'container' => [
'definitions' => [
'\luya\admin\models\User' => 'app\components\User',
],
],