CakeDC / users

Users Plugin for CakePHP
https://www.cakedc.com
Other
520 stars 296 forks source link

Feature request: Make `last_login` optional through configuration #1014

Closed acjbizar closed 6 months ago

acjbizar commented 1 year ago

The last_login thing is nice, but I now have a situation where I have to connect to an external database that I can’t do migrations on. I got everything working, except the last_login upgrade it tries to do when logging in. In an attempt to overrule the login rules, I went down a rabbit hole of custom controller, trait, component, component loader … duplicating more and more code, making it much harder to maintain.

I think it would be better if we could just flag a last_login option in users.php like 'last_login' => false. Even better, would probably to move it to its own class that then can be overridden explicitly, in a smililar way we handle other things like password hashers. The database I’m connecting to does have another field that takes a timestamp and does basically the same thing. (Though I could use a custom behavior to do that if the default last_login could just be disabled.)

rochamarcelo commented 1 year ago

@acjbizar Have you tried to overwrite the method LoginComponent::updateLastLogin witha a custom component? https://github.com/CakeDC/users/blob/33af43401e2fab89b37175d6cdc3c3720ac6d14d/src/Controller/Component/LoginComponent.php

'Auth.FormLoginFailure.component' => 'MyLoginB', ( https://github.com/CakeDC/users/blob/33af43401e2fab89b37175d6cdc3c3720ac6d14d/Docs/Documentation/Authentication.md#handling-login-result )

acjbizar commented 1 year ago

@acjbizar Have you tried to overwrite the method LoginComponent::updateLastLogin witha a custom component?

… Oh, wow. That was a lot easier than what I was trying to do. Thanks!

I still think moving this thing to some sort of configuration would be a nice thing to have, but this is definitely workable for my case. Thanks again.

rochamarcelo commented 1 year ago

A config do disable it should not be a problem, feel free to send a pull request, by default the logic would not be disabled.

arodu commented 6 months ago

@rochamarcelo check this cake4: https://github.com/CakeDC/users/pull/1068 cake5: https://github.com/CakeDC/users/pull/1069

rochamarcelo commented 6 months ago

Changes merged

rochamarcelo commented 6 months ago

Thank You.