adrian

Email New User

Recommended Posts

I catch emails with Tracy´s mail interceptor, but no email is there. 

Share this post


Link to post
Share on other sites
Just now, jmartsch said:

Yes, I removed that line, but email is still not being sent.

I even set autoload to true in the settings file, but that changes nothing.

Don't know why the email is not sent

Is this site online? Can I take a look?

Share this post


Link to post
Share on other sites

I just tested with Mail Interceptor and it's catching the email just fine. Would you mind debugging the sendNewUserEmail() function - see if it's being called at all and where it is failing?

Share this post


Link to post
Share on other sites

Hey Adrian, I spotted another bug.

If you go to the modules settings and check the "Generate Password" option, then after saving an error occurs: "Session: You need to have digits and at least one of the letter options checked."

Share this post


Link to post
Share on other sites
5 minutes ago, jmartsch said:

Hey Adrian, I spotted another bug.

If you go to the modules settings and check the "Generate Password" option, then after saving an error occurs: "Session: You need to have digits and at least one of the letter options checked."

Sorry about that - I wasn't seeing that because I had an older, updated install that already had those options stored in the settings database.

New version just committed fixes it.

Thanks again!

  • Like 2

Share this post


Link to post
Share on other sites

Hi Adrian, I have a question :) 

I implemented login via link base on @Ivan Gretsky's code snippet: https://processwire.com/talk/topic/13708-login-with-a-link-is-it-called-magic-link/?do=findComment&comment=155465

I'm also using your module so that the site manager creating the users in the admin does not have to send the very first email to the user manually. The module sends the email successfully but I have a two issues:

  • While http://example.com/?user={id}&token={login_token} is turned into the proper "link", hardcoding the protocol+domain is not a good idea and {adminUrl} is not what I need.
  • I also implemented a simple form asking for an email only. When submitted,  the login token is regenerated for the user (associated with that email) and an email is sent with the new login link in it. It would be great to be able to base these two emails (mail sent by this module and mail sent by my form) on the same template, meaning they should be identical without me implementing them twice.

My function to send the new link via email is dead simple:

