Skip to content

Instantly share code, notes, and snippets.

@sijanec
Created October 18, 2020 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sijanec/109fe4d043bf2aabbb79e678349347a2 to your computer and use it in GitHub Desktop.
Save sijanec/109fe4d043bf2aabbb79e678349347a2 to your computer and use it in GitHub Desktop.
<?php
$data = json_decode(file_get_contents("php://input"), true);
if (strpos($data["username"], "@") !== false) {
$data["username"] = explode("@", $data["username"])[0];
}
$opts = array("http" =>
array(
"method" => "POST",
"content" => "username=" . urlencode($data["username"]) . "&password=" . urlencode($data["password"]),
),
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
);
$context = stream_context_create($opts);
$result = false;
$result = @file_get_contents("https://ucilnice.gimb.org/login/token.php?service=moodle_mobile_app", false, $context);
// exit($result);
$result = json_decode($result, true);
if (array_key_exists("error", $result)) {
//fail
http_response_code(401);
//error_log(print_r($result, true));
$user_response = array(
"success" => false,
"errorcode" => $result["errorcode"],
);
header("Content-Type: application/json");
echo json_encode($user_response);
die();
}
// success
$user_response = array(
"success" => true,
);
header("Content-Type: application/json");
echo json_encode($user_response);
die();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment