Skip to content

Commit

Permalink
Merge pull request #17 from naaando/add-laravel-pulse
Browse files Browse the repository at this point in the history
Add laravel pulse
  • Loading branch information
naaando authored Dec 15, 2023
2 parents fc401f1 + 11c61d4 commit fb2a460
Show file tree
Hide file tree
Showing 64 changed files with 5,043 additions and 558 deletions.
28 changes: 28 additions & 0 deletions pets-api/app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;

class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}

if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}

return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}
}
20 changes: 20 additions & 0 deletions pets-api/app/Livewire/Actions/Logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Livewire\Actions;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class Logout
{
/**
* Log the current user out of the application.
*/
public function __invoke(): void
{
Auth::guard('web')->logout();

Session::invalidate();
Session::regenerateToken();
}
}
72 changes: 72 additions & 0 deletions pets-api/app/Livewire/Forms/LoginForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Livewire\Forms;

use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Validate;
use Livewire\Form;

class LoginForm extends Form
{
#[Validate('required|string|email')]
public string $email = '';

#[Validate('required|string')]
public string $password = '';

#[Validate('boolean')]
public bool $remember = false;

/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function authenticate(): void
{
$this->ensureIsNotRateLimited();

if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) {
RateLimiter::hit($this->throttleKey());

throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}

RateLimiter::clear($this->throttleKey());
}

/**
* Ensure the authentication request is not rate limited.
*/
protected function ensureIsNotRateLimited(): void
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}

event(new Lockout(request()));

$seconds = RateLimiter::availableIn($this->throttleKey());

throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}

/**
* Get the authentication rate limiting throttle key.
*/
protected function throttleKey(): string
{
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
}
}
4 changes: 4 additions & 0 deletions pets-api/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot(): void
{
Gate::define('viewPulse', function (User $user) {
return $user->is_admin;
});

Gate::define('save-pet', function (User $user, Pet|null $pet = null) {
if ($pet === null) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion pets-api/app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/home';
public const HOME = '/dashboard';

/**
* Define your route model bindings, pattern filters, and other route configuration.
Expand Down
28 changes: 28 additions & 0 deletions pets-api/app/Providers/VoltServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Livewire\Volt\Volt;

class VoltServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
Volt::mount([
resource_path('views/livewire'),
resource_path('views/pages'),
]);
}
}
17 changes: 17 additions & 0 deletions pets-api/app/View/Components/AppLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;

class AppLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.app');
}
}
17 changes: 17 additions & 0 deletions pets-api/app/View/Components/GuestLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;

class GuestLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.guest');
}
}
9 changes: 6 additions & 3 deletions pets-api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/octane": "^2.0",
"laravel/pulse": "^v1.0.0-beta5",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"league/flysystem-aws-s3-v3": "^3.0",
"livewire/livewire": "^3.0",
"livewire/volt": "^1.0",
"sentry/sentry-laravel": "^3.8",
"spatie/laravel-image-optimizer": "^1.7",
"spiral/roadrunner-cli": "^2.5",
Expand All @@ -21,16 +24,16 @@
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.13",
"fakerphp/faker": "^1.9.1",
"laravel/breeze": "^1.26",
"laravel/pint": "^1.13",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.0",
"pestphp/pest": "^2.8",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-faker": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"pestphp/pest-plugin-watch": "^2.0",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
Expand Down Expand Up @@ -74,7 +77,7 @@
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"minimum-stability": "beta",
"prefer-stable": true,
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
Expand Down
Loading

0 comments on commit fb2a460

Please sign in to comment.