DrQuincy Posted June 20, 2022 Share Posted June 20, 2022 I want to make it so that both user name and email are unique in template users. I've got this which issues a warning, which is better than nothing: wire()->addHookAfter('Pages::saveReady', function(\ProcessWire\HookEvent $event) { $page = $event->arguments(0); // Don't run on newly created pages if ($page !== null && $page->created !== 0) { if ($page->template == 'user') { $pages = wire('pages')->find('template=user'); foreach ($pages as $p) { // Don't compare to current page if ($p->id != $page->id) { if ($p->email == $page->email) { wire('session')->warning('**' . $p->email . '** is already being used by [' . $p->name . '](/processwire/access/users/edit/?id=' . $p->id . ') — it is highly recommended each account has a unique email address', \ProcessWire\Notice::allowMarkdown); } } } } } }); I am also using the EmailNewUser module. The reason I am issuing a warning as opposed to preventing the page being saved is regardless of what I do if you have the Send welcome email checkbox checked, EmailNewUser seems to always send the email out — and always to the duplicate email. I did try overriding the email to a random non-existent one so the email send would go nowhere — but EmailNewUser always emails the duplicate address, which is going to be confusing for the client. Is there any way to adapt the above code to prevent EmailNewUser from running if the email is a duplicate? Or is there a way to make EmailNewUser used an updated random email instead? I'm not sure how it works but however EmailNewUser is set up it seems to always use the old value. I hope that makes sense! Thanks. Link to comment Share on other sites More sharing options...
DrQuincy Posted June 21, 2022 Author Share Posted June 21, 2022 On another thread I've found out how to make the email field unique but EmailNewUser still runs if you use a duplicate email and sends to the old address. Is there any way to prevent this happening? 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