Add User and Send Email

Permalink 1 user found helpful
Is it possible to send a new user an email when they are added via the dashboard?

We do not want to use the registration features because we have an existing external process to collect and validate our members information (including email). We would like to be able to create the users, assign the group and have them receive an email that would allow them to click on a link and provide their own password (just like the forget password feature).

 
xaritas replied on at Permalink Reply
I just looked into this for a client project. I don't think it is supported natively, but if you don't mind writing a little bit of code it looks like it should be fairly simple. I haven't implemented it yet, so don't hold me to it.

You need to subscribe to the on_user_add event, documented here:
http://www.concrete5.org/documentation/developers/system/events/...

(This documentation actually uses on_add_user as the example so you are in luck).

Then you can invoke the code in /concrete/controllers/login.php that does the actual password reset email. Obviously you can copy and paste into your own code, or you can probably reuse it by stuffing the request object.
jpduffy77 replied on at Permalink Reply
xarita, thank you so much. This worked perfectly.

For those looking to do the same, here are the detailed steps I followed:

1. Add line to config/site.php --> define('ENABLE_APPLICATION_EVENTS',true);
2. Create file config/site_events.php
3. Put the following in site_events.php
<?php
Events::extend('on_user_update', /* event */
'LoginController', /* class */
'forgot_password', /* method */
'models/login.php');
?>

4. Copied concrete/controller/login.php to models/login.php
5. Changed the following lines in login.php

line 396: public function forgot_password() --> public function forgot_password($ui)
line 439: $loginData['msg']=$this->getPasswordSentMsg();--> $loginData['msg']='An email containing instructions on reseting your password has been sent to your account address.';
line 450: if($loginData['success']==1) --> blank (I deleted the text)
line 451: $this->redirect('/login', 'password_sent'); --> blank (I deleted the text)
annekeh replied on at Permalink Reply
annekeh
Hi guys,

This would be the perfect solution for me. When I try it, i get the following error:

Fatal error: Using $this when not in object context in /home/therapinfo/domains/eigenzorgpraktijk.nl/public_html/models/login.php on line 436

Do you know what went wrong?

Thank you!
moosh replied on at Permalink Reply
moosh
Hi,

I developped an addon for that but it currently in validation before being available on the marketplace.
annekeh replied on at Permalink Reply
annekeh
That would be great! Do you know when it is available?
moosh replied on at Permalink Reply
moosh
I don't know because there are a lot of addons in waiting approval actually...

I can send you by mail a copy of this addon, so you can test and give me your feedback.
Gingebean replied on at Permalink Reply
Gingebean
Hi there,

would love to test this out too, if it is possible.

thanks
remarkablecontent replied on at Permalink Reply
remarkablecontent
I can't see the plugin against your profile, did it get approved?
moosh replied on at Permalink Reply
moosh
Hi,

No sorry. This addon will not be available because it require so much core overrides and so must be a core feature.

Best,
moosh
remarkablecontent replied on at Permalink Reply
remarkablecontent
No worries, I got it sorted anyway!

Thanks for letting me know.
decibeldesign replied on at Permalink Reply
decibeldesign
For folks like myself whom were googling how to do this in 5.7.*, here's what I did to make it work:

In my application/bootstrap/app.php file, I added the following:

\Events::addListener('on_user_add', function($event) {
   $user = $event->getUserInfoObject();
   $mh = \Core::make('helper/mail');
   if (\Config::get('concrete.user.registration.email_registration')) {
        $mh->addParameter('uName', $user->getUserEmail());
        \Log::info(sprintf('Added user %s', $user->getUserEmail()));        
    } else {
        $mh->addParameter('uName', $user->getUserName());
        \Log::info(sprintf('Added user %s', $user->getUserName()));
    }
    //generate hash that'll be used to authenticate user, allowing them to change their password
    $h = new \Concrete\Core\User\ValidationHash();
    $uHash = $h->add($user->uID, intval(UVTYPE_CHANGE_PASSWORD), true);
    $changePassURL = \View::url(
            '/login',


Are there better ways to do this, rather than ripping code directly from the authentication controller for my listener? Most likely, but I'm new to 5.7.* and needed something fast! Feel free to suggest improvements!