Created
February 14, 2011 00:21
-
-
Save iammerrick/825334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Try creating the user, commit a transaction. | |
* | |
* @author Merrick Christensen | |
*/ | |
try | |
{ | |
$user = ORM::factory('user') | |
->create_user($_POST, array( | |
'email', | |
'password', | |
'username', | |
)); | |
$roles = array( | |
'login' => new Model_Role(array('name' => 'login')), | |
'landlord' => new Model_Role(array('name' => 'landlord')) | |
); | |
$user->add('roles', $roles['login']); | |
$user->add('roles', $roles['landlord']); | |
$db->commit(); | |
} | |
catch(ORM_Validation_Exception $e) | |
{ | |
$errors = $e; | |
} | |
/** | |
* Try creating the landlord, if not merge the errors with | |
* the user and rollback the user transaction. | |
* | |
* @author Merrick Christensen | |
*/ | |
try | |
{ | |
$landlord = ORM::factory('landlord') | |
->create_landlord($_POST, array( | |
'first_name', | |
'last_name', | |
'mobile' | |
), $user); | |
if($landlord) | |
{ | |
$this->auth->login($user->username, Arr::get($_POST, 'password')); | |
$this->request->redirect('/dashboard'); | |
} | |
} | |
catch (ORM_Validation_Exception $e) | |
{ | |
$errors->merge('user', $e); | |
Message::set(Message::ERROR, $errors->errors('user')); | |
$this->_db->rollback(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment