|
@@ -0,0 +1,44 @@
|
|
|
|
+<?php
|
|
|
|
+require_once("../vendor/autoload.php");
|
|
|
|
+
|
|
|
|
+use MongoDB\Client;
|
|
|
|
+use MongoDB\BSON\ObjectId;
|
|
|
|
+use Firebase\JWT\JWT;
|
|
|
|
+use Firebase\JWT\Key;
|
|
|
|
+//print_r($_REQUEST);
|
|
|
|
+$userInput = file_get_contents('php://input');
|
|
|
|
+$userInputData = json_decode($userInput, true);
|
|
|
|
+if ($userInputData !== null) {
|
|
|
|
+ $client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
|
|
|
|
+ $collection = $client->selectCollection('kpmaster', 'kpu');
|
|
|
|
+ $cursor = $collection->find(
|
|
|
|
+ [
|
|
|
|
+ 'em' => $userInputData["email"],
|
|
|
|
+ 'ps' => md5($userInputData["password"])
|
|
|
|
+ ],
|
|
|
|
+ ['projection' => [
|
|
|
|
+ '_id' => 1,
|
|
|
|
+ 'fn' => 1,
|
|
|
|
+ ],]
|
|
|
|
+ );
|
|
|
|
+ $outputArray = iterator_to_array($cursor);
|
|
|
|
+ $refinedArray = json_decode(json_encode($outputArray), true);
|
|
|
|
+ $id = $refinedArray[0]["_id"]['$oid'];
|
|
|
|
+ $key = '97eda3db6f898bfb1f821178d1c27064';
|
|
|
|
+ $payload = [
|
|
|
|
+ 'iss' => 'http://kittipoyi.com',
|
|
|
|
+ 'aud' => 'http://kittipoyi.com',
|
|
|
|
+ 'iat' => time(),
|
|
|
|
+ 'nbf' => time(),
|
|
|
|
+ 'kpid' => $id
|
|
|
|
+ ];
|
|
|
|
+ $jwt = JWT::encode($payload, $key, 'HS256');
|
|
|
|
+ $message['status'] = true;
|
|
|
|
+ $message['token'] = $jwt;
|
|
|
|
+ $message['statusMessage'] = "Login Sucessfull";
|
|
|
|
+} else {
|
|
|
|
+ $message['status'] = false;
|
|
|
|
+ $message['statusCode'] = "KP001";
|
|
|
|
+ $message['statusMessage'] = "Data Not Received";
|
|
|
|
+}
|
|
|
|
+echo json_encode($message);
|