Jump to content
adrian

Email New User

Recommended Posts

This module allows you to automatically send an email to a newly created user with their username and password. It also has the option to automatically generate a password for the user upon creation.

http://modules.processwire.com/modules/email-new-user/

https://github.com/adrianbj/EmailNewUser

The following things are configurable:

  • Whether Send Email option should be automatically checked when creating new user - also affects new users created via API
     
  • From email address (if left blank it will use the admin email set in the config/php file
     
  • Email subject
     
  • Email body - includes the ability to use any fields from the user template using {field_name} codes so these can be put into the body wherever you want. It's your choice if you want to include the password in the email or not.
     
  • Whether to automatically generate a password. This can be toggled on/off, but even if it is on, you can override it by simply entering a password manually when creating the new user.
     
  • Ability to control the length and character sets used to make up the automatically generated password.
     
  • Option to send a test email to yourself to make sure it is configured the way you expect.

Because it is generally not a good idea to email passwords, it is highly recommended to use the new Password Force Change module in conjunction with this module. That way the user has to change their password the first time they login which will somewhat reduce the vulnerability of emailing the password.

post-985-0-79912800-1437180859_thumb.png

It can also be used for API generated users:

$modules->get("EmailNewUser"); // call the module since it is not autoload on the front end
$newuser = new User(); 
$newuser->name = 'newuser';
$newuser->email = 'newuser@gmail.com';
$newuser->sendEmail = true; // only needed if Automatic Email Send is unchecked
$newuser->save();

Please let me know if you have any ideas for improvements.

PS Thanks to everyone in this post: https://processwire.com/talk/topic/2981-new-user-welcome-message/ for their thoughts and ideas on how to do this.

  • Like 20

Share this post


Link to post
Share on other sites

Thanks adrian, not only for this new module but also for your

abundant supporting posts and contributions in this forum.

  • Like 9

Share this post


Link to post
Share on other sites

Because it is generally not a good idea to email passwords, it is highly recommended to use the new Password Force Change module in conjunction with this module. That way the user has to change their password the first time they login which will somewhat reduce the vulnerability of emailing the password.

I would be in favour of them choosing a password when signing up with an confirmation link in the email, assuming there was a signup form, however I appreciate that this module is limited ("focused" is probably a better word :)) in its scope and that my suggestion would be better suited to a wider user account module.

  • Like 1

Share this post


Link to post
Share on other sites
I would be in favour of them choosing a password when signing up with an confirmation link in the email, assuming there was a signup form, however I appreciate that this module is limited ("focused" is probably a better word  :)) in its scope and that my suggestion would be better suited to a wider user account module.

Hi Pete - that is exactly what I do with my front-end registration script, but this module is designed for backend creation of admin users. I have never facilitated user signup for admin accounts, but perhaps that is not a bad idea - a module that allows a user to signup for an account with their own details and then after email activation, the superuser gets an email with the new user's account edit link and then they go and make sure they are a valid user and then assign them the appropriate roles/permissions. Is that basically what you are suggesting?

Share this post


Link to post
Share on other sites

Just in case anyone was thinking this module forced you to send the user's password, I just wanted to clarify that if you don't want to email the password at all, that is no problem - the body of the email is completely configurable.

In the module config settings you create the message from scratch using any of the fields from the user's page however you want, so you could quite easily let your clients know their initial default password over the phone (potentially the same for each person in their team), but still have this module automatically send each user an email with their username and the link to the site's PW admin control panel.

Using this approach, together with Password Force Change, you'd have a very safe way of getting out the login details for the entire team of editors and making sure their passwords get immediately changed.

  • Like 2

Share this post


Link to post
Share on other sites

Minor, but important update today. This morning's commits to PW 2.4.17 made the password field required for new users, which broke this module when using the automatically generated password option. I just submitted a fix for this. Please let me know if you have any troubles.

  • Like 1

Share this post


Link to post
Share on other sites

Tried to install the module, got this:

Error: Class EmailNewUser contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Module::getModuleInfo)

Share this post


Link to post
Share on other sites

Tried to install the module, got this:

Error: Class EmailNewUser contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Module::getModuleInfo)

Sorry about that - I have just committed a fix that I think should take care of it. Please let me know if it works for you now.

Not sure why you got that error, but I have never seen it - maybe a PHP version difference?

Also, note that it requires PW dev due to the way I set up the module info in a separate file.

  • Like 1

Share this post


Link to post
Share on other sites

Adrian, i think this may be what I'm after through I've not had a chance yet to try it. I need to bulk import a number of users to become registered users. Could I import these users with csv to page and have this module email them their details?

Thanks

David

Share this post


Link to post
Share on other sites

Hi David,

There is definitely the possibility to do this, but depending on how you are doing the import I might need to tweak some things for you because the module is currently restricted to the admin template only. I did a test with creating a user via the API and the everything works as expected, so we should be good there.

How are you planning on importing? I tried Ryan's CSV importer, but it doesn't look like it will work for creating users because it doesn't have access to the name field of a page. Instead it uses the title, but user pages don't have a title field, so not sure how you could make it work. Also the issue of assigning roles to the imported users - again another strike for the CSV importer. So I think you'll need to write your own CSV import / user creation script - which should be fairly easy to do.

So anyway, once you have that up and running, let me know the exact mechanism and I'll do whatever might be needed to make this module play nicely for you.

