- inform main admin about new user registration
- in UserController.php new user is created and and email will be sent - email view is in resources/views/emails/newUserEmail.blade.php - App\MailNewUser Mailable
This commit is contained in:
parent
390b2396eb
commit
4bc66213a4
|
@ -2,11 +2,13 @@
|
||||||
namespace App\Http\Controllers\Settings\Access;
|
namespace App\Http\Controllers\Settings\Access;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Mail\NewUser;
|
||||||
use App\Models\Role;
|
use App\Models\Role;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -81,6 +83,18 @@ class UserController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inform main admin about new user
|
||||||
|
$adminUser = User::where('email', config('mail.mailadmin'))->first();
|
||||||
|
if ($adminUser) {
|
||||||
|
// Mail::to("receiver@example.com")->send(new DemoEmail($objDemo));
|
||||||
|
$details = [
|
||||||
|
'title' => 'New user ',
|
||||||
|
'admin_name' => $adminUser->login,
|
||||||
|
'email' => $user->email,
|
||||||
|
];
|
||||||
|
Mail::to($adminUser->email)->send(new NewUser($details));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('access.user.index')
|
->route('access.user.index')
|
||||||
->with('success', 'User has been created successfully');
|
->with('success', 'User has been created successfully');
|
||||||
|
@ -149,7 +163,7 @@ class UserController extends Controller
|
||||||
$errors = new \Illuminate\Support\MessageBag();
|
$errors = new \Illuminate\Support\MessageBag();
|
||||||
|
|
||||||
if (array_key_exists('current_password', $input)) {
|
if (array_key_exists('current_password', $input)) {
|
||||||
// if user is not admin he must enter old_password if a new password is defined
|
// if user is not admin he must enter old_password if a new password is defined
|
||||||
if (!Auth::user()->hasRole('Administrator') && $input['current_password'] == null && $input['password'] != null) {
|
if (!Auth::user()->hasRole('Administrator') && $input['current_password'] == null && $input['password'] != null) {
|
||||||
//ModelState.AddModelError("OldPassword", Resources.User_Edit_OldPasswordEmpty);
|
//ModelState.AddModelError("OldPassword", Resources.User_Edit_OldPasswordEmpty);
|
||||||
//$flash_message = 'Current password should not be empty.';
|
//$flash_message = 'Current password should not be empty.';
|
||||||
|
@ -158,7 +172,6 @@ class UserController extends Controller
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($input['current_password'] != null && $this->validateUser($user->id, $input['current_password']) == false) {
|
if ($input['current_password'] != null && $this->validateUser($user->id, $input['current_password']) == false) {
|
||||||
//$flash_message = 'Password does not match the current password.';
|
//$flash_message = 'Password does not match the current password.';
|
||||||
$errors->add('your_custom_error', 'Password does not match the current password.');
|
$errors->add('your_custom_error', 'Password does not match the current password.');
|
||||||
|
@ -166,8 +179,6 @@ class UserController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//$input = $request->only(['login', 'email', 'password']); //Retreive the name, email and password fields
|
//$input = $request->only(['login', 'email', 'password']); //Retreive the name, email and password fields
|
||||||
if ($valid == true) {
|
if ($valid == true) {
|
||||||
$user->login = $input['login'];
|
$user->login = $input['login'];
|
||||||
|
@ -175,7 +186,7 @@ class UserController extends Controller
|
||||||
if ($input['password']) {
|
if ($input['password']) {
|
||||||
$user->password = Hash::make($input['password']);
|
$user->password = Hash::make($input['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$roles = $request['roles']; //Retreive all roles
|
$roles = $request['roles']; //Retreive all roles
|
||||||
|
@ -194,8 +205,8 @@ class UserController extends Controller
|
||||||
// ->with('flash_message', 'User successfully edited.');
|
// ->with('flash_message', 'User successfully edited.');
|
||||||
}
|
}
|
||||||
return back()
|
return back()
|
||||||
->withInput($input)
|
->withInput($input)
|
||||||
->withErrors($errors);
|
->withErrors($errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
36
app/Mail/NewUser.php
Normal file
36
app/Mail/NewUser.php
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class NewUser extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $details;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($details)
|
||||||
|
{
|
||||||
|
$this->details = $details;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the message.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->subject('Mail from www.tethys.at')
|
||||||
|
->view('emails.newUserEmail');
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ return [
|
||||||
|
|
||||||
'workspacePath' => storage_path() . DIRECTORY_SEPARATOR . "workspace",
|
'workspacePath' => storage_path() . DIRECTORY_SEPARATOR . "workspace",
|
||||||
|
|
||||||
'name' => env('APP_NAME', 'App'),
|
'name' => env('APP_NAME', 'Tethys'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
@ -54,7 +54,10 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'from' => ['address' => env('MAIL_FROM', null), 'name' => 'Hasan Doha'],
|
'from' => [
|
||||||
|
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||||
|
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -67,7 +70,7 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'encryption' => 'tls',
|
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -95,6 +98,8 @@ return [
|
||||||
|
|
||||||
'password' => env('MAIL_PASSWORD'),
|
'password' => env('MAIL_PASSWORD'),
|
||||||
|
|
||||||
|
'mailadmin' => env('MAIL_ADMIN', 'hello@example.com'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Sendmail System Path
|
| Sendmail System Path
|
||||||
|
@ -106,19 +111,48 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'sendmail' => '/usr/sbin/sendmail -bs',
|
// 'sendmail' => '/usr/sbin/sendmail -bs',
|
||||||
|
|
||||||
|
'sendmail' => 'sendmail -bs',
|
||||||
|
|
||||||
/*
|
'stream' => [
|
||||||
|
'ssl' => [
|
||||||
|
'allow_self_signed' => true,
|
||||||
|
'verify_peer' => false,
|
||||||
|
'verify_peer_name' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Mail "Pretend"
|
| Markdown Mail Settings
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| When this option is enabled, e-mail will not actually be sent over the
|
| If you are using Markdown based email rendering, you may configure your
|
||||||
| web and will instead be written to your application's logs files so
|
| theme and component paths here, allowing you to customize the design
|
||||||
| you may inspect the message. This is great for local development.
|
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'pretend' => false,
|
'markdown' => [
|
||||||
|
'theme' => 'default',
|
||||||
|
|
||||||
|
'paths' => [
|
||||||
|
resource_path('views/vendor/mail'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Log Channel
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| If you are using the "log" driver, you may specify the logging channel
|
||||||
|
| if you prefer to keep mail messages separate from other log entries
|
||||||
|
| for simpler reading. Otherwise, the default channel will be used.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'log_channel' => env('MAIL_LOG_CHANNEL'),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
19
resources/views/emails/newUserEmail.blade.php
Normal file
19
resources/views/emails/newUserEmail.blade.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ app()->getLocale() }}">
|
||||||
|
<head>
|
||||||
|
<title>www.tethys.at"</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>{{ $details['title'] }}</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Dear {{$details['admin_name']}},
|
||||||
|
</p>
|
||||||
|
|
||||||
|
a new user with email {{ $details['email'] }} has been registered to your site.
|
||||||
|
|
||||||
|
Thanks,
|
||||||
|
{{ config('app.name') }}
|
||||||
|
<p>Thank you</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user