Jump to content

Email New User


adrian

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 22
Link to comment
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
Link to comment
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?

Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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

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

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

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

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

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

Link to comment
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!

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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.

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
×
×
  • Create New...