<?php
function site_email_user_login_info($login_user) {
    createLoginToken($login_user);
    $login_link = createLoginLink($login_user);
    $mail = wireMail();
    $mail->to($login_user->email);
    $mail->from('contact@example.com');
    $mail->subject('How to login...');
    $mail->bodyHTML("<html><body>
                        <h2>Some dummy header</h2>
                        <p>Some placeholder text. Blah-blah. Please click to login:</p>
                        <a href='{$login_link}'>{$login_link}</a>
                     </body></html>");
    $mail->send();
}

It is bodyHTML and the module's Email Massage which should be populated from the same source. Could you please give me some guidance on how to achieve this? Is it possible?

 

Share this post


Link to post
Share on other sites

Hi @szabesz - if I understand correctly, I think you could make use of this module instead of your custom site_email_user_login_info() function.

Via the API you can use:

$u->sendEmail = true;

If you need to adjust the body of the email (both via admin and frontent/API), you can hook into: EmailNewUser:: parseBody - you could add your own logic for dynamically building the http://example.com/?user={id}&token={login_token} link without hardcoding anything.

https://processwire.com/talk/topic/7051-email-new-user/?do=findComment&comment=136252

Let me know how you go.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, adrian said:

EmailNewUser:: parseBody

Thank you Adrian, this is what I need. I've long forgotten about it even though I did read your post.

I've just refactored my code to take advantage of it and everything works as expected, great module as always!

As for $u->sendEmail = true; I do not need it because my frontend form is not for creating new users but for sending an email to existing users. Why sending the same email? Because already registered users might have long forgotten how to login to the system so I want to send the same instructions no matter what. I will probably introduce a slight difference based on some simple logic but most part of the email body will be the same. For this reason I use the hook to completely overwrite $htmlBody which I find easier to implement than using str_replace and such to change something created in the RTE.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian,

My first time using this lovely module. A question and a couple of requests...

When editing/saving a user in admin, under what circumstances is an email sent if the "Automatic Email Send" option is checked? For existing users (who may have already been sent their welcome message) will an email be sent if nothing is changed but the user just saved? Silly me, I was trying to work it out from the code rather than just trying it out. I see now that the interface changes to "Re-send welcome message" after the first user save.

Request 1: It would be cool if there was an option in the module config to select key fields in the user template, where if any of those fields have changed the user is automatically sent an email. The obvious fields to trigger this would be "name" and "pass", but it would be nice to include custom fields too because in my case users log in with their email address. If other fields are changed no email would be sent. As I type this another thought occurs to me - maybe there could be different email templates for "new user" (password old value is blank) versus "modified user" (key field has changed)?

Request 2: How about a module config option for not showing the "Send welcome message" checkbox and the "Email message" CKEditor field in Edit User? In my scenario there are several different roles with different user-admin privileges. I'd rather take the decisions out of their hands whether or not to send an email and what the message will be.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @Robin S

All the "Automatic Email Send" option does is check the "Send welcome message" option when creating a new user. It doesn't have any impact on existing users, but there is an option to "Resend Welcome Message" to an existing user. This will re-generate a new password if that option is selected.

As for your requests, unfortunately I just don't have time at the moment as those look relatively substantial, but they sound useful. I think "2" especially sounds like a good idea. I am not sure about "1" - it sounds like it might be beyond the scope of "Email New User", but I am happy to be convinced that it's a worthwhile addition.

There's realistically no chance of me getting to this until late May, but of course PRs are always greatly appreciated :) Sorry I can't help out in a reasonable timeframe on this one!

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @adrian, no worries. The needs of my current project are fairly specific/unique so I'm not sure yet whether I'll modify the Email New User module or make a new custom module. I'm sure your module will be a big help in either case, and if I do make some additions to Email New User that could be useful to others I'll certainly share them here.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @Robin S - I think Request 2 would be pretty quick to implement, so might take a look at that when I am procrastinating from work.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, Robin S said:

Request 1: It would be cool if there was an option in the module config to select key fields in the user template, where if any of those fields have changed the user is automatically sent an email.

Just chiming in to point out that this sounds like something that might be better solved by the Field Change Notifier module. I'm not sure what the state of said module is, and it doesn't currently seem to support selecting notified user based on the page being edited either, but perhaps it would be easier to adapt to this need? :)

  • Like 2

Share this post


Link to post
Share on other sites

Hi @adrian, just a heads up:

I was again experiencing this issue that you raised in the PW issues repo a while ago: https://github.com/processwire/processwire-issues/issues/432

It was a bit puzzling but I traced it back to the Email New User module which I was testing out. Due to this commit the module is undoing the fix that was applied in the PW core.

  • Like 2

Share this post


Link to post
Share on other sites

Hi @Robin S - sorry about that. I can try to take a look tomorrow, but maybe in the meantime @Torsten Baldes could also see if there is an alternative to that commit of his that fixed the password issue, but not have the side-effect of breaking user saving?

  • Like 1

Share this post


Link to post
Share on other sites

Hey @Robin S - I just had a quick look and I can't actually see any issues with saving a user. Maybe I am doing doing the right thing, but can you please explain exactly what is required to reproduce?

Share this post


Link to post
Share on other sites
6 minutes ago, adrian said:

can you please explain exactly what is required to reproduce

The issue is exactly as you described it in the GitHub issue I linked to above. It is related to the browser autofilling the password field, so it depends on the form history that is saved in your browser. It's not the kind of thing that will always cause a problem, more one that can (but shouldn't) cause a problem. The fix that Ryan pushed to the core was to avoid that.

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

@adrian, looking at the commit that introduced the issue, it looks like removing the autocomplete attribute is an attempt to defeat this piece of InputfieldPassword.js.

