]> _ Git - bastide-resah.git/commitdiff
wip #6888 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Apr 2024 13:33:02 +0000 (15:33 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Apr 2024 13:33:02 +0000 (15:33 +0200)
app/Http/Controllers/FluidbookController.php
app/Http/Controllers/ForgotPassword.php [new file with mode: 0644]
app/Http/Controllers/LandingController.php
app/Models/Client.php
app/Notifications/ResahNotification.php
routes/web.php

index d11a1513108f4663b7502ad423f1b3a1805f395e..adebb5e1ac3cff8a9a3f4f2250246afcec324e0c 100644 (file)
@@ -12,6 +12,8 @@ use Illuminate\Support\Facades\Validator;
 
 class FluidbookController extends Controller
 {
+    use ForgotPassword;
+
     protected function signin()
     {
         $validator = Validator::make(request()->all(), [
@@ -81,11 +83,6 @@ class FluidbookController extends Controller
         }
     }
 
-    protected function forgotpassword()
-    {
-        //
-    }
-
 
     public static function loadData()
     {
@@ -141,8 +138,6 @@ class FluidbookController extends Controller
         $order->total_ht = $total;
         $order->save();
 
-
-
         $user->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST_SENT, $order));
         User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST, $order));
 
diff --git a/app/Http/Controllers/ForgotPassword.php b/app/Http/Controllers/ForgotPassword.php
new file mode 100644 (file)
index 0000000..8b7631e
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Password;
+
+trait ForgotPassword
+{
+
+    protected function forgotPassword()
+    {
+        $status = Password::broker('clients')->sendResetLink(
+            ['email' => request('email')],
+        );
+
+        return $status === Password::RESET_LINK_SENT
+            ? response()->json(['status' => __($status)], 200)
+            : response()->json(['status' => __($status)], 400);
+    }
+
+    protected function resetPassword($email, $token)
+    {
+
+    }
+
+    protected function changePassword()
+    {
+
+    }
+
+    protected function guard()
+    {
+        return Auth::guard('clients');
+    }
+
+    protected function broker()
+    {
+        return Password::broker('clients');
+    }
+
+}
index 2efa16cc54ae287305573c909da18cae243bb342..461603daf09b5cc8ccecef330482c97626062305 100644 (file)
@@ -7,6 +7,8 @@ use Illuminate\Support\Facades\Auth;
 
 class LandingController extends Controller
 {
+  use ForgotPassword;
+
     public function catchall($path = '')
     {
         if (!$path) {
index d92e80018bd5e297d09fe6daa36c7f9cddea4236..bb48f240407a8a0a753cf1b6ef7837d8e0eb41d2 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Models;
 use App\Http\Controllers\Operations\Client\Fluidbook;
 use App\Http\Controllers\Operations\Client\Landing;
 use App\Notifications\ResahNotification;
+use Backpack\CRUD\app\Notifications\ResetPasswordNotification;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Models\CubistMagicAuthenticatable;
 use Illuminate\Notifications\Notifiable;
@@ -43,4 +44,9 @@ class Client extends CubistMagicAuthenticatable
         }
         return parent::onSaving();
     }
+
+    public function sendPasswordResetNotification($token)
+    {
+        $this->notify(new ResahNotification(ResahNotification::FORGOT_PASSWORD, ['token' => $token, 'email' => $this->email]));
+    }
 }
index a116ce610a1b4e6b10120129880a4d4e05a3b712..916f7e07ab749717d654bc7f269c7f7ea7c988ec 100644 (file)
@@ -70,6 +70,10 @@ class ResahNotification extends Notification
             $subject = 'Votre demande de devis sur Bastide-resah.fr';
             $html = 'Votre demande de devis est en cours de traitement (récapitulatif en pièce jointe).<br>Nous vous recontacterons dans les meilleurs délais.';
             //$file = storage_path('orders/' . $this->data->id . '.pdf');
+        } else if ($this->type === self::FORGOT_PASSWORD) {
+            $url = url('/landing/resetpassword/' . $this->data['email'] . '/' . $this->data['token']);
+            $subject = 'Réinitialisation de votre mot de passe';
+            $html = 'Vous recevez cet e-mail car nous avons reçu une demande de réinitialisation de mot de passe pour votre compte. Cliquez sur le lien suivant pour le réinitialiser : <a href="' . $url . '">' . $url . '</a><br><br><br>Si vous n\'êtes pas à l\'origine de cette demande, vous pouvez simplement ignorer cet e-mail.';
         }
 
 
index 4f991a993530378c7b64c65e946fb7ce8cc2f665..a278fdf551d1ebd5a97a17df0d5b94e447c5d361 100644 (file)
@@ -9,13 +9,15 @@ Route::get('/catalogue_invite/{path?}', \App\Http\Controllers\CatalogController:
 
 Route::match(['post'], '/fluidbook/signin', \App\Http\Controllers\FluidbookController::class . '@signin')->withoutMiddleware([VerifyCsrfToken::class]);
 Route::match(['post'], '/fluidbook/login', \App\Http\Controllers\FluidbookController::class . '@login')->withoutMiddleware([VerifyCsrfToken::class]);
-Route::match(['post'], '/fluidbook/forgotpassword', \App\Http\Controllers\FluidbookController::class . '@forgotPassword')->withoutMiddleware([VerifyCsrfToken::class]);
+Route::match(['post','get'], '/fluidbook/forgotpassword', \App\Http\Controllers\FluidbookController::class . '@forgotPassword')->withoutMiddleware([VerifyCsrfToken::class]);
 Route::match(['get'], '/fluidbook/auth', \App\Http\Controllers\FluidbookController::class . '@auth');
 Route::match(['post'], '/fluidbook/order', \App\Http\Controllers\FluidbookController::class . '@order')->withoutMiddleware([VerifyCsrfToken::class]);
 
 Route::match(['post'], '/landing/signin', \App\Http\Controllers\LandingController::class . '@signin');
 Route::match(['post'], '/landing/login', \App\Http\Controllers\LandingController::class . '@login');
-Route::match(['post'], '/landing/forgotpassword', \App\Http\Controllers\LandingController::class . '@forgotPassword');
+Route::match(['post','get'], '/landing/forgotpassword', \App\Http\Controllers\LandingController::class . '@forgotPassword');
 Route::match(['get'], '/landing/logout', \App\Http\Controllers\LandingController::class . '@logout');
+Route::match(['get'], '/landing/resetpassword/{email}/{token}', \App\Http\Controllers\LandingController::class . '@resetPassword');
+Route::match(['post'], '/landing/resetpassword', \App\Http\Controllers\LandingController::class . '@changePassword');
 
 Route::get('/{path?}', \App\Http\Controllers\LandingController::class . '@catchall')->where('path', '.*');