Explorar o código

Provider Login Added

Anand Ayyappan hai 1 ano
pai
achega
7742ae6a9b
Modificáronse 1 ficheiros con 44 adicións e 0 borrados
  1. 44 0
      api/v1/loginProvider/index.php

+ 44 - 0
api/v1/loginProvider/index.php

@@ -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);