public function action_register(){
parse_str($_POST['data'], $values);//convert data in to normal array
$auto_render = false;
if($_POST['action'] == 'get_form'){//render registration window
$form = View::factory("home/registration");
$page = $form->render();
$this->response->body($page);
}else{//validate registration
try{
$user = ORM::factory('user');
$validate = Validation::factory($values)
->rule('name', 'not_empty')
->rule('password', 'matches', array(':validation', 'password', 'repeat-password'))
->rule('password', 'not_empty')
->rule('email', 'email')->rule('email', 'not_empty')
->rule('about-me', 'max_length', array(':value', 300));
$user->values(array(
'username' => $values['name'],
'email' => $values['email'],
'password' => $values['password'],
'password_confirm' => $values['repeat-password'],
'age' => $value['date'],
'country' => $value['Country'],
'city' => $value['city'],
'height' => $value['height'],
'body' => $value['body-type'],
'eyes' => $value['eyes'],
'hair' => $value['hair'],
'about_me' => $value['about-me']
));
$user->save();
// remember to add the login role AND the admin roles
// add a role; add() executes the query immediatelys
$model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
echo 'Registration was successful';
Auth::instance()->login($values['name'], $values['password']);
$mailer = Email::connect();
$message =
'
<div style="text-align:center; color:#69a000;">
Wellcome to VoyageGirls.com
</div>
<br /><br />
<span style="font-size:12px; color:#666666;">
Welcome to VoyageGirls.com, your registration was succesful.<br />
Here is you registration data:
</span><br /><br />
<span style="font-weight:bold; font-size:12px; color:#666666;">
Username: <span style="color:#1ba6b2" font-weight:normal;">'.$values['name'].'</span>
</span><br />
<span style="font-weight:bold; font-size:12px; color:#666666;">
Password: <span style="color:#1ba6b2" font-weight:normal;">'.$values['password'].'</span>
</span>
';
Email::send($values['email'], 'voyagegirls@gmail.com', 'no reply', $message, $html = true);
}catch(ORM_Validation_Exception $e){
$errors = $e->errors('registration', true);
foreach($errors as $value){
echo $value."<br />";
}
}
}