I need to let users resgister themselves through a form, and let them inactive users till, the Administrator change their active field or whatever to 1
What are the steps to do that ?
User Model ? a boolean 'active' field in the users migration ? Where and how to call the next code found in the documentation page?
if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1))) { // The user is active, not suspended, and exists. } Or should i use sentry ? and forget about the basic built in laravel auth ? please help with this
Just create a boolean field in your users table called active, and set it to true for activated users. That line of code is what you use to authenticate users, so in your LoginController probably.
I am doing it like this.
public function postLogin() {
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if ( ! Auth::attempt($credentials) ) {
// return with error
}
if ( Auth::once($credentials) ) {
if ( ! Auth::user()->activated ) {
Auth::logout();
// return with error
}
}
// etc.
}
I copy and past below lines from laravel site,so I think this way is better.
Authenticating A User With Conditions
You also may add extra conditions to the authenticating query:
if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1)))
{
// The user is active, not suspended, and exists.
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community