Esempio n. 1
0
 public function action_register()
 {
     $this->request->response = new View_User_Register();
     $user = new Model_Vendo_User();
     $address = new Model_Vendo_Address();
     if ($_POST) {
         $user_post = arr::get($_POST, 'user', array());
         $address_post = arr::get($_POST, 'address', array());
         $validate = Validate::factory(array('password' => arr::get($user_post, 'password'), 'repeat_password' => arr::get($user_post, 'repeat_password')))->rule('repeat_password', 'not_empty')->rule('password', 'matches', array('repeat_password'));
         $roles = arr::get($user_post, 'role_id', array());
         unset($_POST['user']['role_id']);
         unset($_POST['user']['repeat_password']);
         $user->set_fields($user_post);
         $address->set_fields($address_post);
         try {
             // See if the user entered any address information
             $entered_address = FALSE;
             foreach ($address_post as $address_info) {
                 if ($address_info) {
                     $entered_address = TRUE;
                     break;
                 }
             }
             if ($entered_address) {
                 $address->save();
                 $user->address_id = $address->id;
             } else {
                 $user->address_id = NULL;
             }
             $user->save($validate);
             foreach ($roles as $role) {
                 $user->vendo_roles = $role;
             }
             Request::instance()->redirect('home');
         } catch (AutoModeler_Exception $e) {
             $this->request->response->errors = (string) $e;
             // If we've saved an address, get rid of it because it's junk
             // This can happen if the address is valid on the page, but the
             // user is not
             if ($address->id) {
                 $address->delete();
             }
         }
     }
     $this->request->response->user = $user;
     $this->request->response->address = $address;
 }
Esempio n. 2
0
 /**
  * Performs functionality to process a new user account during checkout
  *
  * @return bool
  */
 protected function process_new_account(Model_Vendo_User &$user, $user_post = array(), Model_Vendo_Address $address)
 {
     $validate = Validate::factory(array('password' => arr::get($user_post['password'], 'password'), 'repeat_password' => arr::get($user_post['repeat_password'], 'repeat_password')))->rule('repeat_password', 'not_empty')->rule('password', 'matches', array('repeat_password'));
     $valid_user = $user->is_valid($validate);
     $valid_address = $address->is_valid();
     if (TRUE === $valid_user and TRUE === $valid_address) {
         $address->save();
         $user->address_id = $address->id;
         $user->save();
         $user->roles = Model_Vendo_Role::LOGIN;
     } else {
         $errors = $user->errors('form_errors');
         $errors += $address->errors('form_errors');
         $this->request->response = new View_Checkout_Index();
         $this->request->response->set(array('user' => $user->as_array(), 'address' => $address->as_array(), 'cart' => Auth::instance()->get_user()->cart()));
         $errors = (string) View::factory('form_errors')->set(array('errors' => $errors));
         $this->request->response->errors = $errors;
         return FALSE;
     }
     return TRUE;
 }