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

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 Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
    • By Robin S
      Inspired by a recent question.
      Image Crop Ratios
      Allows preset aspect ratios to be defined per image field for the ProcessWire image crop tool.
      The module adds a select dropdown to the crop tool. Choose an aspect ratio and the crop area will be fixed to that ratio.
      Screencast

      Installation
      Install the Image Crop Ratios module.
      Configuration
      Default aspect ratios for all image fields can be defined in the module config. Aspect ratios for specific image fields can be defined on the Input tab of the field settings. You can override the ratio settings in template context if needed. Insert a hyphen as the first item in the ratio settings unless you want to force a ratio to be applied to the crop tool. The hyphen represents a blank option that allows a free crop area to be drawn. Usage
      Click the "Crop" link on the details view of an image thumbnail. Click the "Crop" icon at the top of the editor window. Choose an option from the "Ratio" select dropdown.  
      https://github.com/Toutouwai/ImageCropRatios
      https://modules.processwire.com/modules/image-crop-ratios/
×
×
  • Create New...