Created
October 18, 2020 20:08
-
-
Save sijanec/109fe4d043bf2aabbb79e678349347a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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