Jump to content

LoginRegister - How to make user Name field editable?


JayGee
 Share

Recommended Posts

Hi,

I'm just setting up @ryan's LoginRegister module for a project. Just wondering is there a way to make the PW user 'Name' field included in the registration/profile output? It's available to me in the drop-down and I've made the field user editable too.

Link to comment
Share on other sites

3 minutes ago, wbmnfktr said:

You can go to the settings and define either username or e-mail address for registration.

2018-05-04 12_49_15-Module • ProcessWire • processwire.tld.png

I already tried changing that setting - but it doesn't seem to make any difference to whether or not the name field shows?

Screen Shot 2018-05-04 at 11.56.25.png

Link to comment
Share on other sites

1 minute ago, wbmnfktr said:

Glad I'm using the e-mail as login and not the username. ?

UX Planet - Requiring a user name to login: https://uxplanet.org/7-inexcusable-yet-common-ux-gaffes-that-make-you-look-like-a-total-amateur-cb504a74b917#3b00

I'm going to use their email for login, but planning to use their username for display around the site so thought it would be nicer for them to choose their own. If solving this becomes too much of a PITA I'll probably just settle for displaying first name and first letter of their last name instead. E.g. Joe Bloggs becomes JoeB.

Link to comment
Share on other sites

Hi @ryan Thanks alot for the great plugin. I've implemented it and customised it well until this point :)

Now I'm stuck trying to add a user-image to the registration form. The first error is triggered by LoginRegister.module line 438:

$form->processInput($this->wire('input')->post);

The problem is, that when it's submited, the user does not exist yet, so there is no upload-path at FieldtypeFile.module > hookProcessInput > line 634

Fatal error: Uncaught Error: Call to a member function path() on null in /home/ubuntu/workspace/www/wire/modules/Fieldtype/FieldtypeFile.module:634 Stack trace: #0 /home/ubuntu/workspace/www/wire/core/WireHooks.php(822): ProcessWire\FieldtypeFile->hookProcessInput(Object(ProcessWire\HookEvent)) #1 /home/ubuntu/workspace/www/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldImage), 'processInput', Array) #2 /home/ubuntu/workspace/www/wire/core/InputfieldWrapper.php(809): ProcessWire\Wire->__call('processInput', Array) #3 /home/ubuntu/workspace/www/wire/modules/Inputfield/InputfieldForm.module(146): ProcessWire\InputfieldWrapper->___processInput(Object(ProcessWire\WireInputData)) #4 /home/ubuntu/workspace/www/wire/core/Wire.php(383): ProcessWire\InputfieldForm->___processInput(Object(ProcessWire\WireInputData)) #5 /home/ubuntu/workspace/www/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___processInput', Array) #6 /home/ubuntu/workspace/www/wire/core/Wire.php(442): ProcessWi in /home/ubuntu/workspace/www/wire/modules/Fieldtype/FieldtypeFile.module on line 634
Error: Uncaught Error: Call to a member function path() on null in /home/ubuntu/workspace/www/wire/modules/Fieldtype/FieldtypeFile.module:634
Stack trace:
#0 /home/ubuntu/workspace/www/wire/core/WireHooks.php(822): ProcessWire\FieldtypeFile->hookProcessInput(Object(ProcessWire\HookEvent))
#1 /home/ubuntu/workspace/www/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldImage), 'processInput', Array)
#2 /home/ubuntu/workspace/www/wire/core/InputfieldWrapper.php(809): ProcessWire\Wire->__call('processInput', Array)
#3 /home/ubuntu/workspace/www/wire/modules/Inputfield/InputfieldForm.module(146): ProcessWire\InputfieldWrapper->___processInput(Object(ProcessWire\WireInputData))
#4 /home/ubuntu/workspace/www/wire/core/Wire.php(383): ProcessWire\InputfieldForm->___processInput(Object(ProcessWire\WireInputData))
#5 /home/ubuntu/workspace/www/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___processInput', Array)
#6 /home/ubuntu/workspace/www/wire/core/Wire.php(442): ProcessWi (line 634 of /home/ubuntu/workspace/www/wire/modules/Fieldtype/FieldtypeFile.module) 

This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged. Administrator has been notified.

$page as well as $pagefiles does not exist:

	/**
	 * Hook into the InputfieldFile's processInput method to set the upload destination path.
	 *
	 * This hook originates with the setupHooks method above.
	 *
	 * @param HookEvent $event
	 */
	public function hookProcessInput($event)
	{
		/** @var InputfieldFile $inputfield */
		$inputfield = $event->object;
		/** @var Page $page */
		$page = $event->options['page']; // < Page does not exist > NullPage
		/** @var Field $field */
		$field = $event->options['field'];
		$pagefiles = $page->get($field->name); // so also field does also not exist…
     // there should be a check if $pagefiles exists, because:
		$inputfield->destinationPath = $pagefiles->path(); // …therefore $pagefiles is NULL and ->path(); throws an error.
	}

I tried to provide a path using a hook:

	wire()->addHookBefore('InputfieldImage::processInput', $this, 'hookProcessInput', ['priority' => 4]);


	/**
	 * Hook into the InputfieldFile's processInput method to set the upload destination path.
	 *
	 * This hook originates with the setupHooks method above.
	 *
	 * @param HookEvent $event
	 */
	public function hookProcessInput($event)
	{

		/** @var InputfieldFile $inputfield */
		$inputfield = $event->object;
		$inputfield->destinationPath = wire('page')->filesManager->getTempPath();
	}

But this throws another error:

Error: Exception: Invalid image (in /home/ubuntu/workspace/www/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 425)

#0 /home/ubuntu/workspace/www/wire/core/Wire.php(383): ProcessWire\InputfieldFile->___processInputAddFile('leo.png')
#1 /home/ubuntu/workspace/www/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___processInput...', Array)
#2 /home/ubuntu/workspace/www/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldImage), 'processInputAdd...', Array)
#3 /home/ubuntu/workspace/www/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(602): ProcessWire\Wire->__call('processInputAdd...', Array)
#4 /home/ubuntu/workspace/www/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module(1304): ProcessWire\InputfieldFile->___processInput(Object(ProcessWire\WireInputData))
#5 /home/ubuntu/workspace/www/wire/core/Wire.php(383): ProcessWire\InputfieldImage->___processInput(Object(ProcessWire\WireInputData))
#6 /home/ubuntu/workspace/www/wire/core/Wi

This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged. Administrator has been notified.

What do you suggest? Do you see a path to success in adding profile pictures to the module?

I could make it work with an existing users profile by way of hooks…

Link to comment
Share on other sites

  • 9 months later...

Hi @Lance O., yes. This is how I did it;

I used the LoginRegister module of Ryan on a Page with a "PageUserProfile" template:

// Code on the template PageUserProfile
$input->get->profile = 1;
$loginRegister = $modules->get('LoginRegister');

$user->of(false);
echo $loginRegister->execute();

Then I use my own module and inside the init() function, I add two hooks:

<?php

/**
 * © ICF Church – <web@icf.ch>
 */

namespace ProcessWire;


class TemplateUser extends WireData implements Module
{
	protected $template = 'user';

	public function init()
	{
		// handle profile images
		$this->addHookBefore('Page(template=PageUserProfile)::render', $this, 'profileImageUpload', ['priority' => 6]);
		$this->addHookAfter('Page(template=PageUserProfile)::render', $this, 'profileImageRemove', ['priority' => 99]);
	}

	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them.
	 *
	 * @return array
	 */
	public static function getModuleInfo()
	{
		return [
			'title' => 'Template User Controller',
			'version' => '0.0.1',
			'summary' => 'Helps with profile image',
			'href' => '',
			'singular' => true,
			'autoload' => true,
			'author' => 'Noël Bossart',
			'icon' => 'unlock',
		];
	}
  
	/**
	 * Hock to add profile image to user object.
	 *
	 * @param HookEvent $event
	 */
	public function profileImageUpload(HookEvent $event)
	{      
		$user = wire('user');
		$input = wire('input');

		if ($input->post->profile_submit) {
			$upload_path = $user->filesManager->getTempPath();

          	// name of the inputfield from the LoginRegister Module:
			$f = new WireUpload('profile_image');
			$f->setMaxFiles(1);
			//$f->setMaxFileSize(1 * 1024 * 1024);
			$f->setOverwrite(true);
			$f->setOverwriteFilename('userimage');
			$f->setDestinationPath($upload_path);
			$f->setValidExtensions(['jpg', 'jpeg', 'png', 'gif']);

			// remove image…
			if (strpos(implode(array_keys($_POST)), 'delete_profile_image_') !== false) {
				$user->of(false);
				$user->image->removeAll();
				$user->save();
			}

			$files = $f->execute();

			if ($f->getErrors()) {
				foreach ($files as $filename) {
					@unlink($upload_path.$filename);
				}
				foreach ($f->getErrors() as $e) {
					echo $e;
				}
			} elseif (is_array($files) && count($files)) {
				$user->of(false);
				$user->image->removeAll(); // wirearray  (line added by @horst: explanation is three posts beneath)

				foreach ($files as $file) {
					$user->image->add($upload_path.$file);
				}

				$user->save();

				foreach ($files as $file) {
					@unlink($upload_path.$file);
				}
			}
		}
	}

	/**
	 * Hock to remove profile image from user
	 *
	 * @param HookEvent $event
	 */
	public function profileImageRemove(HookEvent $event)
	{

		// remove image…
		if (strpos(implode(array_keys($_POST)), 'delete_profile_image_') !== false) {
			$this->user->of(false);
			$this->user->image->removeAll();
		}
	}
}

 

  • Like 2
  • Thanks 1
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...