Jump to content

LoginRegister customisation


Recommended Posts

Thank you @flydev

do you know why at me show up this error?

1304285856_Schermata2018-05-15alle11_35_10.thumb.png.9780d80d6c0838acb7fac778e26bfb63.png

I see the documentation and I try to rewrite but don't have find a solution. I can not understand if the problem is in the loop like the alert or is in the line 47.

The loop like write well, in the option you take the field options and get all the shipping_countrycode value, I think this is correct, I try to use different format like in the documentation but didn't work. like this:

$field = $fields->get('shipping_countrycode');
$options = $this->type->getOptions($field);

This not give me this error but all the process not work... ?

Link to comment
Share on other sites

8 minutes ago, MarcoPLY said:

do you know why at me show up this error?

yes sorry, I edited my previous post, please re-copy the code. The error is because I use the keyword $this (as I am writing a module) instead of using wire() in the hook if he is called from the ready.php ?

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

I have a new install of ProcessWire 3.0.98 and have installed the module LoginRegister, which seems to be functioning as expected, with the following exception:

The module is configured with [x] Use email address for login rather than user name

After registration is confirmed and the user has an account, and they are logged in, they can edit profile. If the user changes email address on the profile and submits the form, it will change the email address correctly. But the user name is not being updated to the new email - as confirmed by going into Admin > Users and seeing the user with modified email, but original "name". 

The module appears to have a section on profile edit that will update the user name if the email address login is active... 
LoginRegister.module line 924: // update name to be consistent with email

Is there another settings that I have to change to make this functional?
 

orodreth_loginregister.png

Link to comment
Share on other sites

  • 3 weeks later...

Fixed User Name update when changing email:

