Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
#13 - invite users to admin panel (#70)
Browse files Browse the repository at this point in the history
* #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 <[email protected]>

* #13 - changes after review

* #13 - fix blade newline

* #13 - cs:fix after merge

* #13 - Apply suggestions from code review

Co-authored-by: Kamil Piech <[email protected]>

* #13 - fix after apply suggestions

* #13 - fix after review

Co-authored-by: Kamil Piech <[email protected]>
  • Loading branch information
Majkulnn and kamilpiech97 authored May 6, 2022
1 parent dd6b610 commit 30fa3ed
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 6 deletions.
9 changes: 9 additions & 0 deletions resources/views/emails/invitation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@component('mail::message')
<h3>Hello {{$receiver}}</h3>
<p>You have received an email from: {{ $sender->name }}</p>
<p>Email: {{ $sender->email }}</p>
<p>You are invited to meetup page</p>
@component('mail::button', ['url' => route("register", ["email" => $receiver])])
<p>Click here to register</p>
@endcomponent
@endcomponent
48 changes: 48 additions & 0 deletions resources/views/invitation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@extends('layouts.app')

@section('content')
<div class="container md:w-[800px] mx-auto">
@auth
<form action="{{ route('invitation.store') }}" method="post" enctype="multipart/form-data"
class="bg-white p-6 mt-20 rounded-20 shadow-xl">
@csrf
<div>
@if(session()->has('message'))
<div>
{{ session()->get('message') }}
</div>
@endif
<div>
<h3 class="text-xl leading-6 font-medium text-gray-900">
Invite User
</h3>
</div>
<div class="mt-6 flex flex-col gap-7">
<div>
<label for="email" class="block font-medium text-gray-700">
Email
</label>
<div class="mt-1">
<input type="email" name="email" id="email" placeholder="Email" value="{{ old('email') }}"
class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" />
<x-input-error for="email" />
</div>
</div>
</div>
</div>
<div class="pt-6">
<div class="flex justify-end">
<a href="{{ route("meetups") }}"
class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancel
</a>
<button type="submit"
class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Save
</button>
</div>
</div>
</form>
@endauth
</div>
@endsection
Empty file modified resources/views/user/login.blade.php
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion resources/views/user/logout.blade.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
@section('content')
<div style="text-align: center">
<h1>You have been successfully loged out</h1>
<a href="{{ route('home') }}"><button type="button">Home Page</button></a>
<a href="{{ route('meetups') }}"><button type="button">Home Page</button></a>
</div>
@endsection
4 changes: 2 additions & 2 deletions resources/views/user/register.blade.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
</h2>
</div>
<form action="{{ route('register') }}" class="space-y-6 mt-12" action="#" method="POST">
<form action="{{ route('register') }}" class="space-y-6 mt-12" method="POST">
@csrf
<div>
<label for="name" class="block text-sm font-medium text-gray-700">
Expand Down Expand Up @@ -51,7 +51,7 @@ class="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md
Email address
</label>
<div class="mt-1">
<input id="email" name="email" type="email" required
<input id="email" name="email" type="email" required value="{{ $email }}"
class="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" />
<x-input-error for="email" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Auth/EmailVerificationController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/Http/Controllers/InvitationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Blumilk\Meetup\Core\Http\Controllers;

use Blumilk\Meetup\Core\Http\Requests\Invitations\StoreInvitationRequest;
use Blumilk\Meetup\Core\Models\User;
use Blumilk\Meetup\Core\Services\InvitationsService;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;

class InvitationController extends Controller
{
public function create(): View
{
return view("invitation");
}

public function store(StoreInvitationRequest $request, InvitationsService $service, Guard $auth): RedirectResponse
{
if (User::query()->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");
}
}
17 changes: 17 additions & 0 deletions src/Http/Requests/Invitations/StoreInvitationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Blumilk\Meetup\Core\Http\Requests\Invitations;

use Illuminate\Foundation\Http\FormRequest;

class StoreInvitationRequest extends FormRequest
{
public function rules(): array
{
return [
"email" => ["required", "email"],
];
}
}
9 changes: 8 additions & 1 deletion src/Http/Routing/WebRouting.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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");
});
Expand Down
38 changes: 38 additions & 0 deletions src/Notifications/InvitationEmailNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Blumilk\Meetup\Core\Notifications;

use Blumilk\Meetup\Core\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class InvitationEmailNotification extends Notification
{
use Queueable;

public function __construct(
protected User $sender,
protected string $email,
) {}

public function via(): array
{
return ["mail"];
}

public function toMail(): MailMessage
{
return (new MailMessage())
->replyTo($this->email)
->markdown(
"emails.invitation",
[
"receiver" => $this->email,
"sender" => $this->sender,
],
);
}
}
Empty file modified src/Providers/EventServiceProvider.php
100644 → 100755
Empty file.
16 changes: 16 additions & 0 deletions src/Services/InvitationsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Blumilk\Meetup\Core\Services;

use Blumilk\Meetup\Core\Models\User;
use Blumilk\Meetup\Core\Notifications\InvitationEmailNotification;

class InvitationsService
{
public function sendInvitation(User $senderUser, string $email): void
{
$senderUser->notify(new InvitationEmailNotification($senderUser, $email));
}
}

0 comments on commit 30fa3ed

Please sign in to comment.