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 2e57c4d commit 862f3c4
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 121 deletions.
6 changes: 2 additions & 4 deletions app/Http/Controllers/Auth/NewPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ function ($user) use ($request) {
);

if ($status !== Password::PASSWORD_RESET) {
throw ValidationException::withMessages([
'email' => [__($status)],
]);
return redirect()->back()->with('error', __($status));
}

return redirect()->route('login')->with('status', __($status));
return redirect()->route('auth.login')->with('success', __($status));
}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/Auth/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public function store(Request $request): RedirectResponse
$request->only('email')
);

return back()->with('status', [
'success' => $status === Password::RESET_LINK_SENT,
'message' => __($status),
]);
$successOrError = $status === Password::RESET_LINK_SENT
? 'success'
: 'error';

return redirect()->back()->with($successOrError, __($status));
}
}
23 changes: 23 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function share(Request $request): array
[
'appName' => config('app.name'),
'auth' => $this->getCurrentUser($request->user()),
'flash' => fn () => $this->flash($request),
]
);
}
Expand All @@ -40,4 +41,26 @@ protected function getCurrentUser(?User $user): ?UserResource
? UserResource::make($user)
: null;
}

protected function flash(Request $request): ?array
{
if (! $request->hasSession()) {
return null;
}

$type = match (true) {
$request->session()->has('error') => 'error',
$request->session()->has('success') => 'success',
default => null,
};

if ($type === null) {
return null;
}

return [
'success' => $type === 'success',
'message' => $request->session()->get($type),
];
}
}
6 changes: 0 additions & 6 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Http\Resources\IssueResource;
use App\Http\Resources\MapPointResource;
use App\Notifications\User\ResetPasswordNotification as UserResetPasswordNotification;
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasAvatar;
use Filament\Models\Contracts\HasName;
Expand Down Expand Up @@ -160,11 +159,6 @@ private static function getAddress($fields)
return null;
}

public function sendPasswordResetNotification($token)
{
$this->notify(new UserResetPasswordNotification($token));
}

public function issues(): HasMany
{
return $this->hasMany(Issue::class);
Expand Down
9 changes: 9 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace App\Providers;

// use Illuminate\Support\Facades\Gate;

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

Expand All @@ -27,5 +29,12 @@ public function boot(): void
->numbers()
->symbols();
});

ResetPassword::$createUrlCallback = function ($notifiable, $token) {
return route('auth.password.reset', [
'token' => $token,
'email' => $notifiable->getEmailForPasswordReset(),
]);
};
}
}
2 changes: 0 additions & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\RouteServiceProvider::class,
Spatie\Permission\PermissionServiceProvider::class,

])->toArray(),

/*
Expand All @@ -188,7 +187,6 @@

'aliases' => Facade::defaultAliases()->merge([
// 'Example' => App\Facades\Example::class,
'ReCaptcha' => Biscolab\ReCaptcha\Facades\ReCaptcha::class,
])->toArray(),

];

This file was deleted.

This file was deleted.

15 changes: 11 additions & 4 deletions resources/js/Components/Dashboard/ChangePasswordForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
required
/>
</div>

<Alert v-if="message" type="success" :message="message" />
</div>

<template #footer>
Expand All @@ -42,23 +44,28 @@
</template>

<script setup>
import { useForm, usePage } from '@inertiajs/vue3';
import { ref } from 'vue';
import { useForm } from '@inertiajs/vue3';
import route from '@/Helpers/useRoute';
import Alert from '@/Components/Alert.vue';
import Button from '@/Components/Button.vue';
import Panel from '@/Components/Panel.vue';
import Input from '@/Components/Form/Input.vue';
const page = usePage();
const form = useForm({
current_password: null,
password: null,
password_confirmation: null,
});
const message = ref(null);
const submit = () => {
form.post(route('front.account.password'), {
onSuccess: () => form.reset(),
onSuccess: (page) => {
form.reset();
message.value = page.props.flash.message;
},
});
};
</script>
12 changes: 11 additions & 1 deletion resources/js/Components/Dashboard/UpdateProfileForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
:errors="[form.errors.phone]"
/>
</div>

<Alert v-if="message" type="success" :message="message" />
</div>

<template #footer>
Expand All @@ -50,8 +52,10 @@
</template>

<script setup>
import { ref } from 'vue';
import { useForm, usePage } from '@inertiajs/vue3';
import route from '@/Helpers/useRoute';
import Alert from '@/Components/Alert.vue';
import Button from '@/Components/Button.vue';
import Panel from '@/Components/Panel.vue';
import Input from '@/Components/Form/Input.vue';
Expand All @@ -65,7 +69,13 @@
phone: page.props.auth.phone,
});
const message = ref(null);
const submit = () => {
form.post(route('front.account.profile'));
form.post(route('front.account.profile'), {
onSuccess: (page) => {
message.value = page.props.flash.message;
},
});
};
</script>
7 changes: 6 additions & 1 deletion resources/js/Components/Form/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
:placeholder="placeholder"
:required="required"
:disabled="disabled"
:readonly="readonly"
/>
</template>
</FormField>
</template>

<script setup>
import { computed, ref } from 'vue';
import { computed } from 'vue';
import { CheckIcon } from '@heroicons/vue/16/solid';
import InputText from 'primevue/inputtext';
import FormField from '@/Components/Form/Field.vue';
Expand All @@ -40,6 +41,10 @@
type: Boolean,
default: false,
},
readonly: {
type: Boolean,
default: false,
},
label: {
type: String,
default: null,
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Layouts/AuthLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<div class="mt-10">
<Alert
v-if="$page.props.status"
:type="$page.props.status.success ? 'success' : 'error'"
:message="$page.props.status.message"
v-if="$page.props.flash"
:type="$page.props.flash.success ? 'success' : 'error'"
:message="$page.props.flash.message"
class="mb-6"
/>

Expand All @@ -29,7 +29,7 @@
<div
class="flex flex-col items-center justify-center flex-1 px-4 py-12 sm:px-6 lg:px-20 xl:px-24 bg-primary-700"
>
<div class="prose text-white prose-headings:text-white">
<div class="prose-sm prose text-white sm:prose-base prose-headings:text-white">
<slot name="backdrop" />
</div>
</div>
Expand Down
11 changes: 2 additions & 9 deletions resources/js/Pages/Auth/ForgotPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ul>
</template>

<form class="grid gap-6" @submit.prevent="reset">
<form class="grid gap-6" @submit.prevent="submit">
<Input
name="email"
type="email"
Expand Down Expand Up @@ -49,18 +49,11 @@
import Button from '@/Components/Button.vue';
import Input from '@/Components/Form/Input.vue';
defineProps({
canResetPassword: {
type: Boolean,
default: false,
},
});
const form = useForm({
email: null,
});
const reset = () => {
const submit = () => {
form.post(route('auth.password.request'), {
onSuccess: () => form.reset(),
});
Expand Down
8 changes: 2 additions & 6 deletions resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ul>
</template>

<form class="grid gap-6" @submit.prevent="login">
<form class="grid gap-6" @submit.prevent="submit">
<Input
name="email"
type="email"
Expand Down Expand Up @@ -73,10 +73,6 @@
type: Boolean,
default: false,
},
status: {
type: String,
default: null,
},
});
const form = useForm({
Expand All @@ -85,7 +81,7 @@
remember: false,
});
const login = () => {
const submit = () => {
form.post(route('auth.login'), {
onFinish: () => form.reset('password'),
replace: true,
Expand Down
Loading

0 comments on commit 862f3c4

Please sign in to comment.