...
protected function ___processProfileForm(InputfieldForm $form) {
    ...
    if($this->allowFeature('login-email')) {
        // update name to be consistent with email
        $name = $this->emailToName($email); //-- THIS VALIDATES EMAIL-TO-NAME ... BUT DOES NOT CHANGE USER NAME
        $reason = '';
        if(!$this->allowName($name, $reason)) {
            $emailField->error($this->_('Unable to change to new email address') . " ($reason)"); 
            $emailField->val($user->email);
            $email = '';
        }
        else {
            $user->set('name', $name); //-- ADDED THIS ELSE CONDITION TO UPDATE USER NAME
        }
    }
    if(strlen($email)) {
        $user->set('email', $email);
        $this->message(sprintf($message, $emailField->label));
    }
...

 

Link to comment
Share on other sites

  • 1 month later...

Hi. Is it possible customize the registration form for different pages ?

I have to add a specific roles for the user make the registration from a specific page. And also add one more input in this registration form.

I try to add the role following your idea in the other post but this of course doesn't work.

wire()->addHookBefore('LoginRegister::buildLoginForm', function ($event) {

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

	$string = $page->path();
	$field = 'invoice_IVA_VAT';
	
	// hide a field for all forms except the one on the page.
	if ($string !== 'business-landing') {
		$f = $form->get($field);
		$f->collapsed = Inputfield::collapsedHidden;
	}

	// add them new role
    if ($string == 'business-landing') {
			$u = $event->arguments[0];
			$u->roles->add(wire('roles')->get("bs-user"));
			$u->save();
    }

  $event->return = $form;

});

I see you have use addHookBefore LoginRegister::createdUser  in that post.  But if I want choose the page where this it's apply I have to use buildLoginForm, correct? 

How I can add the roles after the registration and a new field?

UPDATE: 

For add a custom roles need to use an hook by this:

  wire()->addHookBefore('LoginRegister::createdUser', function($event) {
      $u = $event->arguments[0]; // get user object
      $u->addRole('bs-user');
      $u->save();
  });

Be sure to render the login form (and not only the registration form).

 

  • Like 1
Link to comment
Share on other sites

hi @Sevarf2

I know maybe it's not exactly what you were looking for, but could put you in a good direction. 
I didn't test yet but look so nice. I have find here

wire()->addHookAfter('LoginRegister::buildProfileForm', function($event) {
    $form = $event->return;
    foreach ($form->children as $field) {
        if ($field instanceof InputfieldEmail || $field instanceof InputfieldPassword) {
            $form->remove($field);
        }
    }
});

Maybe it's enough make a different hook in instead of  $form->remove($field)

If you want to use just for a specific form you can make the hook in that page, instead of in the ready.php

Link to comment
Share on other sites

On 9/20/2018 at 5:21 PM, MarcoPLY said:

hi @Sevarf2

I know maybe it's not exactly what you were looking for, but could put you in a good direction. 
I didn't test yet but look so nice. I have find here


wire()->addHookAfter('LoginRegister::buildProfileForm', function($event) {
    $form = $event->return;
    foreach ($form->children as $field) {
        if ($field instanceof InputfieldEmail || $field instanceof InputfieldPassword) {
            $form->remove($field);
        }
    }
});

Maybe it's enough make a different hook in instead of  $form->remove($field)

If you want to use just for a specific form you can make the hook in that page, instead of in the ready.php

I tried starting from something like this with no luck

Link to comment
Share on other sites

Hi @Sevarf2

Probably it's better this one:

$wire->addHookAfter('LoginRegister::buildLoginForm', function($event) {

    $form = $event->return;
    $form->description = false; // Remove the description
    
    foreach ($form->children as $field) { // loop form fields
        if($field instanceof InputfieldSubmit) { // if we reach the submit button then
            $field->value = 'My Submit'; // change the value
        }
    }

    $event->return = $form;
});

Probably me too later this week I will try to use, I think this could works. Take a look in the 1° page of this post there are also other part of code that maybe can help you.

  • Like 1
Link to comment
Share on other sites

Hi @flydev 

Is it possible have access to all variable in sendConfirmationEmail ? 

I'd like to include the person's name and password in the e-mail notification, but the moment I'm only able to access the e-mail. 

Also for the buildConfirmationForm I can't add eg. the e-mail inside the text. I try use this but doesn't work.

sprintf($this->_('Thank you, a confirmation code has been emailed to you at %s.'), $email)

Perhaps it's the same problem that I can't access to all variables from the registration form.

Link to comment
Share on other sites

On 10/5/2017 at 3:11 AM, flydev said:

then in ready.php :


wire()->addHookAfter('LoginRegister::processProfileForm', function($e) {
    $form = $e->arguments[0]; // get the form
    foreach ($form->children as $field) {
        if($field instanceof InputfieldImage) {
            foreach ($field->getAttribute('value') as $value) {
                wire('user')->images->add($value);
            }
            wire('user')->save();
        }
    }
});

 

To show the image on the frontend, you can hook renderProfileForm().

 

FlyDev, the LoginRegister module says that is does not support image fields, but it can be modified to do so, as you suggest. 
The snippet shown for the hook is to SAVE images that are input to the profile form. Is there another module or code samples that show more robust image field manipulations (choose file, generate and display thumbnail, save image, show existing image, delete image, overwrite image on save).
The Image Field seems to have a lot of that functionality, but to use the Image Field on the LoginRegister, it looks like it requires some JS and CSS that exist in the admin section?

Link to comment
Share on other sites

  • 6 months later...
  • 4 weeks later...

Hi everyone,

I'm trying to have a page reference field on the registration and profile edit page.
I know that only 'standard' fields are supported but I'm not sure whether the page reference field is 'standard' or not.

Currently it is not rendered correctly, I don't see the select dropdown to select a page (see image)

Has anyone done this before? Or can point me into the right direction?
I'm trying to add the InputfieldPage manually but I wasn't able to find API for a page reference field.

Thanks,
Joeck

team_render.png

Link to comment
Share on other sites

  • 1 year later...

I'm trying to give the newly registered user (via LoginRegister) permissions to edit some page in the admin. So I added permissions accordingly to the role login-register, but now the role is not assigned to the user when they register because in the settings it says 

Roles with page-edit permission are not shown. 

so that's kind of paradoxical. How to solve? only with hooks?

EDIT:

never mind, this works perfectly:

On 9/19/2018 at 11:35 AM, Marco Ro said:

UPDATE: 

For add a custom roles need to use an hook by this:


  wire()->addHookBefore('LoginRegister::createdUser', function($event) {
      $u = $event->arguments[0]; // get user object
      $u->addRole('bs-user');
      $u->save();
  });

 

 

Link to comment
Share on other sites

  • 2 years later...

Hello dear processwirers, I hope you are doing well.

I'm a bit stuck implementing this module.
Since the "Edit Profile"-form renders when the GET-params are "profile=1"
But that form also submits to the same page with the same GET-params "profile=1"
I don't see how I can redirect the page upon form submission without ruling out the case that the user is just on the edit profile page.
That also means that when the form was submitted and I refresh the page, the browser asks me if I want to resubmit.

In more technical terms: how can I edit the form action URL? 

Thanks for help!

Link to comment
Share on other sites

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