samedi 3 avril 2021

How to resend email verification link in Laravel 5.6

Using jrean/laravel-user-verification for User Verification.

The documentation shows the following for resending the verification token.

If you want to regenerate and resend the verification token, you can do this with the following two lines:

UserVerification::generate($user);
UserVerification::send($user, 'My Custom E-mail Subject');

The generate method will generate a new token for the given user and change the verified column to 0. The send method will send a new e-mail to the user.

I have created a method resendEmail using the above documentation.

public function resendEmail() {
    $user = Auth::user();

    UserVerification::generate($user);
    UserVerification::send($user, 'User Verification', config('mail.recieve_to.address'), config('mail.recieve_to.name'));

    return view('home')->with('success','Check your email for verification link!');
}

The receiving email address receives the email with verification link. However, clicking the verification link throws the following error

Jrean \ UserVerification \ Exceptions \ UserNotVerifiedException
This user is not verified.

Routes

Route::get('resend-email', 'HomeController@resendEmail')->name('resend-email');

Route::group(['middleware' => 'isVerified'], function () {
  Route::get('email-verification/error', 'Auth\RegisterController@getVerificationError')->name('email-verification.error');
  Route::get('email-verification/check/{token}', 'Auth\RegisterController@getVerification')->name('email-verification.check');
});

What am I doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire