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

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

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 joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By MoritzLost
      This is a new module that provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory

    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "https://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...