adrian Posted July 21, 2014 Share Posted July 21, 2014 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. 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. 22 Link to comment Share on other sites More sharing options...
pwired Posted July 21, 2014 Share Posted July 21, 2014 Thanks adrian, not only for this new module but also for your abundant supporting posts and contributions in this forum. 10 Link to comment Share on other sites More sharing options...
Pete Posted July 21, 2014 Share Posted July 21, 2014 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. 1 Link to comment Share on other sites More sharing options...
adrian Posted July 21, 2014 Author Share Posted July 21, 2014 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 More sharing options...
Beluga Posted July 21, 2014 Share Posted July 21, 2014 I see this as really useful when migrating users from another CMS! Link to comment Share on other sites More sharing options...
adrian Posted July 22, 2014 Author Share Posted July 22, 2014 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. 2 Link to comment Share on other sites More sharing options...
adrian Posted September 3, 2014 Author Share Posted September 3, 2014 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. 1 Link to comment Share on other sites More sharing options...
kixe Posted September 5, 2014 Share Posted September 5, 2014 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) Link to comment Share on other sites More sharing options...
adrian Posted September 5, 2014 Author Share Posted September 5, 2014 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. 1 Link to comment Share on other sites More sharing options...
kixe Posted September 6, 2014 Share Posted September 6, 2014 Thanks for your help. It works with last dev. Link to comment Share on other sites More sharing options...
davo Posted September 9, 2014 Share Posted September 9, 2014 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 More sharing options...
adrian Posted September 10, 2014 Author Share Posted September 10, 2014 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 More sharing options...
davo Posted September 10, 2014 Share Posted September 10, 2014 Thank you. It looks like renobird has got it to create new users by adding the title field to the user template https://processwire.com/talk/topic/383-module-import-pages-from-csv-file/page-4 I'll have a go at this later and get back to you. 1 Link to comment Share on other sites More sharing options...
davo Posted September 10, 2014 Share Posted September 10, 2014 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 More sharing options...
adrian Posted September 10, 2014 Author Share Posted September 10, 2014 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 More sharing options...
davo Posted September 10, 2014 Share Posted September 10, 2014 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 More sharing options...
adrian Posted September 10, 2014 Author Share Posted September 10, 2014 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 More sharing options...
adrian Posted September 10, 2014 Author Share Posted September 10, 2014 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 More sharing options...
davo Posted September 10, 2014 Share Posted September 10, 2014 (edited) 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 September 10, 2014 by davo Link to comment Share on other sites More sharing options...
adrian Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) 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 September 11, 2014 by adrian Link to comment Share on other sites More sharing options...
davo Posted September 11, 2014 Share Posted September 11, 2014 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? Link to comment Share on other sites More sharing options...
adrian Posted September 11, 2014 Author Share Posted September 11, 2014 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. 1 Link to comment Share on other sites More sharing options...
davo Posted September 11, 2014 Share Posted September 11, 2014 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! 1 Link to comment Share on other sites More sharing options...
davo Posted October 23, 2014 Share Posted October 23, 2014 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? Link to comment Share on other sites More sharing options...
adrian Posted October 23, 2014 Author Share Posted October 23, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now