I use sentry as an auth package for my application, this is my controller method for registering users.
class Controller_Auth extends \Controller_Base
{
function action_signup($type='user')
{
$user = \Fieldset::forge('new_user');
$user->add('email', 'Email', array(), array(array('required'), array('valid_email')));
$user->add('password', 'Password', array(), array(array('required')));
$user->add('confirm_password', 'Confirm Password', array(), array(array('match_field', 'password') ));
$user->add('submit', '', array('value'=>'Sign Up', 'class' => 'btn', 'type'=>'submit'));
$user->repopulate();
if($user->validation()->run())
{
try
{
$fields = $user->validated();
$user_id = \Sentry::user()->create(array('email'=>$fields['email'], 'password'=>$fields['password']));
if($user_id)
{
}
else
{
}
}
catch(\SentryUserException $e)
{
\Library_Message::set('error', $e->getMessage());
}
catch(\Database_Exception $e)
{
\Library_Message::set('error', 'Database error occured. Please try again');
}
}
else
{
\Library_Message::set('error', $user->validation()->errors());
}
$this->template->set('content', $user->form(), false);
}
}
As you can see, I am mixing both validation errors and exceptions, I was wondering if there is a way to handle all errors using exceptions?
source
share