Jump to content

Recommended Posts

Posted (edited)

I have a default front-end user field call approved that is a true|false switch. I want to redirect them to a URL is not yet manually approved. I have this hook in $config->prependTemplateFile file.

wire()->addHookBefore('Users::login', function($event) {

    $user = $event->arguments[0];

	$user->of(true);

    if($user->approved === false) {

		// Prevent login
        $event->return = false; 

		wire('session')->redirect('/account/?approved=0');

    }
	
});

But it does not fire. Do I have the hook wrong or is it in the wrong place? The file itself is definitely being included and if I replace the contents of the hook to a simple exit statement, still nothing happens.

EDIT: I am using LoginRegisterPro, are the hooks different?

Edited by DrQuincy
Posted

This might be helpful:

On 12/27/2024 at 5:47 PM, bernhard said:

Ever wondered when certain hooks get executed? Which hooks got fired along the request? Or need to debug why your hook does not fire as expected?

 

  • Like 1
Posted (edited)

That's great, thanks, I'm definitely going to try that. 🙂

I do want to know why the User hooks aren't firing but in case anyone is using LRP and wondering the same, I have made what I need to do work with the following hooks:

  1. LoginRegisterPro::createdUser: use this to send an admin email to let the site owner know that a new user has registered
  2. LoginRegisterProLogin::success: used to set approved=0 on $user

More info here: https://processwire.com/store/login-register-pro/docs/#hooks

Edited by DrQuincy
Posted

@bernhard Thanks for your massively helpful debug code. I can see now that the Users::* hooks apply to managing users in the back-end so it was never going to work with LRP — the LRP-specific ones are what I needed.

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...