mercredi 6 juin 2018

Lavarvel 5.6 Custom Password Reset Is Giving Invalid Token On Password Reset

what i am trying to do is bypass the email send system and generate custom token and then give it to ResetPasswordController to use the reset method here is my ResetPasswordController

> <?php
> 
> namespace App\Http\Controllers\Auth;
> 
> use App\Http\Controllers\Controller; use Carbon\Carbon; use
> Illuminate\Foundation\Auth\ResetsPasswords; use
> Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use
> Illuminate\Support\Facades\Password; use Illuminate\Support\Str;
> 
> class ResetPasswordController extends Controller {
>     /*
>     |--------------------------------------------------------------------------
>     | Password Reset Controller
>     |--------------------------------------------------------------------------
>     |
>     | This controller is responsible for handling password reset requests
>     | and uses a simple trait to include this behavior. You're free to
>     | explore this trait and override any methods you wish to tweak.
>     |
>     */
> 
>     use ResetsPasswords;
> 
>     /**
>      * Where to redirect users after resetting their password.
>      *
>      * @var string
>      */
>     protected $redirectTo = '/profile';
> 
>     public function reset(Request $request)
>     {
>         $reset_token = hash_hmac('sha256', Str::random(40), env('APP_KEY'));
>         $request->request->add(['token'=> $reset_token]);
>         DB::table('password_resets')->insert([
>             'email' => $request->email,
>             'token' => $reset_token,
>             'created_at' => Carbon::now(),
>         ]);
>         $this->validate($request, $this->rules(), $this->validationErrorMessages());
>         // Here we will attempt to reset the user's password. If it is successful we
>         // will update the password on an actual user model and persist it to the
>         // database. Otherwise we will parse the error and return the response.
>         $response = $this->broker()->reset(
>             $this->credentials($request), function ($user, $password) {
>                 $this->resetPassword($user, $password);
>             }
>         );
> 
>         // If the password was successfully reset, we will redirect the user back to
>         // the application's home authenticated view. If there is an error we can
>         // redirect them back to where they came from with their error message.
>         return $response == Password::PASSWORD_RESET
>                     ? $this->sendResetResponse($response)
>                     : $this->sendResetFailedResponse($request, $response);
>     } }

but it gives me error invalid token please help



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire