Jump to content
adrian

Email New User

Recommended Posts

@adrian Sending copies to a list of users would certainly come in very handy! For debugging user registration scripts, I'd usually have to switch Bcc recipients regularly.

As for re-branding the Bcc option as "notify other users": sounds good, too. I'm fine with the way it works now and would see the ability to send multiple copies as a priority, but I certainly see your point in simplifying it.

  • Like 1

Share this post


Link to post
Share on other sites
20 hours ago, d'Hinnisdaël said:

@adrian Sending copies to a list of users would certainly come in very handy! For debugging user registration scripts, I'd usually have to switch Bcc recipients regularly.

As for re-branding the Bcc option as "notify other users": sounds good, too. I'm fine with the way it works now and would see the ability to send multiple copies as a priority, but I certainly see your point in simplifying it.

Ok, It now supports a comma-separated list of email addresses and it has been rebranded as "Notify Other Users" and it now uses "To" for sending to these addresses as well.

Please let me know if you see any problems.

  • Like 1

Share this post


Link to post
Share on other sites

@adrian This is great, thanks! I'll take it for a test drive next time I get a chance to upgrade modules on that particular site and report back.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian thanks for this great module.

I want to always show the "Send welcome message" field/checkbox for new users, that I create in the admin.
But this checkbox never shows. I filled out the email-address but it still does not show up.
I unchecked the option "Automatic Email Send" in the modules settings, because I want to choose if a user should get a welcome email or not.

Could this be because of the core version of PW that I am using? I am using 3.0.71 right now.

I turned on ProcessWire debug now, and EmailNewUser triggers an error:

Trying to get property of non-object in K:\xampp\htdocs\myproject\src\site\assets\cache\FileCompiler\site\modules\EmailNewUser\EmailNewUser.module on line 54

That line reads 

if ($this->wire('page')->process == "ProcessUser") $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addEmailFields');

I think the problem is 

$this->wire('page')->process == "ProcessUser"

but I am not sure. Any suggestions?

emailnewuser.png

  • Like 1

Share this post


Link to post
Share on other sites

Hi @jmartsch - glad you are finding it useful. 

I can't seem to reproduce any of the problems you are having

What version of the module are you running? Line #54 isn't that line in the current version, although it's only one off, so maybe it's a misreporting?

Do the various fields show when you have the automatic option check in the module config settings?

Also, what is it that you are dumping on line 72 that is returning "FieldtypePassword" ?

One thing to try here - can you change the:

public function init() {

on line 48 to:

public function init() {

}

public function ready() {

Yes, it is making the init function empty and converting the current init() function into a ready() function.

Please let  me know if that helps.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @adrian. Thanks for your quick reply :)

42 minutes ago, adrian said:

Do the various fields show when you have the automatic option check in the module config settings?

 

No they did not show even when the option was checked.

Switching the init function to a ready function fixes the problem. I also thought of doing this, but didn't do it.
Now it is working fine :)

42 minutes ago, adrian said:

What version of the module are you running? Line #54 isn't that line in the current version, although it's only one off, so maybe it's a misreporting?

 

I use the latest version from github = 1.0.5 and if I open the file in a texteditor or in my IDE then line 54 is the correct line.

EDIT: Weird, on github it is line 55. Must be something in my editors.

Regarding the output of line 72 (that was something that I added):

bd($event->object->attributes["class"]);

There is a problem with removing the required attribute from password fields. It gets removed, but if you accidentally enter something in the password field and then delete it, you can not submit the form, because the required attribute gets added back in. This is coming from the InputfieldPassword.js which gets added to the page. Starting in line 120 it reads

$input.on('change', function() {
			var val = $(this).val();
			if(val.length > 0) {
				$input.attr('required', 'required');	
				$confirm.attr('required', 'required');
			} else if(!$(this).closest('.InputfieldStateRequired').length) {
				$input.removeAttr('required');
				$confirm.removeAttr('required');
			}
		});

So if the "Generate Password" Option is set, the script should not be executed or loaded.

One approach would be, to remove the CSS class "InputfieldPasswordComplexify" so the script does not react to it.

I tried to make a hook for this, but it does not work yet. Maybe you have some suggestions?

Here is my hook in the ready function:

$this->addHookBefore('InputfieldPassword::render', $this, 'removeComplexify');

and here the function

 protected function removeComplexify(HookEvent $event)
    {
        $f = $event->object;
        bd($f);
        $f->removeClass('InputfieldPasswordComplexify');
    }

I don't know what is wrong or if this is the right approach. I even tried to use addHookAfter, which also did not work. 

Maybe you have an idea?!

  • Like 2

Share this post


Link to post
Share on other sites

Wow, thanks for noticing that issue when manually entering and deleting a password - I had never come across that before.

The reason that "before" hook doesn't work for is because the InputfieldPassword::render() method uses addClass('InputfieldPasswordComplexify'), so you are removing it before it's actually added. I have achieved the same thing though with a str_replace on an "after" hook - not as elegant, but works fine.

You actually got me thinking about the whole approach to automatically generating the password and I thought it might be better to actually populate the fields when creating the user, rather than leaving them blank and populating when publishing the user.

