Merge user activation e-mail #115

Merged
aheathershaw merged 1 commits from feature/57-user-activation-email into master 2018-10-06 09:44:46 +01:00
6 changed files with 98 additions and 3 deletions
Showing only changes of commit 09de0f1356 - Show all commits

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth; namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Traits\ActivatesUsers;
use App\User; use App\User;
use Illuminate\Foundation\Auth\RedirectsUsers; use Illuminate\Foundation\Auth\RedirectsUsers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -10,7 +11,7 @@ use Illuminate\Support\Facades\App;
class ActivateController extends Controller class ActivateController extends Controller
{ {
use RedirectsUsers; use RedirectsUsers, ActivatesUsers;
/** /**
* Where to redirect users after activation. * Where to redirect users after activation.
@ -46,6 +47,8 @@ class ActivateController extends Controller
$request->session()->flash('info', trans('auth.account_activated_message')); $request->session()->flash('info', trans('auth.account_activated_message'));
$this->sendUserActivatedEmails($user);
return redirect($this->redirectPath()); return redirect($this->redirectPath());
} }
} }

View File

@ -7,6 +7,7 @@ use App\Facade\UserConfig;
use App\Helpers\MiscHelper; use App\Helpers\MiscHelper;
use App\Helpers\RecaptchaHelper; use App\Helpers\RecaptchaHelper;
use App\Mail\UserActivationRequired; use App\Mail\UserActivationRequired;
use App\Traits\ActivatesUsers;
use App\User; use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
@ -27,7 +28,7 @@ class RegisterController extends Controller
| |
*/ */
use RegistersUsers; use RegistersUsers, ActivatesUsers;
/** /**
* Where to redirect users after login / registration. * Where to redirect users after login / registration.
@ -127,6 +128,7 @@ class RegisterController extends Controller
if ($user->is_activated) if ($user->is_activated)
{ {
$this->sendUserActivatedEmails($user);
$this->guard()->login($user); $this->guard()->login($user);
} }
else else

View File

@ -0,0 +1,48 @@
<?php
namespace App\Mail;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class UserSelfActivated extends Mailable
{
use Queueable, SerializesModels;
private $createdUser;
private $user;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user, User $createdUser)
{
$this->user = $user;
$this->createdUser = $createdUser;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$subject = trans('email.user_self_activated_subject', ['app_name' => UserConfig::get('app_name')]);
return $this
->subject($subject)
->markdown(Theme::viewName('email.user_self_activated'))
->with([
'subject' => $subject,
'user' => $this->user,
'created_user' => $this->createdUser
]);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Traits;
use App\Mail\UserSelfActivated;
use App\User;
use Illuminate\Support\Facades\Mail;
trait ActivatesUsers
{
private function sendUserActivatedEmails(User $createdUser)
{
$adminUsers = User::where('is_admin', true)->get();
/** @var User $adminUser */
foreach ($adminUsers as $adminUser)
{
Mail::to($adminUser)->send(new UserSelfActivated($adminUser, $createdUser));
}
}
}

View File

@ -29,5 +29,9 @@ return [
'photo_comment_replied_to_comment_label' => 'Comments:', 'photo_comment_replied_to_comment_label' => 'Comments:',
'photo_comment_replied_to_p1' => 'A reply to your comment has been posted in the :album_name album.', 'photo_comment_replied_to_p1' => 'A reply to your comment has been posted in the :album_name album.',
'photo_comment_replied_to_p2' => 'Click the button below to view the photo\'s page to see the reply to your comment.', 'photo_comment_replied_to_p2' => 'Click the button below to view the photo\'s page to see the reply to your comment.',
'photo_comment_replied_to_subject' => 'A reply to your comment was posted in :album_name' 'photo_comment_replied_to_subject' => 'A reply to your comment was posted in :album_name',
'user_self_activated_p1' => 'A new user has been created and activated at :app_name. The user\'s details are shown below.',
'user_self_activated_p2' => 'Name: :user_name',
'user_self_activated_p3' => 'E-mail address: :email_address',
'user_self_activated_subject' => 'New user created at :app_name'
]; ];

View File

@ -0,0 +1,17 @@
@component('mail::message')
@lang('email.generic_intro', ['user_name' => $user->name])
@lang('email.user_self_activated_p1', ['app_name' => UserConfig::get('app_name')])
@lang('email.user_self_activated_p2', ['user_name' => $created_user->name])
@lang('email.user_self_activated_p3', ['email_address' => $created_user->email])
@lang('email.generic_regards')<br/>
{{ UserConfig::get('app_name') }}<br/>
<a href="{{ route('home') }}">{{ route('home') }}</a>
@endcomponent