2amigos / yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
https://github.com/2amigos/yii2-usuario
Other
294 stars 142 forks source link

Two Factor - Email - User model doesnt get init properly #513

Closed deadmantfa closed 9 months ago

deadmantfa commented 1 year ago

What steps will reproduce the problem?

Enable Two-Factor Email. Logout. Try Loging in - Error Message

What is the expected result?

Email to be sent with the code

What do you get instead?

Error message - Unable to send email

edegaudenzi commented 1 year ago

Context Had same problem with 2amigos/yii2-usuario version 1.6.1 and a custom User model that extends the yii2-usuario one.

Problem Found out the problem is syntactical and it's actually in:

vendor/2amigos/yii2-usuario/src/User/Validator/TwoFactorEmailValidator.php line 114

at this line the trait method make() is used, passing the class we want to make as the first argument, and the $this->user as a second argument; and the problem is here! The trait method make() uses the yii\di\Container::get() method, which accepts an array as a second parameter. It does not throw an exception probably because the User object is silently cast in array, so the argument is still formally valid.

Solution Coming back to TwoFactorEmailValidator.php line 114, if instead of return $this->make(TwoFactorEmailCodeGeneratorService::class, $this->user)->run(); you use return $this->make(TwoFactorEmailCodeGeneratorService::class, [$this->user])->run();

then everything starts to work.

Hope to have been useful, I will submit a pull request if someone else doesn't beat me on time.

Live long and prosper \\//_

deadmantfa commented 1 year ago

There is a PR already there #519 with the fixes its not merged yet

edegaudenzi commented 1 year ago

Thank you deadmantfa, didn't see it before doing mine. For readers:

maxxer commented 9 months ago

PR merged, should fix this issue