Jump to content
adrian

Email New User

Recommended Posts

Actually, on second thought (distracted thoughts while working on something totally non-PW), I think a test send would be a good idea - would be nice to see exactly what the users will getting emailed to them.

Might take me a few days to get to this, but I will get to it as soon as I can.

  • Like 1

Share this post


Link to post
Share on other sites

I have just committed an update that adds an option to send a test message from the module settings page.

The fields in the email body will come from the sending user's account so you must have an email entered for your account and if you have fields like first name etc in the body template, then you should have those completed for your account also.

If your body template makes use of the {pass} code, in the test email you will see "password" instead of your actual password. 

Please let me know if you find any problems with this new version or any other ideas for improvements.

  • Like 1

Share this post


Link to post
Share on other sites

There is something you could explain though. I'm still working on an easy login process for people so i tried putting the following in the welcome email:

Welcome {first_name} {last_name}

Please login in at: http://abandoman.co.uk/login/{name}/{pass}

Username: {name}
Password: {pass}

If you have any questions, please email us at: {fromEmail}

I enable url segments and put the following in my login page:


if($input->urlSegment(1) && $input->urlSegment(2)) {
	$username = $sanitizer->username($input->urlSegment(1));
        $pass = $input->urlSegment(2);
         $u = $session->login($username, $pass);
  		if ($u && $u->id) {
    // user is logged in, get rid of tmp_pass
    $u->of(false);
    $u->tmp_pass = '';
    $u->save(); }
         $session->redirect("/");
}

Works great if you have a simple user name and password, but with a system generated one it throws a page not found error.

I'm assuming that's because of all the stars and @s in the password.

Is there anyway around this?

Share this post


Link to post
Share on other sites

Not that I necessarily think it is a good idea that you're logging people in using the password in the url!

But I thought it would be a good idea to add this functionality anyway - so with the new version you can now control the character sets used in the automatically generated password, as well as its length.

Turning off the "Special Characters" set should take care of what you need.

Let me know if that works for you.

  • Like 1

Share this post


Link to post
Share on other sites

That's great. Logs in first time.

I don't need nca proof passwords for this site and if it got sent or intercepted by email I don't think there's too much damage that could be done anyway.

Awesome module

  • Like 1

Share this post


Link to post
Share on other sites

I've been testing a bit further and have noticed some anomalies which you may be able to advise on. 

The module works great when creating a user from the back end, but when I create a user using form builder 2.4 dev to create a page user details, the email fails to send.

I'm using the following hook to push the password and title into a session variable for later user:


wire()->addHookAfter('FormBuilderProcessor::formSubmitSuccess', function($event) {
  $form = $event->arguments(0); 
  if($form->name != 'new-user') return;
  $field = $form->get('password'); 
  $value = $field->attr('value'); 
  wire('session')->set('password', $value); 

    
      
      $field = $form->get('title');
      $value = $field->attr('value'); 
      wire('session')->set('title', $value);
}); 

I'm sure that prior 'email new user' was sending out an email on creation of a user from the front end.

The things that have changed are:

I've added the hook

upgraded for builder from 2.2 to 2.4 dev

upgraded the module

Could any of these thing have affected it's behaviour?

Share this post


Link to post
Share on other sites

Just a quick guess - I did make the module only load for the admin at some point, but it was several versions back. Try going into:

EmailNewUser.info.json and changing:

"autoload": "template=admin",

to:

    "autoload": true,

If that works, I'll consider changing it back for you in the main module code.

Let me know if that works for you.

Share this post


Link to post
Share on other sites

That change made sense, but unfortunately didn't work.

Looks like this:

{

"title": "Email New User",

"summary": "Email new user their account details, and optionally automatically generate a password for them.",

"version": 14,

"author": "Adrian Jones",

"autoload": true,

"requires": "ProcessWire>=2.4.3",

"icon": "envelope-o"

}

I'm sure this was working a while ago, but now I'm starting to doubt myself.

Thanks for your help with this.

Any ideas?

Maybe I'll have to look again with a fresh head from another angle.

Share this post


Link to post
Share on other sites

davo,

Just a quick note to say that I tested on the front-end and it works fine like this:

$modules->get("EmailNewUser");
$u = new User();
$u->name = 'newuser';
$u->email = 'newuser@gmail.com';
$u->save();

Note that I am manually calling the module - that avoids the need to make it autoload on the front-end.

I don't see where in your form builder hook that you create a new user ?

Share this post


Link to post
Share on other sites

Ah! I don't use a hook for that purpose. I let form builder process the form and publish as a new user 'user page'.

Share this post


Link to post
Share on other sites

davo,

Just a quick note to say that I tested on the front-end and it works fine like this:

$modules->get("EmailNewUser");
$u = new User();
$u->name = 'newuser';
$u->email = 'newuser@gmail.com';
$u->save();

Note that I am manually calling the module - that avoids the need to make it autoload on the front-end.

I don't see where in your form builder hook that you create a new user ?

Could that be the issue you think? form builder publishes the form as a new page rather than calling a hook to make a new user?

Share this post


Link to post
Share on other sites

I just tested this which is how I would expect form builder is probably creating the page and it also works:

$modules->get("EmailNewUser");
$p = new Page();
$p->name = "me";
$p->parent = $pages->get(29);
$p->template = $templates->get("user");
$p->email = "me@gmail.com";
$p->of(false);
$p->save();

So the only things I can think of are that the module is not being loaded. See here that again I am manually loading it, but if you change it to autoload in the module, you should be ok.

The other thing to clarify - is the form definitely creating and saving the email address?

I am not really a form builder user, but perhaps if you can explain your exact configuration I can play around with it and test at my end. 

Share this post


Link to post
Share on other sites

Ok, it all makes sense now :)

Ideally it would be best if you could hook into the point before the form builder saves the page - not sure what that hook is - sorry.

But, if you want to quickly test, the autoload = true option works, you just have to remember to refresh your modules: Modules > Refresh after you make that change to the info.json file that I mentioned above.

Do that and I think the emails should send fine even via the formbuilder user page creation.

It shouldn't be a huge problem to leave the module autoload because it checks to make sure that the page being saved has the user template, so it shouldn't affect any other pages on the front-end.

Let me know if that works for you.

  • Like 1

Share this post


Link to post
Share on other sites

I've just foolishly made two changes, and although it now works, I don't know which it was!

First I put this on the page that loads the form:

$modules->get("EmailNewUser");

Second I refreshed the module

And now it works!

  • Like 1

Share this post


Link to post
Share on other sites

So long as you are loading the module on the front end like that, the refresh shouldn't be relevant. The refresh was only if you wanted to do the autoload, but this is much better. I wasn't think about adding the load to the page containing the form - much easier than hooking - good thinking :)

Share this post


Link to post
Share on other sites

Have you changed in the latest update to force a password even if it is not blank?

Share this post


Link to post
Share on other sites

Hi davo - sorry not exactly sure what you mean. I can't see anything in the latest commit that would have change the password behavior.

Can you try to explain a little differently what you mean.

Share this post


Link to post
Share on other sites

I'm sure that a couple of versions ago, it was set to only create a password if one had not already been set. Now, if I have the 'create password' checked it's creating one regardless, meaning my login mechanism isn't working as it's immediately been over written by the module.

If I uncheck the field, the password sent in the email is blank.

I assumed you'd changed something a version or two ago. I was sure it said in the text next to that field a password would only be created if the  field was blank?

Share this post


Link to post
Share on other sites

I am only testing via the admin at the moment, but everything seems to be working here whether the "Generate Password" option is checked or not. In either case I can manually enter a password and that is the one that gets emailed out.

If it isn't checked, and I don't manually enter one, I get a warning that the email wasn't sent because the password wasn't set, but if I do manually set it, it works fine.

