/** * Create a new post and recalculate post count. * * @param array $values * @param array $expected * @return ORM */ public function create_post($values, $expected) { // Validation for topic $extra_validation = Validation::Factory($values)->rule('topic_id', 'Model_Forum_Topic::topic_exists'); $this->values($values, $expected)->create($extra_validation); // Update the post count for the post owner. $user = $this->user; $user->set_property('forum.posts', $user->get_property('forum.posts') + 1); $user->save(); return $this; }
public function create_vote($values, $expected) { // Validation for vote $extra_validation = Validation::Factory($values)->rule('poll_id', 'Model_Forum_Poll::poll_exists')->rule('option_id', 'Model_Forum_Poll_Option::option_exists'); return $this->values($values, $expected)->create($extra_validation); }
public function create_poll($values, $expected) { // Validation for poll $extra_validation = Validation::Factory($values)->rule('topic_id', 'Model_Forum_Topic::topic_exists'); return $this->values($values, $expected)->create($extra_validation); }
public function create_message($values, $expected) { // Validation for id $extra_validation = Validation::Factory($values)->rule('receiver_id', 'Model_User::user_exists'); return $this->values($values, $expected)->create($extra_validation); }
private function validateEmailOrPhone($post) { $extra_validation = Validation::Factory($post); if (empty($post['phone'])) { $extra_validation->rule('email', 'not_empty'); } else { if (empty($post['email'])) { $extra_validation->rule('phone', 'not_empty'); } } return $extra_validation; }
public function build_regID($post, $locations, $convention_id) { $validate = Validation::Factory($post)->rule('comp_loc', 'in_array', array(':value', array_values($locations)))->rule('comp_id', 'numeric')->rule('comp_id', 'not_empty'); $errors = array(); if (!$validate->check() || !is_numeric($convention_id)) { foreach ($validate->errors('reg_id') as $error_msg) { array_push($errors, $error_msg); } $this->reg_id = ''; } else { $this->reg_id = sprintf('%s-%02s-%04s', $post['comp_loc'], $convention_id, $post['comp_id']); } return $errors; }
public function create_pet($values, $expected) { $extra_validation = Validation::Factory($values)->rule('colour_id', 'Valid_Pet::colour_free', array(':value')); return $this->values($values, $expected)->create($extra_validation); }
function action_changePassword() { /* Set page title */ $this->template->title = __('Change Password'); $this->template->heading = __('Change Your Password'); $this->template->subheading = __('Change your account password.'); /* Require login */ $this->requireLogin(); /* Get logged in account */ $account = $this->auth->getAccount(); $fields = $account->default_fields; $form = array('password' => '', 'confirm_password' => ''); $errors = $form; if ($post = $this->request->post()) { $extra_validation = Validation::Factory($post); $account->values($post); try { $extra_validation->rule('password', 'matches', array(':validation', 'password', 'confirm_password')); $account->save($extra_validation); $this->addMessage('Successfully changed the password for ' . $account->email); /* Complete login, update hash, update timestamps, etc */ $account->salt = null; $account->password = $post['password']; $this->auth->complete_login($account); $this->request->redirect('user/index'); return; } catch (ORM_Validation_Exception $e) { // repopulate the form fields $form = arr::overwrite($form, $post); // populate the error fields, if any // We need to already have created an error message file, for Kohana to use // Pass the error message file name to the errors() method $error_list = $e->errors('form_error_messages'); $errors = arr::overwrite($errors, $error_list); if (!empty($error_list['_external']['password'])) { $errors['confirm_password'] = $error_list['_external']['password']; //This is a hack! } } catch (Exception $e) { $this->addError("Oops. Something went wrong and it's not your fault. Contact the system maintainer please!"); } } $this->template->content = new View('user/changePassword', array('form' => $form, 'errors' => $errors, 'fields' => $fields)); }