function get_xhr($authUser) { if ($this->checkAuth()) { if (!AuthUserData::userExist(mb_strtolower($authUser))) { echo json_encode(StatusReturn::S200()); } else { echo json_encode(StatusReturn::E400('Username Exists Already!')); } } }
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!')); } } } }
public function loadUser($authUser, $initialize = false) { if (AuthUserData::userExist($authUser)) { $this->loadUserForced($authUser); if (AuthUserData::userExistConfirmed($authUser)) { if ($initialize) { return true; } return $this->findCurrentSession(); } } return false; }