Merge branch 'develop' into trunk
This commit is contained in:
commit
fab9bdb124
8 changed files with 120 additions and 1 deletions
|
|
@ -3,10 +3,18 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserController extends CrudController
|
||||
{
|
||||
|
||||
/** @var User */
|
||||
protected static $modelClass = User::class;
|
||||
|
||||
public function storedModel(Model &$model)
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$model = $model;
|
||||
$model->sendMailConfirm();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
app/Jobs/SendUserCreatedEmail.php
Normal file
44
app/Jobs/SendUserCreatedEmail.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Mail\UserCreatedMail;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendUserCreatedEmail implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
|
||||
/** @var User */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user->withoutRelations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Mail::to(['email' => $this->user->email])
|
||||
->send(new UserCreatedMail($this->user));
|
||||
Log::debug(sprintf('Sent %s to %s', UserCreatedMail::class, $this->user->email));
|
||||
}
|
||||
}
|
||||
37
app/Mail/UserCreatedMail.php
Normal file
37
app/Mail/UserCreatedMail.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
||||
class UserCreatedMail extends Mailable
|
||||
{
|
||||
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->subject(sprintf('%s : Votre compte a été crée', config('app.name')))
|
||||
->view('emails.mail-created')
|
||||
->text('emails.mail-created-plain')
|
||||
->with('user', $this->user)
|
||||
->with('pwd', $this->user->tmpPass);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use App\Enums\CrudAction;
|
||||
use App\Enums\CrudType;
|
||||
use App\Enums\Role;
|
||||
use App\Jobs\SendUserCreatedEmail;
|
||||
use App\Traits\IsCrudModel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
|
@ -30,6 +31,9 @@ class User extends Authenticatable
|
|||
|
||||
protected $crudValueColumn = 'id';
|
||||
|
||||
// stores unhashed pwd
|
||||
public $tmpPass = null;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
|
@ -144,6 +148,7 @@ class User extends Authenticatable
|
|||
static::creating(function (User $user) {
|
||||
if (\is_null($user->password)) {
|
||||
$user->password = Str::random(10);
|
||||
$user->tmpPass = $user->password;
|
||||
}
|
||||
if (Hash::needsRehash($user->password)) {
|
||||
$user->password = Hash::make($user->password);
|
||||
|
|
@ -175,4 +180,9 @@ class User extends Authenticatable
|
|||
{
|
||||
return $this->belongsToMany(Project::class);
|
||||
}
|
||||
|
||||
public function sendMailConfirm()
|
||||
{
|
||||
dispatch(new SendUserCreatedEmail($this));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
resources/views/emails/mail-created-plain.blade.php
Normal file
4
resources/views/emails/mail-created-plain.blade.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Bonjour {{ $user->name }},
|
||||
Votre compte {{ config('app.name') }} vient d'être créé. Votre identifiant est votre email.
|
||||
Votre mot de passe est le suivant: {{$pwd }}
|
||||
Merci d'enregistrer celui-ci dans un gestionnaire de mot de passe et de supprimer cet email au plus vite.
|
||||
13
resources/views/emails/mail-created.blade.php
Normal file
13
resources/views/emails/mail-created.blade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>{{ config('app.name') }}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<p class="corps_greet">Bonjour <span class="identity">{{ $user->name }}</span>,</p>
|
||||
<p>Votre compte <span class="underline">{{ config('app.name') }}</span> vient d'être créé. Votre identifiant est votre email.</p>
|
||||
<p>Votre mot de passe est le suivant : {{$pwd }}</p>
|
||||
<p><b>Merci d'enregistrer celui-ci dans un gestionnaire de mot de passe et de supprimer cet email au plus vite.</b></p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
@include('modules.error-messages')
|
||||
@php
|
||||
$userPr = Auth::user()->projects;
|
||||
$userPr = Auth::user()->projects ?? collect([]);
|
||||
@endphp
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('content')
|
||||
@php
|
||||
$userPr = Auth::user()->projects ?? collect([]);
|
||||
@endphp
|
||||
<div class="container container-xxl">
|
||||
<h2>
|
||||
Gestion des tickets @if(request()->status) (Archivés) @endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue