<?php /* Debug mode */ require "Constants/debug_mode.php"; require "Classes/StompAPI.php"; // Requests from the same server don't have a HTTP_ORIGIN header if (!array_key_exists('HTTP_ORIGIN', $_SERVER)) { $_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME']; } try { $API = new StompAPI($_REQUEST['request'], $_SERVER['HTTP_ORIGIN']); echo $API->processAPI() . "\n"; } catch (Exception $e) { echo json_encode(array('error' => $e->getMessage())); }
* */ <?php require "Conn.php"; require "StompAPI.php"; $email = htmlentities($_POST["email"]); $password = htmlentities($_POST["password"]); $returnValue = array(); if (empty($email) || empty($password)) { $returnValue["status"] = "error"; $returnValue["message"] = "Missing required field"; echo json_encode($returnValue); return; } $api = new StompAPI(); $api->openConnection(); $userDetails = $api->getUserDetails($email); if (!empty($userDetails)) { $returnValue["status"] = "error"; $returnValue["message"] = "User already exists"; echo json_encode($returnValue); return; } // user password cannot be read by developer $secure_password = md5($password); $result = $api->registerUser($email, $secure_password); if ($result) { $returnValue["status"] = "Success"; $returnValue["message"] = "User is registered"; echo json_encode($returnValue);
/* * userLogin.php * */ <?php require "Classes/Conn.php"; require "Classes/StompAPI.php"; $email = htmlentities($_POST["email"]); $password = htmlentities($_POST["password"]); $returnValue = array(); if (empty($email) || empty($password)) { $returnValue["status"] = "error"; $returnValue["message"] = "Missing required field"; echo json_encode($returnValue); return; } $api = new StompAPI(); $api->openConnection(); $userDetails = $api->getUserDetailsWithPassword($email, md5($password)); if (!empty($userDetails)) { $returnValue["status"] = "Success"; $returnValue["message"] = "User is registered"; } else { $returnValue["status"] = "error"; $returnValue["message"] = "User is not found"; } echo json_encode($returnValue); $api->closeConnection();