Created
May 16, 2010 18:35
-
-
Save JustLikeIcarus/403067 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 | |
function action_register() | |
{ | |
#If user already signed-in | |
if(Auth::instance()->logged_in()!= 0){ | |
#redirect to the user account | |
Request::instance()->redirect('account/profile'); | |
} | |
#Load the view | |
$this->template->content = View::factory('account/register') | |
->bind($errors) | |
->bind($content); | |
#If there is a post and $_POST is not empty | |
if ($_POST) | |
{ | |
#Instantiate a new user | |
$user = ORM::factory('user'); | |
#Load the validation rules, filters etc... | |
$validate_pw_confirm = Validate::factory($_POST) | |
->rule('password_confirm', 'matches', array('password')); | |
try | |
{ | |
#Affects the sanitized vars to the user object | |
$user->values($_POST); | |
#create the account | |
$user->create($validate_pw_confirm ); | |
#Add the login role to the user | |
$login_role = new Model_Role(array('name' =>'login')); | |
$user->add('roles',$login_role); | |
#sign the user in | |
$content = Kohana::debug(Auth::instance()->login($_POST['username'], $_POST['password'])); | |
#redirect to the user account | |
#Request::instance()->redirect('account/profile'); | |
} | |
catch(ORM_Validation_Exception $e) | |
{ | |
#Get errors for display in view | |
$errors = $e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment