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 Robin S
      After forgetting the class name of the wonderful AdminPageFieldEditLinks module for what feels like the 100th time I decided I needed to give my failing memory a helping hand...
      Autocomplete Module Class Name
      Provides class name autocomplete suggestions for the "Add Module From Directory" field at Modules > New.
      Requires ProcessWire >= v3.0.16.
      Screencast

      Installation
      Install the Autocomplete Module Class Name module.
      Configuration
      Choose the type of autocomplete options list: "Module class names from directory" or "Custom list of module class names". The latter could be useful if you regularly install some modules and would prefer a shorter list of autocomplete suggestions. The list of class names in the modules directory is generated when the Autocomplete Module Class Name module is installed. It doesn't update automatically (because the retrieval of the class names is quite slow), but you can use the button underneath when you want to retrieve an updated list of class names from the directory. The "fuzzy search" option uses custom filter and item functions for Awesomplete so that the characters you type just have to exist in the module class name and occur after preceding matches but do not need to be contiguous. Uncheck this option if you prefer the standard Awesomplete matching. Custom settings for Awesomplete can be entered in the "Awesomplete options" field if needed. See the Awesomplete documentation for more information.  
      https://github.com/Toutouwai/AutocompleteModuleClassName
      https://modules.processwire.com/modules/autocomplete-module-class-name/
    • By teppo
      MarkupMenu is a markup module for generating menu trees. When provided a root page as a starting point, it generates a navigation tree (by default as a HTML "<ul>" element wrapped by a "<nav>" element) from that point onwards. If you've also provided it with current (active) page, the menu will be rendered accordingly, with current item highlighted and items rendered up to that item and its children (unless you disable the "collapsed" option, in which case the full page tree will be rendered instead).
      Modules directory: https://modules.processwire.com/modules/markup-menu/ GitHub repository: https://github.com/teppokoivula/MarkupMenu Usage
      As a markup module, MarkupMenu is intended for front-end use, but you can of course use it in a module as well. Typically you'll only need the render() method, which takes an array of options as its only argument:
      echo $modules->get('MarkupMenu')->render([ 'root_page' => $pages->get(1), 'current_page' => $page, ]); Note: if you omit root_page, site root page is used by default. If you omit current_page, the menu will be rendered, but current (active) page won't be highlighted etc.
      A slightly more complex example, based on what I'm using on one of my own sites to render a (single-level) top menu:
      echo $modules->get('MarkupMenu')->render([ 'current_page' => $page, 'templates' => [ 'nav' => '<nav class="{classes} menu--{menu_class_modifier}" aria-label="{aria_label}">%s</nav>', 'item_current' => '<a class="menu__item menu__item--current" href="{item.url}" tabindex="0" aria-label="Current page: {item.title}">{item.title}</a>', ], 'placeholders' => [ 'menu_class_modifier' => 'top', 'aria_label' => 'Main navigation', ], 'include' => [ 'root_page' => true, ], 'exclude' => [ 'level_greater_than' => 1, ], ]); Note: some things you see above may not be entirely sensible, such as the use of {menu_class_modifier} and {aria_label} placeholders. On the actual site the "nav" template is defined in site config, so I can define just these parts on a case-by-case basis while actual nav markup is maintained in one place.
      Please check out the README file for available render options. I'd very much prefer not to keep this list up to date in multiple places. Basically there are settings for defining "templates" for different parts of the menu (list, item, etc.), include array for defining rules for including in the menu and exclude array for the opposite effect, classes and placeholders arrays for overriding default classes and injecting custom placeholders, etc. 🙂
      MarkupMenu vs. MarkupSimpleNavigation
      TL;DR: this is another take on the same concept. There are many similarities, but also some differences – especially when it comes to the supported options and syntax. If you're currently using MarkupSimpleNavigation then there's probably no reason to switch over.
      I'd be surprised if anyone didn't draw lines between this module and Soma's awesome MarkupSimpleNavigation. Simply put, I've been using MSN (...) for a number of years, and it's been great – but there have been some smallish issues with it, particularly with the markup generation part, and it's also doing some things in a way that just doesn't work for me – the xtemplates thing being one of these. In many ways it's less about features, and more about style.
      In MarkupMenu I've tried to correct these little hiccups, modernise the default markup, and allow for more flexibility with placeholder variables and additional / different options. MarkupMenu was built for ProcessWire 3.0.112+ and PHP 7.1+, it's installable with Composer, and I have a few additional ideas (such as conditional placeholders) on my todo list.
      One smallish and rather specific difference is that MarkupMenu supports overriding default options via $config->MarkupMenu. I find myself redefining the default markup for every site, which until now meant that each site has a wrapper function for MarkupSimpleNavigation (to avoid code / config repetition), and this way I've been able to omit that 🙂
      Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 If you're working on an earlier version of ProcessWire or PHP, use MarkupSimpleNavigation instead.
    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...