コード例 #1
0
ファイル: Controller.php プロジェクト: ptarcher/exercise_mvc
 /**
  * Create a new user form.
  *
  * @return The Webpage Text
  */
 function create()
 {
     $api = new Module_UserManagement_API();
     $user_types = $api->getExerciseTypes();
     $form = new AddUserForm();
     if ($form->validate()) {
         $userid = $form->getSubmitValue('login');
         $password = $form->getSubmitValue('password');
         $coach = $form->getSubmitValue('coach');
         $athlete = $form->getSubmitValue('athlete');
         $usertype = $form->getSubmitValue('usertype');
         $success = $api->createUser($userid, $password, $coach, $athlete, $usertype);
         if ($success) {
             /* We have sucessfully logged in, now lets 
              * display the next page */
             /*
             if (!isset($redirect_module) || !isset($redirect_action)) {
                 $redirect_module = 'Sessions';
             }
             
             Core_Url::redirectToUrl($urlToRedirect);
             */
         }
     }
     $view = Core_View::factory('adduser');
     //$view->users = $users;
     $view->addForm($form);
     $view->subTemplate = 'genericForm.tpl';
     /* Coach radio buttons */
     $view->assign('coach_types', array('y' => 'Yes', 'n' => 'No'));
     $view->assign('coach_selected', 'n');
     /* Athlete radio buttons */
     $view->assign('athlete_types', array('y' => 'Yes', 'n' => 'No'));
     $view->assign('athlete_selected', 'n');
     /* Athlete radio buttons */
     $view->assign('usertype_types', array('user' => 'User', 'superuser' => 'SuperUser'));
     $view->assign('usertype_selected', 'user');
     echo $view->render();
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: ptarcher/exercise_mvc
 /**
  * Create a new user
  */
 function signup()
 {
     $form = new Module_Login_SignUpForm();
     $view = Core_View::factory('signup');
     $view->errorMessage = "";
     if ($form->validate()) {
         $api = new Module_Login_API();
         $user_api = new Module_UserManagement_API();
         $login = $form->getSubmitValue('form_login');
         $password = $form->getSubmitValue('form_password');
         $password2 = $form->getSubmitValue('form_passwordconfirm');
         $email = $form->getSubmitValue('form_email');
         /* Check the passwords match */
         try {
             /* Check if the username exists */
             if ($api->getUser($login)) {
                 throw new Exception('The username is already taken');
             }
             /* Check the passwords */
             if ($password !== $password2) {
                 throw new Exception('The passwords do not match');
             }
             $user_api->createUser($login, $password, $email);
             Core_Url::redirectToUrl('index.php');
         } catch (Exception $e) {
             $view->errorMessage = $e->getMessage();
         }
     }
     $view->addForm($form);
     $view->subTemplate = 'genericForm.tpl';
     echo $view->render();
 }