Beispiel #1
0
 protected function render_body()
 {
     if (!empty($_POST)) {
         $errors = $this->validate_first_name(isset($_POST['first-name']) ? $_POST['first-name'] : "");
         $errors .= $this->validate_last_name(isset($_POST['last-name']) ? $_POST['last-name'] : "");
         $errors .= $this->validate_username(isset($_POST['username']) ? $_POST['username'] : "");
         $errors .= $this->validate_password(isset($_POST['password']) ? $_POST['password'] : "");
         $errors .= $this->validate_academic_year(isset($_POST['academic-year']) ? $_POST['academic-year'] : "");
         if ($errors) {
             $this->render_register_form($errors);
         } else {
             $user = new User();
             $user->set_first_name($_POST['first-name']);
             $user->set_last_name($_POST['last-name']);
             $user->set_username($_POST['username']);
             $user->set_password($_POST['password']);
             $user->set_academic_year($_POST['academic-year']);
             $user_model = new User_model();
             if ($user_model->store_user($user, false, false, true) == false) {
                 $this->render_register_form('Username already exists.');
             } else {
                 $this->redirect_to_main_page();
             }
         }
     } else {
         $this->render_register_form();
     }
 }