What exact code are you using to create the user and add the password?

Share this post


Link to post
Share on other sites

Unfortunately I don't know the exact code as   I use form builder to match fields into the user template, but I'll walk you through the process....

I have a template that loads the module on the page and then loads the form in form builder like this:

<?php 
$modules->get("EmailNewUser");
echo $forms->embed('new-user'); ?>

Then, in the form there is a field called title which maps to 'name' in a user page. There is also a password field which also maps to 'password'.

The new user is created.

In the form builder include file i have the following code:

<?php 

wire()->addHookAfter('FormBuilderProcessor::formSubmitSuccess', function($event) {
  $form = $event->arguments(0); 
  if($form->name != 'new-user') return;
  $field = $form->get('password'); 
  $value = $field->attr('value'); 
  wire('session')->set('password', $value); 

    
      
      $field = $form->get('title');
      $value = $field->attr('value'); 
      wire('session')->set('title', $value);

      $field = $form->get('dob');
    $value = $field->attr('value'); 
 wire('session')->set('dob', $value);

      $field = $form->get('email');
    $value = $field->attr('value'); 
 wire('session')->set('email', $value);
}); 

The above code helps me then store the newly created variables as session variables so I can use them on the following page.

On successful page creation (user) , the user is redirections to my acc_success page which consists of the following::


<?php

$dob = $session->dob;
$email = $session->email;

$new_user = $pages->get("email=$email");
$password = $session->password;
$username = $new_user->name;

    if($session->login($username, $password)){
         $session->redirect("/");}



echo "<p>Thats great. Now just click below to log in and help judge - <i>its ok, its for science!</i></p><p><a href='/login/{$new_user->name}/{$password}'>Log in {$new_user->name} with the password {$password}</a></P>";

?>

This should look for a user matching the email address supplied and look up the user name and use the previously supplied password to log the user in.

The odd behaviour i'm suffering is that if the create user password is ticked, it over rides the user created password and the automatic login fails. I check the email sent and it references a newly created password.

If the create password is not ticked then the automatic login succeeds but of course no password is supplied by the module.

Suddenly typing this out it makes more sense!

I guess the situation I want to get to is for the module to only to create a password if it were left blank, but also to be able to include the password supplied by by the session variable.... I guess that's my next move to try.

Share this post


Link to post
Share on other sites

So this is what i tried to use the session variable in the module settings:

Welcome {first_name} {last_name}

Your photo has been submitted! Login to judge yourself against others. 

Please login in at: http://abandoman.co.uk/login/{name}/{pass}{$session->password}

the email was just blank  for both pass and session->password parts.

don't worry too much, I know what i'm trying to get it to do is a bit beyond it's original purpose

Share this post


Link to post
Share on other sites

Firstly, the $session->password will never work, because I am not using eval to pass the contents of the email, but rather using the {} as a replacement mechanism.

The problem with getting a password manually entered via the API was that I was using the InputfieldPassword::processInput hook to grab the password before it is encoded. This won't be triggered when the password is set via the API.

I just committed an update that uses the Password::setPass hook instead and it seems to be working well in all scenarios, including setting the password via the API.

Could you please test and let me know if that fixes things for you?

  • Like 2

Share this post


Link to post
Share on other sites

I don't know how you did it... but it all seems to work now! Thank you.

  • Like 1

Share this post


Link to post
Share on other sites

Just committed some new features:

  • New checkbox "Send welcome message" added to the bottom of each user page - uncheck to NOT send the email to a new user.
  • You can use this checkobox to re-send a user's welcome email if needed.
  • You can edit the welcome message template for each user as you create and save the user.
  • Also some better error reporting, and detection of PasswordForceChange.

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

  • Like 2

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 eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild.  
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Steps (Read more) Manual override of the selected value (will still adhere to the rules above) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant If it's usable for others I'll add it to the Modules list  
      Changelog
      v002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional 
      v001
      - Initial release
       
      Thanks!
       
       
    • 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...