I'm currently working on my Laravel app and to prevent spam I decided that only active users are able to login. I'm currently using Laravel's login system just like in Laravel's official website tutorial, here's my form action:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}">
This works completely fine, however I'd like to check the user's active, if not active it would be redirected to the activation page, otherwise it would login. Is there a simple way to do this or am I obligated to make a new controller, routes and more verifications? Thank you.
Edit: Forgot to mention that I have a 'active' column in my database.
in AuthController override method getCredentials like this:
make sure you have the column active on user table...
In Laravel 5.4 open Auth/LoginController.php
and add this function:
And you are done..!
Laravel 5.4 / 5.5
Override the default
login()
function by placing this function in yourLoginController
:Overriding the
login()
method in this way is recommended over many of the other answers on this question because it allows you to still use many of the more advanced authentication functionality of Laravel 5.4+ such as login throttling, multiple authentication guard drivers/providers, etc. while still allowing you to set a custom error message.Laravel 5.3
Change or override your
postLogin()
function in yourAuthController
to look like this:This code redirects back to the login page with an error message about the user being inactive. If you want to redirect to an authentication page you would change the line I marked with the comment
Change this to redirect elsewhere
.