It should also work well with the automatic password generation and combined with Force Password Change (http://modules.processwire.com/modules/password-force-change/) you should have a pretty easy method of setting up a large number of new users.

Anyway, let me know what you need.

Share this post


Link to post
Share on other sites

Hi David,

There is definitely the possibility to do this, but depending on how you are doing the import I might need to tweak some things for you because the module is currently restricted to the admin template only. I did a test with creating a user via the API and the everything works as expected, so we should be good there.

How are you planning on importing? I tried Ryan's CSV importer, but it doesn't look like it will work for creating users because it doesn't have access to the name field of a page. Instead it uses the title, but user pages don't have a title field, so not sure how you could make it work. Also the issue of assigning roles to the imported users - again another strike for the CSV importer. So I think you'll need to write your own CSV import / user creation script - which should be fairly easy to do.

So anyway, once you have that up and running, let me know the exact mechanism and I'll do whatever might be needed to make this module play nicely for you.

It should also work well with the automatic password generation and combined with Force Password Change (http://modules.processwire.com/modules/password-force-change/) you should have a pretty easy method of setting up a large number of new users.

Anyway, let me know what you need.

Ok, it's there!

Used Ryan's import users from CSV module. Added title to the users template which seems to duplicate in to the name field.My test csv looks like this:

title,pass,email,roles,,,,,

james,james,james@james.com,2107,,,,,

What's next?

Share this post


Link to post
Share on other sites

Well I just did some quick testing and things seem to work perfectly with all the emails being sent as soon as the CSV import is completed.

The only problem I noticed is getting the password into the email. If you don't populate the password via the CSV, and use the automatic password generation feature of my module, then it all works, but if you populate the email from the CSV, then my module doesn't have access to the password. Do the users already know their passwords? Could you use the automatic generation instead?

Let me know if you do need to import the passwords and I'll see what I can do about getting my module to grab these a different way - apparently the InputfieldPassword::processInput hook doesn't work in this situation.

The only other problem I noticed with the actual import was that I couldn't get the oles field to populate even though I added FieldtypePage to the array. Did the roles import work for you?

Share this post


Link to post
Share on other sites

Thanks so much.

I don't need to pre populate the passwords so I'm happy to have them generated by your module.

Yes, I did get the roles to import in the end.  It looks like this for me:

	protected $fieldtypes = array(
		'FieldtypePageTitle',
		'FieldtypeText',
		'FieldtypeTextarea',
		'FieldtypeInteger',
		'FieldtypeFloat',
		'FieldtypeEmail',
		'FieldtypeURL',
		'FieldtypeCheckbox',
		'FieldtypeFile',
		'FieldtypePassword', // add this line for passwords
		'FieldtypePage', // add this line for the roles
		);

I had to call the columns in the roles 'roles' and reference the role by ID rather than name

Share this post


Link to post
Share on other sites
I don't need to pre populate the passwords so I'm happy to have them generated by your module.

Great!

I had to call the columns in the roles 'roles' and reference the role by ID rather than name

I thought I did exactly the same - oh well so long as you have it working :)

I'd say install my module, run a test import of a few dummy users, all with your email address to make sure it works as expected, and then you should be good to go.

I am heading out now for a bit but will get back to you later if you report any problems.

Share this post


Link to post
Share on other sites

PS I would recommend also installing: http://modules.processwire.com/modules/password-force-change/

This way the user will be required to change their automatically generated temp password when they first sign in.

Make sure the role that you assign to each new user has edit-profile permission otherwise they won't be able to change their password!

Share this post


Link to post
Share on other sites

That's odd, on my playground site the module installed, but on the live site i got this error when installing it:

Error: Class EmailNewUser contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Module::getModuleInfo) (line 215 of /var/www/clients/client2/web37/web/site/modules/EmailNewUser/EmailNewUser.module) 

The site still functions but won't let me into the modules section without that message.

actually, happens on both upon install...

Edited by davo

Share this post


Link to post
Share on other sites

Sorry, I built the module using the new .info.json file for describing the module info which requires PW 2.4.3+

Upgrading to PW dev will fix it - keep in mind that 2.5 stable is slated for late this week, early next week, so there will be minimal changes before official release now. If you don't want to do that, just let me know and I'll quickly put together a version that will work just fine with 2.4 stable. The modules directory needs a dev option or at least a 2.x where x is the version after the current stable so people know a modules requires the dev version.

Edited by adrian

Share this post


Link to post
Share on other sites

I could upgrade my playground site early to test it all and then wait for the 2.5 stable release for the live site. Sound most sensible?

Share this post


Link to post
Share on other sites

I say go for it - there is certainly no reason to not be running the dev version on a test/dev site right now and if you find no problems, switch the live whenever you are ready.

Let me know how it goes - I think it would be nice to write up a tutorial for this when you're done to describe all the steps and any changes needed to the CSV importer to make it all work. I am actually tempted to build something specific to importing and emailing users, but maybe if we can have a clear step-by-step that will be fine too.

  • Like 1

Share this post


Link to post
Share on other sites

Success on playground site -

Deleted module

Upgraded pw to dev branch

installed new user email module

installed import pages from CSV

edited the module to include additional protected fields

successfully imported user from CSV and welcome email sent!

Thank you. When I do the live site I'll try and video the process for others.

Cheers!

  • Like 1

Share this post


Link to post
Share on other sites

I'm trying to get back to this again now. It's not currently sending emails for new users. Do you think it would be a good idea to in the module settings to add a 'send test email' button?

Share this post


Link to post
Share on other sites

Hi davo,

Pretty busy here this morning, so just a quick reply to say that I think email test sending is probably better left to one of the WireMail modules: http://modules.processwire.com/modules/wire-mail-swift-mailer/ or http://modules.processwire.com/modules/wire-mail-smtp/

I think they both have a test send function, although there might be some reliability issues with that - there is a couple of posts about that on the support thread for the latter module (the one by horst).

Are you getting any emails sent from your site at all? If any work, then the ones from this module should work fine.

Let me know how you go and I'll try to have more input later.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...