Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Sep 11, 2024
1 parent 862f3c4 commit 1d3e769
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Illuminate\Http\Response;

class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*/
public function __invoke(Request $request): RedirectResponse|Response
public function __invoke(Request $request): JsonResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended();
return response()->json(['message' => 'already-verified'], Response::HTTP_BAD_REQUEST);
}

return Inertia::render('Auth/VerifyEmail', [
'status' => session('status'),
]);
$request->user()->sendEmailVerificationNotification();

// $request->user()->sendEmailVerificationNotification();
return response()->json(['message' => 'verification-link-sent']);
}
}
11 changes: 5 additions & 6 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

declare(strict_types=1);

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;
Expand All @@ -15,17 +18,13 @@ class VerifyEmailController extends Controller
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(
config('app.frontend_url').'/dashboard?verified=1'
);
return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1');
}

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

return redirect()->intended(
config('app.frontend_url').'/dashboard?verified=1'
);
return redirect()->intended(RouteServiceProvider::getDashboardUrl() . '?verified=1');
}
}
2 changes: 2 additions & 0 deletions app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function toArray(Request $request): array
'phone' => $this->phone,
'avatar' => $this->getFilamentAvatarUrl(),
'created_at' => $this->created_at->isoFormat('Do MMMM YYYY'),
'is_unverified' => ! $this->hasVerifiedEmail(),
'show_verified_message' => $request->boolean('verified'),
];
}
}
5 changes: 2 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Filament\Models\Contracts\HasAvatar;
use Filament\Models\Contracts\HasName;
use Filament\Panel;
use Illuminate\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand All @@ -25,10 +25,9 @@
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements FilamentUser, HasAvatar, HasName, HasMedia, CanResetPassword
class User extends Authenticatable implements FilamentUser, HasAvatar, HasName, HasMedia, CanResetPassword, MustVerifyEmail
{
use InteractsWithMedia;
use MustVerifyEmail;
use HasFactory;
use Notifiable;
use HasRoles;
Expand Down
13 changes: 13 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// use Illuminate\Support\Facades\Gate;

use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\URL;
use Illuminate\Validation\Rules\Password;

class AuthServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -36,5 +38,16 @@ public function boot(): void
'email' => $notifiable->getEmailForPasswordReset(),
]);
};

VerifyEmail::$createUrlCallback = function ($notifiable) {
return URL::temporarySignedRoute(
'auth.verification.verify',
now()->addMinutes(config('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
};
}
}
3 changes: 3 additions & 0 deletions lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@

"auth.reset_password": "Resetează parola",

"auth.verify.unverified_notice": "Contul tău nu a fost încă verificat. Te rugăm să verifici emailul pentru a activa contul.",
"auth.verify.resend": "Trimite email de verificare",

"add_point.title": "Adaugă un punct pe hartă",
"add_point.yes": "Da",
"add_point.no": "Nu",
Expand Down
6 changes: 4 additions & 2 deletions resources/js/Components/Alert.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<template>
<div class="p-4 rounded-md bg-green-50" :class="color">
<div class="flex gap-3">
<div class="flex items-center gap-3 text-sm">
<Component :is="icon" class="w-5 h-5 shrink-0" :class="iconColor" aria-hidden="true" />

<p class="text-sm font-medium" v-text="message" />
<p v-text="message" />

<slot name="action" />
</div>
</div>
</template>
Expand Down
38 changes: 38 additions & 0 deletions resources/js/Components/EmailVerifiedAlert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<Alert v-if="$page.props.auth.is_unverified" type="warning" :message="$t('auth.verify.unverified_notice')">
<template #action>
<button
type="button"
@click="submit"
class="font-semibold text-yellow-700 underline hover:text-yellow-600"
v-text="$t('auth.verify.resend')"
/>
</template>
</Alert>

<Alert v-else-if="$page.props.auth.show_verified_message" type="success" message="This is an error message." />
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';
import route from '@/Helpers/useRoute';
import Alert from '@/Components/Alert.vue';
const success = ref(false);
const message = ref(null);
const submit = () => {
axios
.post(route('auth.verification.send'))
.then((response) => {
console.log(response);
success.value = true;
message.value = response.data.message;
})
.catch(({ response }) => {
success.value = false;
message.value = response.data.message;
});
};
</script>
12 changes: 11 additions & 1 deletion resources/js/Layouts/DefaultLayout.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div class="flex flex-col h-screen overflow-hidden">
<Header class="shrink-0" />
<EmailVerifiedAlert v-if="$page.props.auth?.is_unverified || $page.props.auth?.show_verified_message" />

<Header class="shrink-0" :dashboard="dashboard" />

<div class="relative flex-1">
<slot />
Expand All @@ -9,5 +11,13 @@
</template>

<script setup>
import { computed } from 'vue';
import route from '@/Helpers/useRoute';
import EmailVerifiedAlert from '@/Components/EmailVerifiedAlert.vue';
import Header from '@/Components/Navigation/Header.vue';
import { usePage } from '@inertiajs/vue3';
const page = usePage();
const dashboard = computed(() => page.url && route().current('front.account.*'));
</script>
2 changes: 0 additions & 2 deletions resources/js/Layouts/MapLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
<script setup>
import L from 'leaflet';
import DefaultLayout from '@/Layouts/DefaultLayout.vue';
import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue';
import { XMarkIcon } from '@heroicons/vue/24/outline';
Expand Down
Loading

0 comments on commit 1d3e769

Please sign in to comment.