Пример #1
0
 function post_xhr($userID = null)
 {
     if ($this->checkAuth()) {
         if (is_null($userID)) {
             $userExists = AuthUserData::userExist(mb_strtolower($_POST['userName']));
             $emailExists = AuthUserData::emailExist(mb_strtolower($_POST['email']));
             if (mb_strlen($_POST['userName']) >= _USERNAME_MIN_LENGTH_ && !$userExists && !empty($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) && !$emailExists && !empty($_POST['password']) && is_numeric($_POST['twoFactorType'])) {
                 $headers = getallheaders();
                 $subUser = new AuthSubUser(mb_strtolower($headers['Auth-User']));
                 $roles = array();
                 if (isset($_POST['roles']) && is_array($_POST['roles'])) {
                     $roles = $_POST['roles'];
                 }
                 if ($newUserId = $subUser->createSubUser(mb_strtolower($_POST['userName']), mb_strtolower($_POST['email']), $_POST['password'], $_POST['twoFactorType'], $roles)) {
                     echo json_encode(StatusReturn::S200(array('id' => $newUserId)), JSON_NUMERIC_CHECK);
                 } else {
                     echo json_encode(StatusReturn::E400('Unknown Error!'));
                 }
             } else {
                 if ($userExists) {
                     echo json_encode(StatusReturn::E400('User Exists!'));
                 } else {
                     if ($emailExists) {
                         echo json_encode(StatusReturn::E400('Email Exists!'));
                     } else {
                         echo json_encode(StatusReturn::E400('Missing roles or twoFactorType'));
                     }
                 }
             }
         } else {
             if (AuthUserData::userExistByID($userID)) {
                 $headers = getallheaders();
                 $subUser = new AuthSubUser(mb_strtolower($headers['Auth-User']), (int) $userID);
                 $allSuccess = true;
                 if (isset($_POST['newPassword'])) {
                     $allSuccess = $allSuccess && $subUser->updateSubUserPassword($_POST['newPassword']);
                 }
                 if (isset($_POST['twoFactorType']) && TwoFactor::isValidValue((int) $_POST['twoFactorType'])) {
                     $allSuccess = $allSuccess && $subUser->updateSubUserFactor($_POST['twoFactorType']);
                 }
                 if (isset($_POST['roles']) && is_array($_POST['roles'])) {
                     $allSuccess = $allSuccess && $subUser->updateSubUserRoles($_POST['roles']);
                 }
                 if ($allSuccess) {
                     echo json_encode(StatusReturn::S200(array('id' => $userID)), JSON_NUMERIC_CHECK);
                 } else {
                     echo json_encode(StatusReturn::E400('Some or All Changes Failed to Save!'));
                 }
             } else {
                 echo json_encode(StatusReturn::E400('User Name is not a child of this account!'));
             }
         }
     }
 }
 function post_xhr()
 {
     if ($this->checkAuth()) {
         if (isset($_POST['baseLang'], $_POST['twoFactorType']) && !empty($_POST['baseLang']) && TwoFactor::isValidValue($_POST['twoFactorType'], false)) {
             $headers = getallheaders();
             $newUser = new AuthUser();
             $newUser->loadUser(mb_strtolower($headers['Auth-User']));
             $packages = array();
             if (isset($_POST['packages'])) {
                 $packages = $_POST['packages'];
             }
             if ($newUser->setSettings($_POST['baseLang'], $_POST['twoFactorType'], $packages)) {
                 echo json_encode(StatusReturn::S200());
             } else {
                 echo json_encode(StatusReturn::E400('Failed to save settings!'));
             }
         } else {
             echo json_encode(StatusReturn::E400('Missing or bad data!'));
         }
     }
 }