From 30fa3edc83dcc66a71f6878d4ce03efc58a42492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ga=C5=82=C4=99zyka?= <72552648+Majkulnn@users.noreply.github.com> Date: Fri, 6 May 2022 13:54:48 +0200 Subject: [PATCH] #13 - invite users to admin panel (#70) * #13 - create basic view, controller, service, routing * #13 - create event, modify previous commit, fix * #13 - fix * #13 - Apply suggestions from code review Co-authored-by: Kamil Piech * #13 - changes after review * #13 - fix blade newline * #13 - cs:fix after merge * #13 - Apply suggestions from code review Co-authored-by: Kamil Piech * #13 - fix after apply suggestions * #13 - fix after review Co-authored-by: Kamil Piech --- resources/views/emails/invitation.blade.php | 9 ++++ resources/views/invitation.blade.php | 48 +++++++++++++++++++ resources/views/user/login.blade.php | 0 resources/views/user/logout.blade.php | 2 +- resources/views/user/register.blade.php | 4 +- .../Auth/EmailVerificationController.php | 2 +- .../Controllers/Auth/RegisterController.php | 6 ++- src/Http/Controllers/InvitationController.php | 31 ++++++++++++ .../Invitations/StoreInvitationRequest.php | 17 +++++++ src/Http/Routing/WebRouting.php | 9 +++- .../InvitationEmailNotification.php | 38 +++++++++++++++ src/Providers/EventServiceProvider.php | 0 src/Services/InvitationsService.php | 16 +++++++ 13 files changed, 176 insertions(+), 6 deletions(-) create mode 100755 resources/views/emails/invitation.blade.php create mode 100755 resources/views/invitation.blade.php mode change 100644 => 100755 resources/views/user/login.blade.php mode change 100644 => 100755 resources/views/user/logout.blade.php mode change 100644 => 100755 resources/views/user/register.blade.php mode change 100644 => 100755 src/Http/Controllers/Auth/EmailVerificationController.php create mode 100755 src/Http/Controllers/InvitationController.php create mode 100755 src/Http/Requests/Invitations/StoreInvitationRequest.php mode change 100644 => 100755 src/Http/Routing/WebRouting.php create mode 100755 src/Notifications/InvitationEmailNotification.php mode change 100644 => 100755 src/Providers/EventServiceProvider.php create mode 100755 src/Services/InvitationsService.php diff --git a/resources/views/emails/invitation.blade.php b/resources/views/emails/invitation.blade.php new file mode 100755 index 00000000..859e155e --- /dev/null +++ b/resources/views/emails/invitation.blade.php @@ -0,0 +1,9 @@ +@component('mail::message') +

Hello {{$receiver}}

+

You have received an email from: {{ $sender->name }}

+

Email: {{ $sender->email }}

+

You are invited to meetup page

+ @component('mail::button', ['url' => route("register", ["email" => $receiver])]) +

Click here to register

+ @endcomponent +@endcomponent diff --git a/resources/views/invitation.blade.php b/resources/views/invitation.blade.php new file mode 100755 index 00000000..ea9ddaa0 --- /dev/null +++ b/resources/views/invitation.blade.php @@ -0,0 +1,48 @@ +@extends('layouts.app') + +@section('content') +
+ @auth +
+ @csrf +
+ @if(session()->has('message')) +
+ {{ session()->get('message') }} +
+ @endif +
+

+ Invite User +

+
+
+
+ +
+ + +
+
+
+
+
+
+ + Cancel + + +
+
+
+ @endauth +
+@endsection diff --git a/resources/views/user/login.blade.php b/resources/views/user/login.blade.php old mode 100644 new mode 100755 diff --git a/resources/views/user/logout.blade.php b/resources/views/user/logout.blade.php old mode 100644 new mode 100755 index ae7c6e02..dbfafee5 --- a/resources/views/user/logout.blade.php +++ b/resources/views/user/logout.blade.php @@ -3,6 +3,6 @@ @section('content')

You have been successfully loged out

