コード例 #1
0
 public function actionSavenewaccount()
 {
     $session = Yii::$app->session;
     $url = Yii::$app->params['siteHostBackendUrl'] . 'home/error';
     if ($session->has('accountTypeID')) {
         $accountTypeID = (int) $session->get('accountTypeID');
         if ($accountTypeID == DefaultForm::ACCOUNT_TYPE_SUPERUSER || $accountTypeID == DefaultForm::ACCOUNT_TYPE_ADMINISTRATOR) {
             $request = Yii::$app->request;
             if ($request->isAjax) {
                 $post = $request->post();
                 $lastName = $post['LastName'];
                 $firstName = $post['FirstName'];
                 $middleName = $post['MiddleName'];
                 $gender = $post['Gender'];
                 $birthday = $post['Birthday'];
                 $homeAddress = $post['HomeAddress'];
                 $countryCode = $post['CountryCode'];
                 $cityID = $post['CityID'];
                 $telephoneNumber = $post['TelephoneNumber'];
                 $mobileNumber = $post['MobileNumber'];
                 $usernamePost = $post['Username'];
                 $password = $post['Password'];
                 $confirmPassword = $post['ConfirmPassword'];
                 $status = $post['Status'];
                 $passwordAsAdmin = $post['PasswordAsAdmin'];
                 $accountType = $post['AccountType'];
                 if ($lastName != "") {
                     if ($firstName != "") {
                         if ($middleName != "") {
                             if ($gender != "") {
                                 if (is_numeric($gender)) {
                                     if ($birthday != "") {
                                         if ($homeAddress != "") {
                                             if ($countryCode != "") {
                                                 if ($cityID != "") {
                                                     if (is_numeric($cityID)) {
                                                         if ($status != "") {
                                                             if (is_numeric($status)) {
                                                                 if ($mobileNumber != "") {
                                                                     if ($password != "") {
                                                                         if ($password == $confirmPassword) {
                                                                             if ($accountTypeID == DefaultForm::ACCOUNT_TYPE_ADMINISTRATOR && $accountType == DefaultForm::ACCOUNT_TYPE_ADMINISTRATOR || $accountTypeID == DefaultForm::ACCOUNT_TYPE_ADMINISTRATOR && $accountType == DefaultForm::ACCOUNT_TYPE_SUPERUSER) {
                                                                                 return DefaultController::redirectToUrl($url);
                                                                             } else {
                                                                                 if ($usernamePost != "") {
                                                                                     if (strlen($usernamePost) >= 8 && strlen($usernamePost) <= 20) {
                                                                                         $username = strtolower($usernamePost);
                                                                                         $_AccountStudentsForm = new AccountStudentsForm();
                                                                                         $isUsernameExistsStudents = $_AccountStudentsForm->checkIfUsernameExists($username);
                                                                                         if ((int) $isUsernameExistsStudents == 0) {
                                                                                             $_AccountAdminForm = new AccountAdminForm();
                                                                                             $isUsernameExistsAdmin = $_AccountAdminForm->checkIfUsernameExists($username);
                                                                                             if ((int) $isUsernameExistsAdmin == 0) {
                                                                                                 $_AccountRegisteredUsersForm = new AccountRegisteredUsersForm();
                                                                                                 $isUsernameExistsRegisteredUsers = $_AccountRegisteredUsersForm->checkIfUsernameExists($username);
                                                                                                 if ((int) $isUsernameExistsRegisteredUsers == 0) {
                                                                                                     $passwordAsAdmin = md5($passwordAsAdmin);
                                                                                                     $checkIfAdminIsReal = $_AccountAdminForm->checkIfAdminIsReal($accountTypeID, $passwordAsAdmin);
                                                                                                     if ($checkIfAdminIsReal == true) {
                                                                                                         $password = md5($password);
                                                                                                         $_AccountAdminDetailsForm = new AccountAdminDetailsForm();
                                                                                                         $saveAccount = $_AccountAdminDetailsForm->saveNewAdmin($lastName, $firstName, $middleName, $gender, $birthday, $homeAddress, $countryCode, $cityID, $telephoneNumber, $mobileNumber, $username, $password, $accountType, $status);
                                                                                                         $returnData = array('adminID' => $saveAccount['AdminID'], 'status' => $saveAccount['status'], 'message' => $saveAccount['message']);
                                                                                                     } else {
                                                                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "You are not authorized to perform this action!");
                                                                                                     }
                                                                                                 } else {
                                                                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username already exists!");
                                                                                                 }
                                                                                             } else {
                                                                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username already exists!");
                                                                                             }
                                                                                         } else {
                                                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username already exists!");
                                                                                         }
                                                                                     } else {
                                                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username must be greater than or equal to 8 characters AND lower than or equal to 20 characters!");
                                                                                     }
                                                                                 } else {
                                                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username is required!");
                                                                                 }
                                                                             }
                                                                         } else {
                                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Passwords does not match!");
                                                                         }
                                                                     } else {
                                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Password is required!");
                                                                     }
                                                                 } else {
                                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Mobile number is required!");
                                                                 }
                                                             } else {
                                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Status is invalid!");
                                                             }
                                                         } else {
                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Status is required!");
                                                         }
                                                     } else {
                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "City is inavalid!");
                                                     }
                                                 } else {
                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "City is required!");
                                                 }
                                             } else {
                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Country is required!");
                                             }
                                         } else {
                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Home address is required!");
                                         }
                                     } else {
                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Birthday is required!");
                                     }
                                 } else {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Gender is invalid!");
                                 }
                             } else {
                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Gender is required!");
                             }
                         } else {
                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Middle name is required!");
                         }
                     } else {
                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "First name is required!");
                     }
                 } else {
                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Last name is required!");
                 }
             } else {
                 $returnData = array('status' => DefaultForm::ERROR_CODE_REQUEST_DEFAULT, 'message' => DefaultForm::ERROR_MESSAGE_AJAX_REQUEST_DEFAULT);
             }
         } else {
             return DefaultController::redirectToLogOut();
         }
     } else {
         return DefaultController::redirectToLogOut();
     }
     echo json_encode($returnData);
 }
