Code below is my login method using Sentry 2. I'm basically letting Sentry do everything for me validation, find the user and, of course, login the user. Messages are in portuguese, but if you need me to translate just tell.
public function login()
{
try
{
$credentials = array(
'email' => Input::has('email') ? Input::get('email') : null,
'password' => Input::has('password') ? Input::get('password') : null,
);
// Log the user in
$user = Sentry::authenticate($credentials, Input::has('remember_me') and Input::get('remember_me') == 'checked');
return View::make('site.common.message')
->with('title','Seja bem-vindo!')
->with('message','Você efetuou login com sucesso em nossa loja.');
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
{
return View::make('site.common.message')
->with('title','Erro')
->with('message','O campo do e-mail é necessário.');
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
{
return View::make('site.common.message')
->with('title','Erro')
->with('message','O campo do senha é necessário.');
}
catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
{
$user = Sentry::getUserProvider()->findByLogin(Input::get('email'));
Email::queue($user, 'site.users.emailActivation', 'Ativação da sua conta na Vevey');
return View::make('site.common.message')
->with('title','Usuário não ativado')
->with('message',"O seu usuário ainda não foi ativado na nossa loja. Um novo e-mail de ativação foi enviado para $user->email, por favor verifique a sua caixa postal e clique no link que enviamos na mensagem. Verifique também se os nossos e-mails não estão indo direto para a sua caixa de SPAM.");
}
catch (Cartalyst\Sentry\Users\WrongPasswordException $e)
{
return View::make('site.common.message')
->with('title','Erro')
->with('message','A senha fornecida para este e-mail é inválida.');
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
return View::make('site.common.message')
->with('title','Erro')
->with('message','Não existe usuário cadastrado com este e-mail em nossa loja.');
}
// Following is only needed if throttle is enabled
catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
{
$time = $throttle->getSuspensionTime();
return View::make('site.common.message')
->with('title','Erro')
->with('message',"Este usário está suspenso por [$time] minutes. Aguarde e tente novamente mais tarde.");
}
catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
{
return View::make('site.common.message')
->with('title','Erro')
->with('message',"Este usário está banido do nossa loja.");
}
}