Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoginForm identity override is not possible #764

Open
rochdi80tn opened this issue Sep 16, 2024 · 2 comments
Open

LoginForm identity override is not possible #764

rochdi80tn opened this issue Sep 16, 2024 · 2 comments

Comments

@rochdi80tn
Copy link
Contributor

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.
@nadar
Copy link
Contributor

nadar commented Sep 16, 2024

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.

@rochdi80tn
Copy link
Contributor Author

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',
         ],
     ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants