suntrop Posted November 25, 2018 Share Posted November 25, 2018 Hi all I am using the login form $modules->get('LoginRegister')->execute() and have in /site/init.php $session->addHookAfter('loginSuccess', function($event) { // Update user's last login time $user = $event->arguments(0); $user->details->last_login = time(); $user->of(false); $user->save('details'); if(wire('page')->template == 'admin') return; wire('session')->redirect('/dashboard/'); exit(); }); But somehow, the last_login subfield doesn't update, if I use the Login/Register module login. However, it updates using "PW's default login". Any idea why? Seems to be the only reliable method to check if the user logged in successfully. The other one, afterLogin, runs for failed logins as well, as I can see. Link to comment Share on other sites More sharing options...
breezer Posted November 26, 2018 Share Posted November 26, 2018 I'm new to PW and just learning hooks myself but this is how I got the loginSuccess hook to work in site/_init.php. Note this only sets a session variable but it is proof that the hook is there and working. wire()->addHook('LoginRegister::loginSuccess', function($event) { // outside a class $session = wire('session'); $session->set('Login_Register_hook', 'success'); }); output: [Login_Register_hook] => success wire()->addHook('LoginRegister::loginFail', function($event) { $session = wire('session'); $session->set('Login_Register_hook', 'failure'); }); output: [Login_Register_hook] => failure 1 Link to comment Share on other sites More sharing options...
suntrop Posted November 26, 2018 Author Share Posted November 26, 2018 Well, you are right. Thanks for pointing me the right direction. Had the $user->of(false) on the wrong line and just needed to move it before setting the field value. Don't know, why this worked on the default login. Link to comment Share on other sites More sharing options...
teppo Posted November 30, 2018 Share Posted November 30, 2018 @ryan, any chance you could set up a support forum thread for LoginRegister? Currently it doesn't have one, and these requests pile up in the Modules/Plugins area. Just trying to keep things nice and tidy here ? 3 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now