Beispiel #1
0
 public function actionRegistration()
 {
     $this->preventTemplateRender();
     $user = new Model_UserModel();
     $isVarsSet = true;
     if (!isset($_POST['user_nameReg'])) {
         $user->setValidationError('username', 'Username not set');
         $isVarsSet = false;
     }
     if (!isset($_POST['passwordReg'])) {
         $user->setValidationError('password', 'Password not set');
         $isVarsSet = false;
     }
     if (!isset($_POST['first_name'])) {
         $user->setValidationError('first_name', 'Firstname not set');
         $isVarsSet = false;
     }
     if (!isset($_POST['last_name'])) {
         $user->setValidationError('password', 'Last name not set');
         $isVarsSet = false;
     }
     if (!isset($_POST['email'])) {
         $user->setValidationError('email', 'Email not set');
         $isVarsSet = false;
     }
     if (!$isVarsSet) {
         echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
         return false;
     }
     $user->setUserName($_POST['user_nameReg']);
     $user->setPasswordBeforeSalt($_POST['passwordReg']);
     $user->setFirstName($_POST['first_name']);
     $user->setLastName($_POST['last_name']);
     $user->setEmail($_POST['email']);
     $user->validateFields(array('user_name', 'password', 'first_name', 'last_name', 'email'));
     if ($user->isValid()) {
         $user->registration();
         if (!$user->isValid()) {
             echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
         } else {
             echo json_encode(array('status' => 'ok', 'message' => 'Registration is complete<br /> You may login now'));
         }
     } else {
         echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
     }
 }