Advertisement
Guest User

Untitled

a guest
Jan 13th, 2012
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1.     public function action_register(){
  2.         parse_str($_POST['data'], $values);//convert data in to normal array
  3.  
  4.         $auto_render = false;
  5.         if($_POST['action'] == 'get_form'){//render registration window
  6.             $form = View::factory("home/registration");
  7.             $page = $form->render();
  8.             $this->response->body($page);
  9.            
  10.         }else{//validate registration
  11.             try{
  12.                 $user = ORM::factory('user');
  13.                
  14.                 $validate = Validation::factory($values)
  15.                         ->rule('name', 'not_empty')
  16.                         ->rule('password', 'matches', array(':validation', 'password', 'repeat-password'))
  17.                         ->rule('password', 'not_empty')
  18.                         ->rule('email', 'email')->rule('email', 'not_empty')
  19.                         ->rule('about-me', 'max_length', array(':value', 300));
  20.  
  21.                 $user->values(array(
  22.                     'username'          => $values['name'],
  23.                     'email'             => $values['email'],
  24.                     'password'          => $values['password'],
  25.                     'password_confirm'  => $values['repeat-password'],
  26.                     'age'               => $value['date'],
  27.                     'country'           => $value['Country'],
  28.                     'city'              => $value['city'],
  29.                     'height'            => $value['height'],
  30.                     'body'              => $value['body-type'],
  31.                     'eyes'              => $value['eyes'],
  32.                     'hair'              => $value['hair'],
  33.                     'about_me'          => $value['about-me']
  34.                 ));
  35.                 $user->save();
  36.  
  37.             // remember to add the login role AND the admin roles
  38.                 // add a role; add() executes the query immediatelys
  39.                 $model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
  40.                 echo 'Registration was successful';
  41.                 Auth::instance()->login($values['name'], $values['password']);
  42.                 $mailer = Email::connect();
  43.                 $message =
  44.                 '
  45.                 <div style="text-align:center; color:#69a000;">
  46.                     Wellcome to VoyageGirls.com
  47.                 </div>
  48.                 <br /><br />
  49.                 <span style="font-size:12px; color:#666666;">
  50.                     Welcome to VoyageGirls.com, your registration was succesful.<br />
  51.                     Here is you registration data:
  52.                 </span><br /><br />
  53.                 <span style="font-weight:bold; font-size:12px; color:#666666;">
  54.                     Username: <span style="color:#1ba6b2" font-weight:normal;">'.$values['name'].'</span>
  55.                 </span><br />
  56.                 <span style="font-weight:bold; font-size:12px; color:#666666;">
  57.                     Password: <span style="color:#1ba6b2" font-weight:normal;">'.$values['password'].'</span>
  58.                 </span>
  59.                 ';
  60.                 Email::send($values['email'], 'voyagegirls@gmail.com', 'no reply', $message, $html = true);
  61.             }catch(ORM_Validation_Exception $e){
  62.                 $errors = $e->errors('registration', true);
  63.                 foreach($errors as $value){
  64.                     echo $value."<br />";
  65.                 }
  66.             }
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement