From: soufiane Date: Tue, 13 Jun 2023 15:59:39 +0000 (+0200) Subject: wip #5788 @6:30 mot de passe oublié X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7edd2b1eb1f41a52daaed9619cac8cc1171d4947;p=pmi.git wip #5788 @6:30 mot de passe oublié --- diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1f5aeae..f71acc8 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel $schedule->command('backup:run')->daily()->at('05:00'); $schedule->command('cubist:search:index', ['PMI', 'all'])->cron('35 */4 * * *'); $schedule->command('cubist:search:index', ['MICHSCI', 'all'])->cron('5 */4 * * *'); + $schedule->command('auth:clear-resets')->everyFifteenMinutes(); } /** diff --git a/app/Http/Controllers/ClientForgotPassword.php b/app/Http/Controllers/ClientForgotPassword.php index 5ebfc52..747893a 100644 --- a/app/Http/Controllers/ClientForgotPassword.php +++ b/app/Http/Controllers/ClientForgotPassword.php @@ -2,16 +2,21 @@ namespace App\Http\Controllers; - +use App\Models\AuthClient; +use App\User; use App\Models\Client; -use Illuminate\Support\Facades\Mail; +use Cubist\Backpack\app\Magic\Menu\Menu; +use Illuminate\Auth\Events\PasswordReset; use Illuminate\Support\Facades\Password; use Illuminate\Http\Request; -use Illuminate\Auth\Passwords\CanResetPassword; -use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; -use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; +use Cubist\Backpack\app\Http\Controllers\CubistPageController; +use Illuminate\Support\Facades\DB; +use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Auth\Passwords\PasswordBroker; -class ClientForgotPassword +class ClientForgotPassword extends CubistPageController { /* |-------------------------------------------------------------------------- @@ -23,30 +28,48 @@ class ClientForgotPassword | your application to your users. Feel free to explore this trait. | */ - use CanResetPassword; public function test(Request $request) { $request->validate(['email' => 'required|email']); - $email = $request->only('email'); - $contents = ""; - - $client = Client::where('email', $email['email'])->first(); - - $token = Password::createToken($client); + $status = Password::sendResetLink( + $request->only('email') + ); - dd($token); - - Mail::raw($contents, function ($message) use($email) { - $message->from(config('mail.from.address'), config('mail.from.name')); - $message->sender(config('mail.from.address'), config('mail.from.name')); - $message->to($email); - $message->bcc('test+pmi@cubedesigners.com'); - $message->subject("Mise à jour"); - }); + //$url = 'https://example.com/reset-password?token='.$token; + //$this->notify(new ResetPasswordNotification($url)); return $status === Password::RESET_LINK_SENT ? back()->with(['status' => __($status)]) : back()->withErrors(['email' => __($status)]); } + + public function reset(Request $request) { + $request['email'] = str_replace('%40', '@', $request->email); + $request->validate([ + 'token' => 'required', + 'email' => 'required|email', + 'password' => 'required|min:8|confirmed', + ]); + + $password = $request->password; + $email = $request->email; + + $actualToken = DB::table('password_resets')->where('email', $request->email)->first(); + $tokenIsValid = Hash::check($request->token, $actualToken->token); + + // Validate the token + if (!$tokenIsValid) + return back()->withErrors(['error' => 'error']); + + $client = Client::where('email', $email)->first(); + if (!$client) return redirect()->back()->withErrors(['email' => 'Email non trouvé']); + + //Hash and update the new password + $client->password = Hash::make($password); + $client->update(); + + return redirect('/se-connecter'); + //return redirect()->route('se-connecter')->with('status', __('Mot de passe changer avec succès')); + } } diff --git a/app/Models/AuthClient.php b/app/Models/AuthClient.php index ada747e..46d642a 100644 --- a/app/Models/AuthClient.php +++ b/app/Models/AuthClient.php @@ -1,11 +1,19 @@ notify(new ResetPasswordNotification($token)); + } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9784b1a..335cfd1 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -4,6 +4,8 @@ namespace App\Providers; use Illuminate\Support\Facades\Gate; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use App\Models\AuthClient; +use Illuminate\Auth\Notifications\ResetPassword; class AuthServiceProvider extends ServiceProvider { @@ -24,7 +26,6 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); - // } } diff --git a/app/Templates/ChangePassword.php b/app/Templates/ChangePassword.php index 8ad5d47..ccb8962 100644 --- a/app/Templates/ChangePassword.php +++ b/app/Templates/ChangePassword.php @@ -4,6 +4,8 @@ namespace App\Templates; +use Cubist\Backpack\app\Magic\Menu\PageItem; + class ChangePassword extends Base { public function getName() @@ -15,4 +17,12 @@ class ChangePassword extends Base { parent::init(); } + + public function setData(&$data) + { + $token = request()->get('token'); + $email = request()->get('email'); + $data['token'] = $token; + $data['email'] = $email; + } } diff --git a/config/auth.php b/config/auth.php index b766952..cbbea98 100644 --- a/config/auth.php +++ b/config/auth.php @@ -107,6 +107,11 @@ return [ 'table' => 'password_resets', 'expire' => 60, ], + 'clients' => [ + 'provider' => 'clients', + 'table' => 'password_resets', + 'expire' => 60, + ] ], ]; diff --git a/resources/views/pages/change_password.blade.php b/resources/views/pages/change_password.blade.php new file mode 100644 index 0000000..07f62f9 --- /dev/null +++ b/resources/views/pages/change_password.blade.php @@ -0,0 +1,38 @@ +@extends('layouts/app') + +@section('content') +
+ +
+@endsection diff --git a/resources/views/pages/sign_in.blade.php b/resources/views/pages/sign_in.blade.php index f7195a2..a3a16d9 100644 --- a/resources/views/pages/sign_in.blade.php +++ b/resources/views/pages/sign_in.blade.php @@ -70,7 +70,7 @@
- Mot de passe oublié ? + Mot de passe oublié ?