コード例 #2
0
 public function actionPostsaveregistereduser()
 {
     $request = Yii::$app->request;
     if ($request->isAjax) {
         $post = $request->post();
         $lastName = $post['LastName'];
         $firstName = $post['FirstName'];
         $middleName = $post['MiddleName'];
         $gender = $post['Gender'];
         $birthday = $post['Birthday'];
         $homeAddress = $post['HomeAddress'];
         $countryCode = $post['CountryCode'];
         $cityID = $post['CityID'];
         $emailAddress = $post['EmailAddress'];
         $telephoneNumber = $post['TelephoneNumber'];
         $mobileNumber = $post['MobileNumber'];
         $username = $post['Username'];
         $password = $post['Password'];
         $confirmPassword = $post['ConfirmPassword'];
         if ($lastName != "") {
             if ($firstName != "") {
                 if ($gender == "" || $gender == 0 || $gender == "0") {
                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Please select your gender!');
                 } else {
                     if ($birthday != "") {
                         if ($countryCode != "") {
                             if ($cityID != "") {
                                 if (is_numeric($cityID)) {
                                     if ($emailAddress != "") {
                                         $isValidEmailAddress = DefaultController::isValidEmailAddress($emailAddress);
                                         if ($isValidEmailAddress == true) {
                                             if ($username != "") {
                                                 if (strlen($username) >= 8 && strlen($username) <= 20) {
                                                     if ($password != "") {
                                                         if (strlen($password) >= 8 && strlen($password) <= 20) {
                                                             if ($confirmPassword != "") {
                                                                 if ($password == $confirmPassword) {
                                                                     $_AccountRegisteredUsersForm = new AccountRegisteredUsersForm();
                                                                     $isUsernameExistsRegisteredUsers = $_AccountRegisteredUsersForm->checkIfUsernameExists($username);
                                                                     if ((int) $isUsernameExistsRegisteredUsers == 0) {
                                                                         $_AccountStudentsForm = new AccountStudentsForm();
                                                                         $isUsernameExistsStudents = $_AccountStudentsForm->checkIfUsernameExists($username);
                                                                         if ((int) $isUsernameExistsStudents == 0) {
                                                                             $_AccountAdminForm = new AccountAdminForm();
                                                                             $isUsernameExistsAdmin = $_AccountAdminForm->checkIfUsernameExists($username);
                                                                             if ((int) $isUsernameExistsAdmin == 0) {
                                                                                 $_AccountRegisteredUsersForm = new AccountRegisteredUsersForm();
                                                                                 $isEmailAddressExistsRegisteredUsers = $_AccountRegisteredUsersForm->checkIfEmailAddressExists($emailAddress);
                                                                                 if ((int) $isEmailAddressExistsRegisteredUsers == 0) {
                                                                                     $_AccountStudentsForm = new AccountStudentsForm();
                                                                                     $isEmailAddressExistsStudents = $_AccountStudentsForm->checkIfEmailAddressExists($emailAddress);
                                                                                     if ((int) $isEmailAddressExistsStudents == 0) {
                                                                                         $_AccountAdminForm = new AccountAdminForm();
                                                                                         $isEmailAddressExistsAdmin = $_AccountAdminForm->checkIfEmailAddressExists($emailAddress);
                                                                                         if ((int) $isEmailAddressExistsAdmin == 0) {
                                                                                             $_AccountRegisteredUserDetailsForm = new AccountRegisteredUserDetailsForm();
                                                                                             $hashedPassword = md5($password);
                                                                                             $activationCode = DefaultController::generateUniqueCode();
                                                                                             $saveRegisteredUser = $_AccountRegisteredUserDetailsForm->saveRegisteredUser($lastName, $firstName, $middleName, $gender, $birthday, $homeAddress, $countryCode, $cityID, $emailAddress, $telephoneNumber, $mobileNumber, $username, $hashedPassword, $activationCode);
                                                                                             $returnData = array('registeredUserID' => $saveRegisteredUser['registeredUserID'], 'status' => $saveRegisteredUser['status'], 'message' => $saveRegisteredUser['message']);
                                                                                         } else {
                                                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Email address already exists!');
                                                                                         }
                                                                                     } else {
                                                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Email address already exists!');
                                                                                     }
                                                                                 } else {
                                                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Email address already exists!');
                                                                                 }
                                                                             } else {
                                                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Username already exists!');
                                                                             }
                                                                         } else {
                                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Username already exists!');
                                                                         }
                                                                     } else {
                                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Username already exists!');
                                                                     }
                                                                 } else {
                                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Passwords did not match!');
                                                                 }
                                                             } else {
                                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Please confirm your password!');
                                                             }
                                                         } else {
                                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Please check password length!');
                                                         }
                                                     } else {
                                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Password is required!');
                                                     }
                                                 } else {
                                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Please check username length!');
                                                 }
                                             } else {
                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Username is required!');
                                             }
                                         } else {
                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Email address is invalid!');
                                         }
                                     } else {
                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Email address is required!');
                                     }
                                 } else {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'City is invalid!');
                                 }
                             } else {
                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'City is required!');
                             }
                         } else {
                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Country is required!');
                         }
                     } else {
                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Bithday is required!');
                     }
                 }
             } else {
                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'First name is required!');
             }
         } else {
             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Last name is required!');
         }
     } else {
         $returnData = array('status' => DefaultForm::ERROR_CODE_REQUEST_DEFAULT, 'message' => DefaultForm::ERROR_MESSAGE_AJAX_REQUEST_DEFAULT);
     }
     return json_encode($returnData);
 }