josiasmontag / laravel-email-verification

Laravel package to handle user verification using an activation mail

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to skip verification

b4dnewz opened this issue Β· comments

Hi, thanks πŸ™ for this great package, very useful and is working good.
I've a case use where I'm inviting people to this laravel application via email and my boss asked me to skip the verification if the user has been invited via email since he already clicked on the "Accept Invite" button on the email so it's kind of already verified.

I've tried to modify the SendUserVerificationMail which is responsable to listen for Registered events and send the email to this:

if (Session::has('invite_token')) {

        $event->user->forceFill([
          'verified' => true
        ])->save();

} else {

        if (config('emailverification.listen_registered_event', true)) {

          $sent = resolve('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($event->user);
          Session::flash($sent == EmailVerification::VERIFY_LINK_SENT ? 'success' : 'error', trans($sent));

        }

}

in hope of make it working and skip the isEmailVerified middleware but unfortunatelly is not working and still goes to the verification resend page but with the message "You are already verified" since I changed the verified flag on the user profile after a good registration.

Any idea about how I can archive this result? basically in this particular case I need to skip the email verification.

Should work like this. The isEmailVerified also checks for the verified attribute only. There is no other magic.
Sorry, no idea what is going wrong here. Would need some debugging.

Maybe I know what's wrong, the isEmailVerified middleware is asking for $request->user() and at that point after registration I think is null because it still needs to be set.

That's why my previous statement is kind of ignored.
I made it working by overriding the RegisterController showResendVerificationEmailForm function:

public function showResendVerificationEmailForm() {
      if (Session::has('invite_token')) {
        return redirect()->route('teams.accept_invite', [
          'token' => Session::get('invite_token')
        ]);
      }

      $user = Auth::user();
      return view('emailverification::resend', ['verified' => $user->verified, 'email' => $user->email]);
}

but.. I guess this is not the best way to do it.

If want to help me with another solution or I can close the issue as I managed to make it work