Merge pull request 'Add password mail' (#13) from feature/task-fixes into develop

Reviewed-on: #13
This commit is contained in:
ksenia_nevaeva 2024-06-25 21:40:05 +04:00
commit ac5d318cef
6 changed files with 79 additions and 2 deletions

View File

@ -29,7 +29,7 @@ class StudentPostRequest extends FormRequest
'middle_name' => 'required|max:255',
'birthday' => 'required|date',
'grade_id' => 'required|exists:grades,id',
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->route('student')?->user->id)],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->route('student')?->user->id), 'regex:/^(([^<>()\[\]\\.,;:\s@”]+(\.[^<>()\[\]\\.,;:\s@”]+)*)|(“.+”))@((\[[09]{1,3}\.[09]{1,3}\.[09]{1,3}\.[09]{1,3}])|(([a-zA-Z\-09]+\.)+[a-zA-Z]{2,}))$/'],
'password' => 'required|max:255',
];
}

View File

@ -28,7 +28,7 @@ class TeacherPostRequest extends FormRequest
'last_name' => 'required|max:255',
'middle_name' => 'required|max:255',
'birthday' => 'required|date',
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->route('teacher')?->user->id)],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->route('teacher')?->user->id), 'regex:/^(([^<>()\[\]\\.,;:\s@”]+(\.[^<>()\[\]\\.,;:\s@”]+)*)|(“.+”))@((\[[09]{1,3}\.[09]{1,3}\.[09]{1,3}\.[09]{1,3}])|(([a-zA-Z\-09]+\.)+[a-zA-Z]{2,}))$/'],
'password' => 'required|max:255',
];
}

52
app/Mail/UserCreated.php Normal file
View File

@ -0,0 +1,52 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class UserCreated extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(public string $password)
{
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Создана учетная запись',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'mails.user_created',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}

View File

@ -3,11 +3,15 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Observers\UserObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
#[ObservedBy(UserObserver::class)]
class User extends Authenticatable
{
use HasFactory, Notifiable;

View File

@ -0,0 +1,18 @@
<?php
namespace App\Observers;
use App\Mail\UserCreated;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
class UserObserver
{
/**
* Handle the User "created" event.
*/
public function created(User $user): void
{
Mail::to($user)->send(new UserCreated(request()->all()['password']));
}
}

View File

@ -0,0 +1,3 @@
<div>
Ваш пароль для входа на {{ url('/') }}: {{ $password }}
</div>