That piece of JS is a fairly old (and hacky) response to a browser-specific (Firefox) issue that probably no longer applies. The recent autofill fixes in InputfieldPassword and updates/bug-fixes to Firefox should have solved it without the need for that JS workaround (I tested quickly in the latest Firefox and couldn't see any issue with the JS removed). So you could raise a GitHub issue/request to see if Ryan will remove that JS.

In the custom module I made for a project recently I took a different approach to auto-generated passwords. Rather than populate the core password field I manipulated the ProcessUser form to...

1. Hide the password field with CSS

2. Add a markup field to show the user the auto-generated password

3. Add a hidden field containing the auto-generated password

Then in a before hook to InputfieldPassword::processInput I copy the password value from the hidden field to the password field in $input.

That may not be an approach you'd want to take with your module, but just to show there might be other ways to tackle things if Ryan doesn't want to remove that problematic JS.

Edited by Robin S
Corrected hook method to InputfieldPassword::processInput
  • Like 2

Share this post


Link to post
Share on other sites

Thanks for looking into this @Robin S - what actually caused @Torsten Baldes to make that recent change is this recent commit by Ryan: https://github.com/processwire/processwire/commit/ba21b28b4ec6cf4651a618561f8faa149497f7e4#diff-b49b5256779b14f5ffbe105307aa2be2

Everything in this module was working fine until that change in the PW core! Unfortunately I don't see Ryan removing that code because the change was to help fix a recently reported bug. Perhaps I can convince him to add an additional check though. What I have come up with that seems to work is to replace:

https://github.com/processwire/processwire/blob/184059b5d66a6ed8c739594d6b51d8d11f17d62d/wire/modules/Inputfield/InputfieldPassword/InputfieldPassword.js#L175

if($(this).val().length < 1) return;

with:

if($(this).val().length < 1 || $(this).attr('value').length > 0) return;

I am sure it's obvious, but what I am doing is checking the actual value attribute of the field at page load (rather than what is currently entered in the field). Now, if it's already populated (like Email New User does), it won't remove the password. This change means I can actually remove this hooked method entirely:

https://github.com/adrianbj/EmailNewUser/blob/a93ea9d73ef523f1abd19135516edd80ac4ebf37/EmailNewUser.module#L63-L65

Would you mind checking at your end to see if everything works as expected. If it does, I'll see if I can get Ryan to make that change.

@Torsten Baldes - could you please try this approach too please - I really need to revert your recent change ASAP as it's breaking things. Thanks!

  • Like 2

Share this post


Link to post
Share on other sites
5 hours ago, adrian said:

This change means I can actually remove this hooked method entirely:

https://github.com/adrianbj/EmailNewUser/blob/a93ea9d73ef523f1abd19135516edd80ac4ebf37/EmailNewUser.module#L63-L65

Would you mind checking at your end to see if everything works as expected.

If the hook is removed then it will fix the issue I was seeing, because with the autocomplete attribute being on the password fields those fields aren't autofilled by Chrome.

So if the extra condition you added to the JS prevents your generated password from being cleared and you can therefore remove the hook then it will be all good from my end. I guess if/when Firefox autofills the password field it doesn't affect the value attribute? I can't test it here because I can't get Firefox to autofill the password field anyway (or I just don't know what steps are required to reproduce the issue on that browser).

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, Robin S said:

I guess if/when Firefox autofills the password field it doesn't affect the value attribute?

From what I can see, the value attribute is not populated by autocomplete in any browser. Keep in mind that val() and attr('value') are very different things. 

Hopefully Ryan will see this: https://github.com/processwire/processwire-issues/issues/537#issuecomment-383411262 and be happy to implement.

  • Like 1

Share this post


Link to post
Share on other sites
On 22.4.2018 at 8:54 PM, adrian said:

@Torsten Baldes - could you please try this approach too please - I really need to revert your recent change ASAP as it's breaking things. Thanks!

