phpauthenticationlaravel-5.3confirmation-email

Laravel 5.3 E-Mail Confirmation


I need to implement the functionality of confirmation of the email address of a user before making him able to login to my platform.

I have successfully implemented the sending of a confirmation code at registration and save a string "confirmation_code" and and a Boolean "confirmed" of whether a user is confirmed or not in the database.

The verification itself is also already implemented.

Now the only problem I have is the checking at login if the user is confirmed or not. I read into the API of Laravel 5.3 but I could not figure out how to edit the login process in the way I like. I don't like changing too much of the original functionality of laravel, I just want to add a simple parameter to the authentication process during login. Cant be that hard can it?


Solution

  • Okay, I have found a solution for my problem.

    I have now overriden the attemptLogin(Request $request) function with my personal preferences. Not a great deal if you know what you have to look for. I think it should be somehow clarified in the laravel docs because authenticate itself doesnt work at all.

    However, here is my code if anyone is interested:

    protected function attemptLogin(Request $request){
        return $this->guard()->attempt([
            'email' => $request->email,
            'password' => $request->password,
            'confirmed' => 1
        ], $request->has('remember'));
    }
    

    The code above is written in my LoginController.php file.

    The only thing I now have to find out is how to detect why a login has failed so I can tell the user whether his/her email/password combination was wrong or their account is not activated yet.

    Thanks for the help!