/** * */ public function register() { $this->load->helper('form'); $this->load->library('form_validation'); $this->load->library("session"); if ($this->form_validation->run('user/register') === FALSE) { $this->load->view("templates/errorForm.php", array("fields" => array('email', 'username', 'password', 'captcha'))); } else { $this->user->registerStudent($this->input->post("username"), $this->input->post("password"), $this->input->post("email")); try { $this->user->save(); $this->login(); } catch (UsernameAlreadyExistException $e) { $this->load->view("user/user_error.php"); User_Error::register_username_exist(); } catch (EmailAlreadyExistException $e) { $this->load->view("user/user_error.php"); User_Error::register_email_exist(); } } }
public function add() { $this->load->helper('form'); $this->load->library('form_validation'); $this->load->library('session'); if ($this->form_validation->run('goal/add') === FALSE) { $this->load->view("templates/errorForm.php", array("fields" => array('startDate', 'endDate', 'task', 'hour'))); } else { $startDate = $this->input->post("startDate"); $endDate = $this->input->post("endDate"); $taskId = $this->input->post("task"); $val = $this->input->post("hour") * 3600; $description = $this->input->post("description"); $goal = new Goal(); try { $this->load->library("jdf"); if (!checkDateString($startDate) || !checkDateString($endDate)) { show_error("data wrong", 400); return; } $startDate = makeTime($startDate); $endDate = makeTime($endDate); $goal->create($val, $startDate, $endDate, $description)->save(new Task($taskId), new User($this->session->getStudentId())); $this->load->view("goal/goal_created"); } catch (Goal_Start_Greater_Than_End $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Start_Greater_Than_End(); } catch (UserNotFound $e) { $this->load->view("user/user_error.php"); User_Error::UserNotFound(); } catch (Goal_Overlap $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Overlap(); } catch (Goal_Value_Invalid $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Value_Invalid(); } } }
/** * Returns true if slug is not being used * * @param string * @return bool */ public function validSlug($slug) { User_Error::i()->argument(1, 'string'); $row = $this->_database->getRow('user', 'user_slug', $slug); //if there is no slug if (empty($row)) { //it's valid return true; } //if slug is set and slugs are equal and user ids are equal if (isset($this->_data['user_slug']) && $this->_data['user_slug'] == $row['user_slug'] && $this->_data['user_id'] == $row['user_id']) { return true; } return false; }