@adrian Sorry I just saw this. If it breaks something revert it. Seems to work for me.

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S, @Torsten Baldes and everyone else.

Ryan has just implemented my suggestion for that snippet of JS which means that I can now remove the autocomplete removal hack from this module.

Please update your PW core and this module and let me know if you find any further issues.

Thanks!

  • 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 thomasaull
      Some time ago I created a site profile for creation of a REST API with ProcessWire. Since I kept struggeling with updating stuff between different projects which use this, I decided to convert it into a module. It is now ready for testing: https://github.com/thomasaull/RestApi
      Additionally I added a few small features:
      automatic creation of JWT Secret at module install routes can be flagged as auth: false, which makes them publicly accessible even though JWT Auth is activated in module settings To check things out, download and install the module and check the folder /site/api for examples.
      If you find any bugs or can think of improvements, please let me know!
    • By kongondo
      Sites Manager
       
      16 September 2018:
      FOR NOW, PLEASE DO NOT USE THIS MODULE IN A PRODUCTION SITE. A  RECENT ProcessWire UPDATE HAS BROKEN THE MODULE. I AM WORKING ON A FIX.
       
      ################
       
      Sites Manager is a module for ProcessWire that allows Superusers to easily create/install ProcessWire sites on the same serverspace the module is running in. Only Superusers can use the module. You can create both stand-alone and multi-sites.
       
      Single/Stand-alone Sites
      Stand-alone or single-sites are sites that will run in their own document root/directory with their own wire and site folders, .htaccess, index.php, etc. In other words, a normal ProcessWire site.
      Multiple Sites
      Multi-sites are sites that will run off one wire folder (shared amongst two or more sites) each having their own site folder and database. In this regard, it is important to note that Sites Manager is not in itself a multiple sites solution! Rather, it is a utility that helps you create multi-sites to be run using the ProcessWire core multiple sites feature. For more on this core feature, see the official ProcessWire documentation, specifically the solution referred to as Option #1.
      Option #1 approach requires the site admin to initially install ProcessWire in a temporary directory for each new site. The directory then needs to be renamed as site-xxx, where ‘xxx’ is any name you want to use to differentiate the installation from other sites, before it is moved to the webroot. For instance, site-mysite, site-another, site-whatever. In addition, the /wire/index.config.php file must be copied/moved to the webroot. Each time a site is added, the index.config.php has to be edited to add ‘domain’ => ‘site-directory’ key=>value pairs for the site. This process can become a bit tedious. This module aims to automate the whole multi-site site creation process.
      The module is based off the official ProcessWire installer. Creating a site is as simple as completing and submitting a single form! You also have the option to type and paste values or reuse a pre-defined install configuration.
       
      The module will:
      Install a ProcessWire site in your named directory, applying chmod values as specified
      Move the directory to your webroot
      Update/Create a Superuser account as per the submitted form, including setting the desired admin theme and colour
      For multi sites, update sites.json (used by index.config.php to get array of installed sites)
       
      For multi sites, the only difference in relation to the core multi-sites index.config.php is that this file is slightly different from the one that ships with ProcessWire.
      Download from GitHub: Sites Manager (Beta Release)
      Features
      Install unlimited number of sites in one (multi-sites) or independent (single-site) ProcessWire installs. Install by completing a Form, Typing or pasting in configurations or using pre-created install configurations. Choose an Admin Theme to auto-install along with the site installation. For single-sites installation, download, save and reuse ProcessWire versions of your choice. Install and maintain site profiles for reuse to create other sites. Create install configurations to speed up installation tasks. Client and server-side validation of site creation values. Edit uploaded profiles (e.g., replace profile file). Lock installed sites, configurations and profiles to prevent editing. Bulk delete items such as site profiles, installed site directories and/or databases (confirmation required for latter two). View important site details (admin login, chmod, etc). Links to installed sites home and admin pages. Timezones auto-complete/-suggest. Pre-requisites, Installation & Usage
      Please see the documentation.
      Technicalities/Issues
      Only Superusers can use the module.
      ProcessWire 2.7 - 3.x compatible
      Currently using ProcessWire 2.7 installer (install.php)
      For multi-sites, potential race condition when sites.json is being updated on a new site install vs. index.config.php accessing the json file?
      Not tested with sub-directory installs (for instance localhost/pw/my-site-here/)
      Currently not doing the extra/experimental database stuff (database charset and engine)
      Future Possibilities
      Install specified modules along with the ProcessWire install
      Profile previews?
      Credits
      @ryan: for the ProcessWire installer
      @abdus: for the index.config.php reading from JSON idea
      @swampmusic: for the challenge
      Video Demo
      Demo  showing how quick module works on a remote server [YMMV!]. Video shows downloading and processing two versions of ProcessWire (~takes 7 seconds) and installing a single/stand-alone ProcessWire 3 site using the new Admin Theme UI Kit (~2 seconds) on a remote server.
       
      Screens
      1

      2

       
       
    • By Robin S
      Breadcrumb Dropdowns
      Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.

      Installation
      Install the Breadcrumb Dropdowns module. The module requires ProcessWire >= v3.0.83 and AdminThemeUikit.
      There is a checkbox option in the module config that determines if the breadcrumb dropdowns will include pages that the user does not have permission to edit.
      Features/details
      The module adds an additional breadcrumb item at the end for the currently edited page. That's because I think it's more intuitive for the dropdown under each breadcrumb item to show the item's sibling pages rather than the item's child pages. In the dropdown menus the current page and the current page's parents are highlighted in a crimson colour to make it easier to quickly locate them in case you want to edit the next or previous sibling page. Unpublished and hidden pages are indicated in the dropdowns with similar styling to that used in Page List. If the option to include uneditable pages is selected then those pages are indicated by italics with a reduced text opacity and the "not-allowed" cursor is shown on hover. There is a limit of 25 pages per dropdown for performance reasons and to avoid the dropdown becoming unwieldy. If the current user is allowed to add new pages under the parent page an "Add New" link is shown at the bottom of the breadcrumb dropdown. If the currently edited page has children or the user may add children, a caret at the end of the breadcrumbs reveals a dropdown of up to the first 25 children and/or an "Add New" link. Overriding the listed siblings for a page
      If you want to override the siblings that are listed in the dropdowns you can hook the BreadcrumbDropdowns::getSiblingsmethod and change the returned PageArray. For most use cases this won't be necessary.
      Incompatibilities
      This module replaces the AdminThemeUikit::renderBreadcrumbs method so will potentially be incompatible with other modules that hook the same method.
       
      https://modules.processwire.com/modules/breadcrumb-dropdowns/
      https://github.com/Toutouwai/BreadcrumbDropdowns
    • By bernhard
      Some of you might have followed the development of this module here: https://processwire.com/talk/topic/15524-previewdiscussion-rockdatatables/ . It is the successor of "RockDataTables" and requires RockFinder to get the data for the grid easily and efficiently. It uses the open source part of agGrid for grid rendering.
       
      WHY?
      ProcessWire is awesome for creating all kinds of custom backend applications, but where it is not so awesome in my opinion is when it comes to listing this data. Of course we have the built in page lister and we have ListerPro, but none of that solutions is capable of properly displaying large amounts of data, for example lists of revenues, aggregations, quick and easy sorts by the user, instant filter and those kind of features. RockGrid to the rescue 😉 
       
      Features/Highlights:
      100k+ rows Instant (client side) filter, search, sort (different sort based on data type, eg "lower/greater than" for numbers, "contains" for strings) extendable via plugins (available plugins at the moment: fullscreen, csv export, reload, batch-processing of data, column sum/statistics, row selection) all the agGrid features (cell renderers, cell styling, pagination, column grouping etc) vanilla javascript, backend and frontend support (though not all plugins are working on the frontend yet and I don't plan to support it as long as I don't need it myself)  
      Limitations:
      While there is an option to retrieve data via AJAX the actual processing of the grid (displaying, filtering, sorting) is done on the client side, meaning that you can get into troubles when handling really large datasets of several thousands of rows. agGrid should be one of the most performant grid options in the world (see the official example page with a 100k row example) and does a lot to prevent problems (such as virtual row rendering), but you should always have this limitation in mind as this is a major difference to the available lister options that do not have this limitation.
      Currently it only supports AdminThemeUikit and I don't plan to support any other admin theme.
       
      Download: https://gitlab.com/baumrock/FieldtypeRockGrid
      Installation: https://gitlab.com/baumrock/RockGrid/wikis/Installation
      Quikckstart: https://gitlab.com/baumrock/RockGrid/wikis/quickstart
      Further instructions: https://gitlab.com/baumrock/RockGrid/wikis/quickstart#further-instructions
      Changelog: https://gitlab.com/baumrock/FieldtypeRockGrid/raw/master/changelog.md
       
      Module status: alpha, License: MIT
      Note that every installation and uninstallation sends an anonymous google analytics event to my google analytics account. If you don't want that feel free to remove the appropriate lines of code before installation/uninstallation.
       
      Contribute:
      You can contribute to the development of this and other modules or just say thank you by
      testing, reporting issues and making PRs at gitlab liking this post buying me a drink: paypal.me/baumrock/5 liking my facebook page: facebook.com/baumrock hiring me for pw work: baumrock.com  
      Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour (excl vat).
       
      Use Cases / Examples:
      Colored grid cells, Icons, Links etc. The Grid also has a "batcher" feature built in that helps communicating with the server via AJAX and managing resource intensive tasks in batches:

      Filters, PW panel links and instant reload on panel close:

      You can combine the grid with a chart library like I did with the (outdated) RockDataTables module:

    • By Ken Muldrew
      I'm trying to get a short routine to run once per day that will look at some pages and send a reminder email when that customer's subscription (yearly) is about to expire. When I run the code in a template then it works without issue, but inside my lazycron service routine, I get an "Error: Uncaught Error: Call to a member function get() on null" as if the database cannot be found. My autoload module is just the sample HelloWorld module included with ProcessWire, editted to perform this task. The whole of it is included below (I've stripped out the code that generates the email because it never gets past $pages->find):
       
      <?php namespace ProcessWire;
      /**
       * ProcessWire 'LazyCronLoad'  module
       *
       */
      class LazyCronLoad extends WireData implements Module {
          public static function getModuleInfo() {
              return array(
                  'title' => 'LazyCronLoad', 
                  'version' => 1, 
                  'summary' => 'Just loads a lazy cron callback.',
                  'singular' => true, 
                  'autoload' => true, 
                  );
          }
          public function init() {
              // initialize the hook in the AutoLoad module
              $this->addHook('LazyCron::everyDay', $this, 'myHook');
              
          }
          public function myHook(HookEvent $e) {
              // called once per day
              wire('log')->save('user_activities',' lazy cron service routine');
                  $transport_pages = $pages->find("template=aggregate-entry, aggregate_type.title='Transport'");
                  foreach ($transport_pages as $page) {
                      if (($page->purchase_date + 30325800 < time()) && ($page->purchase_date + 30412600 > time())) { // between 351 and 352 days
                          wire('log')->save('user_activities', $page->id . ' email reminder sent');
                          // send email
                  }
              }
          }        
          
      }
      The first wire('log') shows up but the second one doesn't (the purchase_date condition is met (as demonstrated by running the code in a template close in time to when the lazycron routine executes)). The error log gives the Uncaught Error shown above. 
      I think this is a beginner's mistake with something obvious being missed and would be grateful for any assistance in fixing it.