strandoo Posted September 5, 2019 Posted September 5, 2019 Hi all. I'm using the LoginRegister module with a Business-to-Business site. Currently, it appears that you can only call up the Registration form if you are not logged in. I don't want just anyone signing up for an account but would like the sales reps to sign up clients for them. As such, I want to password-protect the Registration form so only certain roles can access it. "Why not just log in to the back-end and create a new user?" you say. I'd like the signup form in the front end because a) this will be the only function the sales reps will use and b) they will often sit with the customer and fill-out the form together. I'd like the interface to match the front end of the site. Can I enable the Reg form through a hook? Any pointers would be greatly appreciated.
Jo J Posted September 5, 2019 Posted September 5, 2019 Yes you can. I have something similar for a blogging site. Copy/edit/improve here what makes sense to your case... wire()->addHookBefore('LoginRegister::renderList', function($event) { $links = array(); $defaults = $event->arguments(0); if(user()->isLoggedin()) { if (user()->hasRole('member')) { $links['member-list'] = "<a href='" . $this->wire('pages')->get('/directory/')->url . "'>" . $this->_('Member Directory') . "</a>"; } if (user()->hasRole('author')) { $links['blog-admin'] = "<a href='" . $this->wire('pages')->get('/utilities/blog-admin/')->url . "'>" . $this->_('Blog Admin') . "</a>"; } if (user()->hasRole('admin')) { $links['back-admin'] = "<a href='" . $this->wire('pages')->get('template=admin')->url . "'>" . $this->_('Page Admin') . "</a>"; } } else { if($event->object->allowFeature('register')) { $defaults['register'] = "<p>Don't have an account yet? Members can <a href='./?register=1' class='inline'>" . $this->_("register for an account") . "</a></p>"; } } $links = array_merge($links, $defaults); $event->arguments('items', $links); }); 3
Jo J Posted September 5, 2019 Posted September 5, 2019 ...you'd have to add $loginRegister = modules()->get('LoginRegister'); $content = $loginRegister->execute(); echo $content;
strandoo Posted September 6, 2019 Author Posted September 6, 2019 Thanks Jo Justo. I don't think this solves my problem though. I need to enable the Registration form routine when the $user->isLoggedin(). You've given me some ideas though, so now I've just got to get my head around this hooking business!
dragan Posted September 6, 2019 Posted September 6, 2019 @strandoo Why don't you create one dedicated page + template for this special use-case? A page that can only be accessed by the sales reps, and then instead of using the LR module you build your own form and with a few lines of code create your new users via API? Of course, this has the downside that those new users won't be getting automatically generated confirmation emails. But maybe you don't need that feature in your case?
strandoo Posted September 6, 2019 Author Posted September 6, 2019 @dragan You’re right; given my limited skills that would be easier. I’ve done something like that for a site without the LoginRegister module, but I guess I just wanted to see if I could keep it all in the same package, and learn more about hooks. But whatever gets the job done. Thanks.
Jo J Posted September 6, 2019 Posted September 6, 2019 I also see your point in wanting to put it all in the same flow. It might take more time, but I would explore the module in depth coz after quick inspection the necessary methods for registration are hookable.
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