I am going to PM you my current dev version to take a look at as see what you think of this new approach.

Thanks again for your help/feedback with this!

  • Like 1

Share this post


Link to post
Share on other sites

Ok, I have committed a new version which fixes the two bugs that @jmartsch reported.

As mentioned above, I have also revamped the password generator - it now populates the password fields while you are creating the user and the generated password matches the options defined in the PW "pass" field's config settings. The only one I can't match is the complexity factor, but so long as you stick to the default (or lower) it should all be fine - thanks to @Robin S's Password Generator (https://processwire.com/talk/topic/17406-password-generator/) for some inspiration :) 

Please let me know if you notice any problems with this new version.

  • Like 2

Share this post


Link to post
Share on other sites

Hey @adrian. I installed the new version from Github. There is a small bug that I found:

If I create a user and don't send him a welcome message, then the next time I edit this user (maybe I want to add some details to custom fields) the label of the email function reads "Re-send welcome message" although I did not send an email yet.

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

  • Like 1

Share this post


Link to post
Share on other sites

Another bug: If you choose to re-send the welcome message, a new password is not generated.

  • Like 1

Share this post


Link to post
Share on other sites

Here is another one: If I create a user via the API and use $new_user->sendEmail = true; an email is not being sent.

Here is the code that I execute via Tracy console:

$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "aceman3000@gmail.com";
$new_user->name ="aceman3000-gmail.com";
$new_user->sendEmail = true;
$new_user->save();

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi @jmartsch - looks like those recent changes broke a few things - sorry about that, but thanks for testing. Taking a look now.

Share this post


Link to post
Share on other sites

Ok @jmartsch, getting through these:

3 hours ago, jmartsch said:

If I create a user and don't send him a welcome message, then the next time I edit this user (maybe I want to add some details to custom fields) the label of the email function reads "Re-send welcome message" although I did not send an email yet.

Not sure how to handle this - the label changes from "Send" to "Resend" once the user has been published. I don't otherwise store a record of the email being sent. Sure it's possible, but I think it might get unnecessarily complicated. Do you have any thoughts for how it could be implemented well?

 

4 hours ago, jmartsch said:

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

EmailNewUser respects the "Automatic Force Change" option in the PasswordForceChange module which ensures it is automatically checked when a new user is created. Does that work for you? I am hesitant to override that setting if it's intentionally unchecked. What do you think?

 

4 hours ago, jmartsch said:

Another bug: If you choose to re-send the welcome message, a new password is not generated.

Thank you - that is a new bug - because the password was populating the pass fields, rather than being generated on publish. Now it will generate if nothing is already set, which is the case when re-sending the welcome message.

 

4 hours ago, jmartsch said:

Here is another one: If I create a user via the API and use $new_user->sendEmail = true; an email is not being sent.

Here is the code that I execute via Tracy console:


$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "aceman3000@gmail.com";
$new_user->name ="aceman3000-gmail.com";
$new_user->sendEmail = true;
$new_user->save();

 

Thanks - there are two things going on here. I broke this when I moved all the hooks yesterday from ready() to init(). I have fixed this now, but the other thing is that you are missing this:

$modules->get("EmailNewUser"); // call the module since it is not autoload on the front end

I just tested with your code with this on top in Tracy's console and it's now working fine.

Please test the latest version and let me know how you go.

Share this post


Link to post
Share on other sites
22 minutes ago, adrian said:
4 hours ago, jmartsch said:

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

EmailNewUser respects the "Automatic Force Change" option in the PasswordForceChange module which ensures it is automatically checked when a new user is created. Does that work for you? I am hesitant to override that setting if it's intentionally unchecked. What do you think?

Actually, maybe the solution here is another config setting in EmailNewUser. The setting would force automatic selection of "Force password change on next login", even if the "Automatic Force Change" option isn't checked in the PasswordForceChange module. Do you think this would work ok?

Share this post


Link to post
Share on other sites

Hey @adrian. The password generation in the latest version does not work correctly. It only generates passwords that are 1 char long.

In line https://github.com/adrianbj/EmailNewUser/blob/master/EmailNewUser.module#L158 you generate the new password. The output of 

bd($this->wire('fields')->get('pass')->minlength);

is null. If I try to insert a number instead, it works.

 $newPass = $this->passwordGenerator(6, false, $this->buildPasswordCharacterSets($this->wire('fields')->get('pass')));

I get back to the other questions soon.

Share this post


Link to post
Share on other sites

Hi @jmartsch - I can't seem to reproduce this - it always returns the correct value from the "pass" field's settings. I tried an API send and a Re-send message and they both returned 10 correctly.

In my case it is set to 10. Any chance your pass field is set to 1, or it's not named "pass".

What happens if you do: 

d($fields->get('pass')->minlength);

in the Tracy Console panel?

59f72a3c2a01d_ScreenShot2017-10-30at6_33_26AM.png.548dc5754c150787540faa72378716b0.png

Share this post


Link to post
Share on other sites