- +
@endsection diff --git a/resources/views/user/register.blade.php b/resources/views/user/register.blade.php old mode 100644 new mode 100755 index 22ab3e59..0b6e885f --- a/resources/views/user/register.blade.php +++ b/resources/views/user/register.blade.php @@ -23,7 +23,7 @@ class="absolute top-1/2 left-1/2 text-white text-6xl font-extrabold transform -t Sign up to your account -
+ @csrf
-
diff --git a/src/Http/Controllers/Auth/EmailVerificationController.php b/src/Http/Controllers/Auth/EmailVerificationController.php old mode 100644 new mode 100755 index 54a7be36..c589f485 --- a/src/Http/Controllers/Auth/EmailVerificationController.php +++ b/src/Http/Controllers/Auth/EmailVerificationController.php @@ -21,7 +21,7 @@ public function store(EmailVerificationRequest $request): RedirectResponse { $request->fulfill(); - return redirect()->route("home"); + return redirect()->route("meetups"); } public function notification(Request $request): RedirectResponse diff --git a/src/Http/Controllers/Auth/RegisterController.php b/src/Http/Controllers/Auth/RegisterController.php index 2efc09d8..1ba7a91a 100644 --- a/src/Http/Controllers/Auth/RegisterController.php +++ b/src/Http/Controllers/Auth/RegisterController.php @@ -14,7 +14,11 @@ class RegisterController extends Controller { public function create(): View { - return view("user.register"); + if (request()->has("email")) { + return view("user.register")->with("email", request()->get("email")); + } + + return view("user.register")->with("email", old("email")); } public function store(RegisterUserRequest $request): View diff --git a/src/Http/Controllers/InvitationController.php b/src/Http/Controllers/InvitationController.php new file mode 100755 index 00000000..123df70d --- /dev/null +++ b/src/Http/Controllers/InvitationController.php @@ -0,0 +1,31 @@ +where("email", $request->validated("email"))->exists()) { + return back()->with("message", "User with that email already existed"); + } + + $service->sendInvitation($auth->user(), $request->validated("email")); + + return back()->with("message", "We have sent invitation"); + } +} diff --git a/src/Http/Requests/Invitations/StoreInvitationRequest.php b/src/Http/Requests/Invitations/StoreInvitationRequest.php new file mode 100755 index 00000000..cf2dcf22 --- /dev/null +++ b/src/Http/Requests/Invitations/StoreInvitationRequest.php @@ -0,0 +1,17 @@ + ["required", "email"], + ]; + } +} diff --git a/src/Http/Routing/WebRouting.php b/src/Http/Routing/WebRouting.php old mode 100644 new mode 100755 index f492ac7d..df7c02b2 --- a/src/Http/Routing/WebRouting.php +++ b/src/Http/Routing/WebRouting.php @@ -4,11 +4,13 @@ namespace Blumilk\Meetup\Core\Http\Routing; +use Blumilk\Meetup\Core\Http\Controllers\Auth\EmailVerificationController; use Blumilk\Meetup\Core\Http\Controllers\Auth\LoginController; use Blumilk\Meetup\Core\Http\Controllers\Auth\PasswordResetController; use Blumilk\Meetup\Core\Http\Controllers\Auth\RegisterController; use Blumilk\Meetup\Core\Http\Controllers\Auth\SocialiteController; use Blumilk\Meetup\Core\Http\Controllers\ContactController; +use Blumilk\Meetup\Core\Http\Controllers\InvitationController; use Blumilk\Meetup\Core\Http\Controllers\MeetupController; use Blumilk\Meetup\Core\Http\Controllers\NewsletterSubscriberController; use Blumilk\Meetup\Core\Http\Controllers\OrganizationController; @@ -33,7 +35,7 @@ public function wire(): void $this->router->get("/auth/logout", "logout")->middleware("auth")->name("logout"); }); - $this->router->controller(PasswordResetController::class)->group(function (): void { + $this->router->controller(EmailVerificationController::class)->group(function (): void { $this->router->get("/email/verify", "create")->middleware("auth")->name("verification.notice"); $this->router->get("/email/verify/{id}/{hash}", "store")->middleware(["auth", "signed"])->name("verification.verify"); $this->router->post("/email/verification-notification", "notification")->middleware(["auth", "throttle:web"])->name("verification.send"); @@ -102,6 +104,11 @@ public function wire(): void $this->router->post("/newsletter/unsubscribe", "destroy")->name("newsletter.destroy"); }); + $this->router->controller(InvitationController::class)->group(function (): void { + $this->router->get("/invitation", "create")->middleware("auth")->name("invitation"); + $this->router->post("/invitation", "store")->name("invitation.store"); + }); + $this->router->controller(StaticController::class)->group(function (): void { $this->router->get("/static/{path}", "index")->where("path", ".*")->name("assets"); }); diff --git a/src/Notifications/InvitationEmailNotification.php b/src/Notifications/InvitationEmailNotification.php new file mode 100755 index 00000000..6dd73a84 --- /dev/null +++ b/src/Notifications/InvitationEmailNotification.php @@ -0,0 +1,38 @@ +replyTo($this->email) + ->markdown( + "emails.invitation", + [ + "receiver" => $this->email, + "sender" => $this->sender, + ], + ); + } +} diff --git a/src/Providers/EventServiceProvider.php b/src/Providers/EventServiceProvider.php old mode 100644 new mode 100755 diff --git a/src/Services/InvitationsService.php b/src/Services/InvitationsService.php new file mode 100755 index 00000000..625ef0cd --- /dev/null +++ b/src/Services/InvitationsService.php @@ -0,0 +1,16 @@ +notify(new InvitationEmailNotification($senderUser, $email)); + } +}