From 4882dedc8d790131e266e4523df0985bea0f3ffd Mon Sep 17 00:00:00 2001 From: anazaryan Date: Fri, 22 Nov 2024 16:31:28 +0400 Subject: [PATCH] verfiy emails --- .../Controllers/Auth/VerificationController.php | 38 +++++++++++- app/Http/Controllers/WorkerController.php | 2 +- app/Mail/ThankYouForRegistering.php | 61 ++++++++++++++++++++ app/Models/User.php | 3 +- app/Providers/AppServiceProvider.php | 15 ++++- public/images/emails/19.svg | 26 +++++++++ public/images/emails/20.svg | 24 ++++++++ public/images/emails/21.svg | 4 ++ public/images/emails/22.svg | 4 ++ public/images/emails/23.svg | 24 ++++++++ public/images/emails/24.svg | 3 + .../views/emails/send_already_registered.blade.php | 34 +++++++++++ resources/views/emails/send_verify.blade.php | 26 +++++++++ 13 files changed, 258 insertions(+), 6 deletions(-) create mode 100644 app/Mail/ThankYouForRegistering.php create mode 100644 public/images/emails/19.svg create mode 100644 public/images/emails/20.svg create mode 100644 public/images/emails/21.svg create mode 100644 public/images/emails/22.svg create mode 100644 public/images/emails/23.svg create mode 100644 public/images/emails/24.svg create mode 100644 resources/views/emails/send_already_registered.blade.php create mode 100644 resources/views/emails/send_verify.blade.php diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index 5e749af..91ee4b7 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -3,8 +3,14 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Mail\ThankYouForRegistering; +use App\Models\User; use App\Providers\RouteServiceProvider; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Auth\Events\Verified; use Illuminate\Foundation\Auth\VerifiesEmails; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Mail; class VerificationController extends Controller { @@ -19,8 +25,9 @@ class VerificationController extends Controller | */ - use VerifiesEmails; - + use VerifiesEmails{ + verify as public traitVerify; + } /** * Where to redirect users after verification. * @@ -35,8 +42,33 @@ class VerificationController extends Controller */ public function __construct() { - $this->middleware('auth'); + $this->middleware('auth')->only('show', 'resend'); $this->middleware('signed')->only('verify'); $this->middleware('throttle:6,1')->only('verify', 'resend'); } + + + public function verify(Request $request) + { + if (!auth()->check()) { + auth()->loginUsingId($request->route('id')); + } + + if ($request->route('id') != $request->user()->getKey()) { + throw new AuthorizationException; + } + + if ($request->user()->hasVerifiedEmail()) { + return redirect($this->redirectPath()); + } + + if ($request->user()->markEmailAsVerified()) { + event(new Verified($request->user())); + + Mail::to($request->user()->email)->send(new ThankYouForRegistering($request->user())); + } + + return redirect($this->redirectPath())->with('success', 'Вы успешно подтвердили свой адрес почты'); + } + } diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 5cf3292..574e34c 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -671,7 +671,7 @@ class WorkerController extends Controller 'telephone' => '1234567890', 'password' => Hash::make('password'), 'pubpassword' => base64_encode('password'), - 'email_verified_at' => Carbon::now(), +// 'email_verified_at' => Carbon::now(), 'is_worker' => 1, ]); diff --git a/app/Mail/ThankYouForRegistering.php b/app/Mail/ThankYouForRegistering.php new file mode 100644 index 0000000..d5bf7aa --- /dev/null +++ b/app/Mail/ThankYouForRegistering.php @@ -0,0 +1,61 @@ +user = $user; + } + + /** + * Get the message envelope. + * + * @return \Illuminate\Mail\Mailables\Envelope + */ + public function envelope() + { + return new Envelope( + subject: 'Благодарим за регистрацию на нашем сайте', + ); + } + + /** + * Get the message content definition. + * + * @return \Illuminate\Mail\Mailables\Content + */ + public function content() + { + return new Content( + view: 'emails.send_already_registered', + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments() + { + return []; + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 9bbd3ab..a03b46d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -10,7 +11,7 @@ use Illuminate\Notifications\Notifiable; use JsonException; use Laravel\Sanctum\HasApiTokens; -class User extends Authenticatable +class User extends Authenticatable implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ee8ca5b..ae3ba48 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,11 @@ namespace App\Providers; +use Carbon\Carbon; +use Illuminate\Auth\Notifications\VerifyEmail; +use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Facades\URL; class AppServiceProvider extends ServiceProvider { @@ -23,6 +27,15 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // + VerifyEmail::toMailUsing(function ($notifiable) { + $verifyUrl = URL::temporarySignedRoute( + 'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey(), 'hash' => sha1($notifiable->getEmailForVerification()),] + ); + + return (new MailMessage) + ->subject('Подтвердите ваш адрес электронной почты!') + ->view('emails.send_verify', ['url' => $verifyUrl]); + }); } + } diff --git a/public/images/emails/19.svg b/public/images/emails/19.svg new file mode 100644 index 0000000..00a1c06 --- /dev/null +++ b/public/images/emails/19.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/emails/20.svg b/public/images/emails/20.svg new file mode 100644 index 0000000..f531016 --- /dev/null +++ b/public/images/emails/20.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/emails/21.svg b/public/images/emails/21.svg new file mode 100644 index 0000000..43e7d53 --- /dev/null +++ b/public/images/emails/21.svg @@ -0,0 +1,4 @@ + + + + diff --git a/public/images/emails/22.svg b/public/images/emails/22.svg new file mode 100644 index 0000000..b5dfd42 --- /dev/null +++ b/public/images/emails/22.svg @@ -0,0 +1,4 @@ + + + + diff --git a/public/images/emails/23.svg b/public/images/emails/23.svg new file mode 100644 index 0000000..785a44f --- /dev/null +++ b/public/images/emails/23.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/emails/24.svg b/public/images/emails/24.svg new file mode 100644 index 0000000..00022b9 --- /dev/null +++ b/public/images/emails/24.svg @@ -0,0 +1,3 @@ + + + diff --git a/resources/views/emails/send_already_registered.blade.php b/resources/views/emails/send_already_registered.blade.php new file mode 100644 index 0000000..e18aa83 --- /dev/null +++ b/resources/views/emails/send_already_registered.blade.php @@ -0,0 +1,34 @@ + + + + + + BAIKALY + + + +
+ + Ваш аккаунт готов к работе, желаем удачи в поисках работы. + Также рекомендуем Вам подписаться на наш Телеграм канал и группу Вконтакте: +
+ + + Телеграм + + + + ВКонтакте + +
+
+
Это письмо отправлено автоматически. Пожалуйста, не отвечайте на него.
+ +
+ + +
+
© 2023 — RekaMore.su
+ + + diff --git a/resources/views/emails/send_verify.blade.php b/resources/views/emails/send_verify.blade.php new file mode 100644 index 0000000..a89c64e --- /dev/null +++ b/resources/views/emails/send_verify.blade.php @@ -0,0 +1,26 @@ + + + + + + BAIKALY + + + +
+ + Благодарим за регистрацию на нашем сайте. Пожалуйста, подтвердите регистрацию, перейдя по ссылке: + + {{ $url }} + +
+
Это письмо отправлено автоматически. Пожалуйста, не отвечайте на него.
+ +
+ + +
+
© 2023 — RekaMore.su
+ + + -- 1.7.10.4