Actually, I think there is a bigger issue at hand - setting the password generator to less than 8 characters results in "too weak" from the PW password validation, so I am going to force the number of characters higher for the automatic generation. After all,  this is only meant to be a temporary password so probably no real need to worry because users will be copying/pasting anyway.

I'll commit an update shortly. Hopefully this will deal with your issue anyway, although it would still be nice to know why you are getting "1".

Share this post


Link to post
Share on other sites

Ok, new version committed. I am now forcing more complex password generation. Using the settings from the "pass" field just weren't working well - often not complex enough for the complexity validation, but should be good now.

Share this post


Link to post
Share on other sites

Adrian, thank you for your support. The new version is generating the password fine.

But now the problem is back that no email is being sent when I create the user via the API :(

Here is the code, that I used to test this:

$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->save();

In a fresh PW 3.0.80 install I tried the latest version 1.1.2 and the output of 

d($fields->get('pass')->minlength);

is still "null". If I output only the field, I get the following data (see screenshot).

chrome_2017-10-30_15-20-53.png

Share this post


Link to post
Share on other sites
1 minute ago, jmartsch said:

But now the problem is back that no email is being sent when I create the user via the API

Don't forget that you need: 

$modules->get("EmailNewUser");

Are you using that and it's still not working?

As for the minlength thing - I get the feeling that maybe you're using a version of PW without those newish settings? This is what I see.

59f73b7c92c94_ScreenShot2017-10-30at7_45_26AM.png.e8c36438f4fe522c8ea79eb3723896e3.png

 

Share this post


Link to post
Share on other sites

Thanks. I did not use 

$modules->get("EmailNewUser");

because I previously changed the module to autoload, but after the updates this setting was gone. Thanks for the hint.

I am using latest ProcessWire Dev version from Github which is 3.0.80

And my settings look like in my screenshot. I am on a Windows System if that matters. But I don't think so.

After going into the pass field and saving the settings my bar dump now shows the same settings as yours. But these settings seem to be not available by default.

image.png.9231233fce20266b31fbde4e0c6e8073.png

Share this post


Link to post
Share on other sites

Even when I use:

$modules->get("EmailNewUser");
$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->of(true);
$new_user->save();

in Tracy console, the mail is not being sent. Or do I do something wrong?

Share this post


Link to post
Share on other sites
9 minutes ago, jmartsch said:


 

because I previously changed the module to autoload, but after the updates this setting was gone. Thanks for the hint.

Glad that sorted things out. I could possibly make it optionally autoloaded on the frontend, but I figure that loading it manually like that is an acceptable approach - any strong thoughts on this?

9 minutes ago, jmartsch said:

After going into the pass field and saving the settings my bar dump now shows the same settings as yours. But these settings seem to be not available by default.

Interesting - is this site upgraded from an old PW version before these settings were available, or is it a new install? I wonder if that's the reason, but also wonder if it's something that the PW System Updater should have taken care of when you upgraded - maybe something to bring up with Ryan? Either way, it's good to know. I am no longer relying on these settings - all I am doing now is adding "symbols/puctuation" if selected, and using a higher min password length if it's set higher than the 12 which I am forcing as a minimum.

Share this post


Link to post
Share on other sites
5 minutes ago, jmartsch said:

Even when I use:


$modules->get("EmailNewUser");
$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->of(true);
$new_user->save();

in Tracy console, the mail is not being sent. Or do I do something wrong?

When I try that I get this error: 

Exception: Can’t save page 0: /admin/access/users/adrian5/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [roles] on line: 500 in /Users/ajones/Sites/ecoreportcard/wire/core/PagesEditor.php

59f74094c5c5c_ScreenShot2017-10-30at8_08_50AM.png.5dc76bf037829fa5d1fc2a80af8e2819.png

 

So, it's pretty clear that you can't turn outputformatting back on before saving (line 9). Do you not see that error in the Tracy console output?

Share this post


Link to post
Share on other sites

Yes, I removed that line, but email is still not being sent.

I even set autoload to true in the settings file, but that changes nothing.

Don't know why the email is not sent

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.

  • Similar Content

    • By Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
    • By Robin S
      Inspired by a recent question.
      Image Crop Ratios
      Allows preset aspect ratios to be defined per image field for the ProcessWire image crop tool.
      The module adds a select dropdown to the crop tool. Choose an aspect ratio and the crop area will be fixed to that ratio.
      Screencast

      Installation
      Install the Image Crop Ratios module.
      Configuration
      Default aspect ratios for all image fields can be defined in the module config. Aspect ratios for specific image fields can be defined on the Input tab of the field settings. You can override the ratio settings in template context if needed. Insert a hyphen as the first item in the ratio settings unless you want to force a ratio to be applied to the crop tool. The hyphen represents a blank option that allows a free crop area to be drawn. Usage
      Click the "Crop" link on the details view of an image thumbnail. Click the "Crop" icon at the top of the editor window. Choose an option from the "Ratio" select dropdown.  
      https://github.com/Toutouwai/ImageCropRatios
      https://modules.processwire.com/modules/image-crop-ratios/
×
×
  • Create New...