The Frayed Ends of Sanity

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

I'm having some trouble on trying to change/remove a label before a checkbox, since the text is already displayed on the side it's useless to have again the label on top with the same text...any idea on how to hook the label render? thanks

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Hi and sorry guys for the late answer, I will take a look tomorrow and will try to answer you both!

Share this post


Link to post
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.