Jump to content
strandoo

LoginRegister - Display Registration Form even when already logged it?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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);
});

 

  • Like 3

Share this post


Link to post
Share on other sites

...you'd have to add

$loginRegister = modules()->get('LoginRegister');
$content = $loginRegister->execute();
echo $content;

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

@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?

Share this post


Link to post
Share on other sites

@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. 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...