*/ header('Content-type: application/json'); require_once ROOT_PATH . 'includes/load_ad_usernames.php'; // Check requests if (!\Utilities\Requests::HasRequest(['username', 'password'])) { die(ModelResponse::InvalidRequest()); } extract($_REQUEST, EXTR_SKIP); $matches = array(); // Username sanitation preg_match('/[A-Za-z0-9_\\.]+/', $username, $matches); if (sizeof($matches) > 0) { $username = $matches[0]; } // end of username sanitation if (!has_account($username)) { die(new ModelResponse(false, 'User is not registered')); } // Otherwise, proceed with LDAP authentication $ldapresource = ldap_connect("ldap://svg.openit.local", 389) or die("Unable to connect to ldap://svg.openit.local:389"); //$result = ldap_bind("svg.openit.local"); ob_start(); $bind = ldap_bind($ldapresource, sprintf("*****@*****.**", $username), trim($password)); $buffer = ob_get_clean(); if ($bind == true) { // Get user data $user = \Models\User::FindUsername($username); if ($user instanceof \Models\User && $user->getUsername() != null) { Utilities\Session::LogIn($user->getUsername()); } die(new ModelResponse(true, 'Authentication success', $user));
* (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * [REST_META] * * username (string) * */ header('Content-type: application/json'); require_once ROOT_PATH . 'includes/load_ad_usernames.php'; // var_dump($_REQUEST); // die(); if (!isset($_REQUEST['username'])) { die(ModelResponse::InvalidRequest()); } $username = trim($_REQUEST['username']); $matches = array(); preg_match('/[A-Za-z0-9_\\.]+/', $username, $matches); if (sizeof($matches) > 0) { $username = strtolower($matches[0]); } $exists = has_account($username); echo new ModelResponse($exists, $exists ? 'Username exists' : 'User is not registered');