public function actionPostupdateadminaccess()
 {
     $session = Yii::$app->session;
     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();
                 $status = $post['Status'];
                 $usernamePost = $post['Username'];
                 $password = $post['Password'];
                 $confirmPassword = $post['ConfirmPassword'];
                 $passwordAsAdmin = $post['PasswordAsAdmin'];
                 $adminID = $post['AdminID'];
                 $sessionAccountID = (int) $session->get('accountID');
                 $_AccountStudentsForm = new AccountStudentsForm();
                 $_AccountAdminForm = new AccountAdminForm();
                 $_AccountRegisteredUsersForm = new AccountRegisteredUsersForm();
                 $accountTypeResult = $_AccountAdminForm->getAccountTypeByID($adminID);
                 if ((!empty($accountTypeResult) || $accountTypeResult != "") && (int) $accountTypeResult != 0) {
                     if (strlen($usernamePost) == 0) {
                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "Username is required!");
                     } else {
                         if (strlen($usernamePost) >= 8 && strlen($usernamePost) <= 20) {
                             $username = strtolower($usernamePost);
                             $isUsernameExistsAdmin = $_AccountAdminForm->checkIfUsernameExistsWithAdminID($username, $adminID);
                             if ((int) $isUsernameExistsAdmin == 0) {
                                 $isUsernameExistsStudents = $_AccountStudentsForm->checkIfUsernameExists($username);
                                 if ((int) $isUsernameExistsStudents == 0) {
                                     $isUsernameExistsRegisteredUsers = $_AccountRegisteredUsersForm->checkIfUsernameExists($username);
                                     if ((int) $isUsernameExistsRegisteredUsers == 0) {
                                         if ($password != "") {
                                             if ($confirmPassword != "") {
                                                 if ($password == $confirmPassword) {
                                                     if ($passwordAsAdmin != "") {
                                                         $passwordAsAdmin = md5($passwordAsAdmin);
                                                         $checkIfAdminIsReal = $_AccountAdminForm->checkIfAdminIsReal($sessionAccountID, $passwordAsAdmin);
                                                         if ($checkIfAdminIsReal == true) {
                                                             $password = md5($password);
                                                             $updateAdminAccess = $_AccountAdminForm->updateAdminStatusAndUsernameAndPassword($status, $username, $password, $adminID);
                                                             $returnData = array('status' => $updateAdminAccess['status'], 'message' => $updateAdminAccess['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' => "Please prove that you are an admin!");
                                                     }
                                                 } 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 {
                                             if ($passwordAsAdmin != "") {
                                                 $passwordAsAdmin = md5($passwordAsAdmin);
                                                 $checkIfAdminIsReal = $_AccountAdminForm->checkIfAdminIsReal($sessionAccountID, $passwordAsAdmin);
                                                 if ($checkIfAdminIsReal == true) {
                                                     $password = md5($password);
                                                     $updateAdminAccess = $_AccountAdminForm->updateAdminStatusAndUsername($status, $username, $adminID);
                                                     $returnData = array('status' => $updateAdminAccess['status'], 'message' => $updateAdminAccess['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' => "Please prove that you are an admin!");
                                             }
                                         }
                                     } 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' => "You are not allowed to perform this action!");
                 }
             } else {
                 $returnData = array('status' => DefaultForm::ERROR_CODE_REQUEST_DEFAULT, 'message' => DefaultForm::ERROR_MESSAGE_AJAX_REQUEST_DEFAULT);
             }
         } else {
             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => "You are not allowed to perform this action!");
         }
         echo json_encode($returnData);
     } else {
         return DefaultController::redirectToLogOut();
     }
 }
 public function actionPostlogin()
 {
     $request = Yii::$app->request;
     if ($request->isAjax) {
         $post = $request->post();
         $usernameOrEmailAddress = $post['UsernameOrEmail'];
         $password = $post['Password'];
         if ($usernameOrEmailAddress != "") {
             if ($password != "") {
                 $_AccountRegisteredUsersForm = new AccountRegisteredUsersForm();
                 $_AccountStudentsForm = new AccountStudentsForm();
                 $isValidEmailAddress = DefaultController::isValidEmailAddress($usernameOrEmailAddress);
                 $password = md5($password);
                 if ($isValidEmailAddress == true) {
                     $resultData = $_AccountRegisteredUsersForm->getAccountTypeIDByEmailAddressAndPassword($usernameOrEmailAddress, $password);
                 } else {
                     $resultData = $_AccountRegisteredUsersForm->getAccountTypeIDByUsernameAndPassword($usernameOrEmailAddress, $password);
                     $userData = $resultData;
                     if (empty($resultData) || is_null($resultData)) {
                         $userData = $_AccountStudentsForm->getAccountTypeIDByUsernameAndPassword($usernameOrEmailAddress, $password);
                     } else {
                         $userData = $resultData;
                     }
                 }
                 if ((!empty($userData) || !is_null($userData)) && $userData != false) {
                     $userID = $userData['ID'];
                     $accountTypeID = $userData['AccountTypeID'];
                     if ($accountTypeID == DefaultForm::ACCOUNT_TYPE_REGISTERED_USER) {
                         $loginDetails = $_AccountRegisteredUsersForm->getLoginDetailsByID($userID);
                     } else {
                         if (DefaultForm::ACCOUNT_TYPE_STUDENT) {
                             $loginDetails = $_AccountStudentsForm->getLoginDetailsByID($userID);
                         } else {
                             $loginDetails = array();
                         }
                     }
                     if ((!empty($loginDetails) || !is_null($loginDetails)) && $loginDetails != false) {
                         $status = $loginDetails['Status'];
                         if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_ACTIVE) {
                             $accountTypeID = $loginDetails['AccountTypeID'];
                             $firstName = $loginDetails['FirstName'];
                             $sessionNameAccountTypeID = 'accountTypeID';
                             $createSessionAccountTypeID = DefaultController::createSession($sessionNameAccountTypeID, $accountTypeID);
                             if ($createSessionAccountTypeID == true) {
                                 $sessionNameAccountID = 'accountID';
                                 $createSessionAccountID = DefaultController::createSession($sessionNameAccountID, $userID);
                                 $sessionNameFirstName = 'firstName';
                                 $createSessionFirstName = DefaultController::createSession($sessionNameFirstName, $firstName);
                                 if ($createSessionAccountID == true && $createSessionFirstName == true) {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_NO_ERROR, 'message' => 'Connected! Redirecting you now...');
                                 } else {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'There was an error creating your account session! Please try again.');
                                 }
                                 $returnData = array('status' => DefaultForm::ERROR_CODE_NO_ERROR, 'message' => 'Connected! Redirecting you now...');
                             } else {
                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'There was an error creating your account session! Please try again.');
                             }
                         } else {
                             if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_INACTIVE) {
                                 if ($accountTypeID == DefaultForm::ACCOUNT_TYPE_REGISTERED_USER) {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Your account is not yet activated! Please go to your mailbox search for your registration details. Kindly follow the instructions to activate your account. Thank you.');
                                 } else {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Your account is not yet activated! Please contact the administrator for further details.');
                                 }
                             } else {
                                 if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_DEACTIVATED) {
                                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Your account has been deactivated! Please contact the administrator for further details.');
                                 } else {
                                     if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_LOCKED_BY_SELF) {
                                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Your account has been locked! Please contact the administrator for further details.');
                                     } else {
                                         if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_LOCKED_BY_THE_ADMINISTRATOR) {
                                             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Your account has been locked! Please contact the administrator for further details.');
                                         } else {
                                             if ($status == DefaultForm::ACCOUNT_STATUS_REGISTERED_USER_DELETED) {
                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Account is invalid!');
                                             } else {
                                                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Could not retrieve account status! Please contact the administrator for further details.');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Account is invalid!');
                     }
                 } else {
                     $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Account is invalid!');
                 }
             } else {
                 $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'Account is invalid!');
             }
         } else {
             $returnData = array('status' => DefaultForm::ERROR_CODE_SYSTEM_DEFAULT, 'message' => 'New password is required!');
         }
     } else {
         $returnData = array('status' => DefaultForm::ERROR_CODE_REQUEST_DEFAULT, 'message' => DefaultForm::ERROR_MESSAGE_AJAX_REQUEST_DEFAULT);
     }
     return json_encode($returnData);
 }