vendredi 26 juillet 2019

How do I fire events after user verification?

First off, I've followed every step in the docs without success. I then dug into the getVerification method handling email verification requests, and went all the way down to Jrean\UserVerification\UserVerification, where they have wasVerified($user)

$user->verification_token = null;

    $user->verified = true;

    $user->verified_at = now();

    $this->updateUser($user);

    event(new UserVerified($user)); 

So I swapped out the default event in the docs, which I was dispatching in my override of getVerification in RegisterController

default EventServiceProvider from docs

protected $listen = [
    'Illuminate\Auth\Events\Verified' => [ // then replaced event name with 'Jrean\UserVerification\Events\UserVerified'
        'App\Listeners\LogVerifiedUser',
    ],
]; 

I also tried listening to both events i.e. firing mine as well in my RegisterController

use VerifiesUsers {

  getVerification as parentVerification;
}


public function getVerification(Request $request, $token) {

    $this->parentVerification($request, $token);

    event(new Verified(\Auth::user()));

Then I dded something (either in the listener or before manually emitting the event in the controller above) and the DB insert in my listener ran seamlessly.

However, there was no redirect afterwards. I removed the dd, believing all to be well and fine, now the behaviour has become even more inscrutable: after "verification", those columns in wasVerified() never get updated in that user's row. Everything is stagnant, yet the user can perform all actions accessible to a verified user (in spite of those routes being protected with the "verified" middleware, which is also registered in the routes middleware in the Kernel). At the same time, either none of the events fire or the listener is deaf.

I tried following the mocking events docs but I don't know how to go about replicating user verification in a test environment. But even if I did, it will just tell me whether the event is fired in the first place, not directly solving the problem at hand.

Finally, I tried manually calling my target handler (both with and without the aid of events) but nothing happens. It just gets into the parent verifier and redirects to the homepage.

Is there any other way of running a desired action after a user is verified?



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

Aucun commentaire:

Enregistrer un commentaire