Reputation: 881
I am trying to check the status of a users account when the user logs into the application with Laravel 4.1.
$attempt = Auth::attempt(array('email' => $input['email'], 'password' => $input['password'], 'active'
=> $input['active']), true);
if($attempt) return Redirect::route('photos.index');
return Redirect::back()->withInput()->with('message', 'Your email or password are incorrect.');
I am using a hidden input "active" to check whether a user account is still active or not. This works fine. However, if this check fails, the user gets to see the same flash message that is displayed when he enters wrong credentials. How could I send a second flash message that states to the user that his account is not active anymore even if he had entered correct credentials?
Any help would be much appreciated.
Thanks!
Upvotes: 1
Views: 892
Reputation: 4111
If the Auth::attempt()
fails you can check with this if it succeeded without an active account.
$attempt = Auth::attempt(array('email' => $input['email'], 'password' => $input['password'], 'active'
=> $input['active']), true);
if($attempt) return Redirect::route('photos.index');
// Check if credentials are correct but the account is not active
if (Auth::validate(array('email' => $input['email'], 'password' => $input['password'])))
{
// Valid but not active
return Redirect::back()->withInput()->with('message', 'Account not active.');
}
return Redirect::back()->withInput()->with('message', 'Your email or password are incorrect.');
Upvotes: 3