mardi 24 mars 2020

Laravel Validation from Email Results in Infinite Redirects

I'm trying to make a validator for an authentication code that is sent to users via email. The user has a link in their email they must click, which sends them to our website to validate the code.

The validator works and is able to validate authentication code against it's database counterpart. However, if an invalid authentication code is created... the user enters an infinite redirect cycle.

This is because the previous page on the website doesn't exist, I'm assuming...

Is there any way I can change the redirect URL in this situation? Here is the function...

class User extends Authenticatable
{
   public function verifyAuthToken(Request $request, $token)
   {
     $data = ["token" => $token];

     // If this fails, it redirects the user to the previous page automatically.
     $result = Validator::make($data, [
         'token' => 'required|exists:users,auth_code,id,' . $this->id,
     ],
     [
       'token' => 'This verification code is invalid, please restart the process.'
     ])->validate();

     // Validation was successful, remove auth code from user...
     $this->auth_code = "";
     $this->save();
   }
}

The issue here is that I call this function by doing user->verifyAuthToken from a different controller. I want this call to automatically redirect the user to a certain page... but since the return value isn't in the scope of the controller we can't issue the redirect ourselves... The validator throws an exception which laravel listens for and handles the redirect itself.... I just need a way to select where this redirect goes...



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bj6GlK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire