Last active
November 30, 2023 05:15
-
-
Save hasinhayder/0b095766f7cc95b2d136b2ba6454df30 to your computer and use it in GitHub Desktop.
Revisions
-
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 32 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,47 +6,51 @@ $users = [ [ 'email' => '[email protected]', 'name' => 'Admin', 'password' => 'admin', 'role' => 'admin', 'token' => hash('sha256', 'admin') ], [ 'email' => '[email protected]', 'name' => 'John Doe', 'password' => 'john', 'role' => 'editor', 'token' => hash('sha256', 'john') ], [ 'email' => '[email protected]', 'name' => 'Jane Doe', 'password' => 'jane', 'role' => 'editor', 'token' => hash('sha256', 'jane') ] ]; // Check if data is sent as JSON payload or form data $jsonData = file_get_contents("php://input"); $data = !empty($jsonData) ? json_decode($jsonData, true) : $_POST; if (isset($data['email']) && isset($data['password'])) { $email = $data['email']; $password = $data['password']; foreach ($users as $user) { if ($user['email'] === $email && $user['password'] === $password) { echo json_encode([ 'success' => 1, 'name' => $user['name'], 'username' => $user['email'], 'role' => $user['role'], 'token' => $user['token'] ]); exit; } } } echo json_encode([ 'success' => 0, 'error' => 'Invalid credentials' ]); -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ <?php header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET'); header('Access-Control-Allow-Headers: Content-Type, Authorization'); $users = [ [ 'email'=>'[email protected]', -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ <?php header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); $users = [ [ 'email'=>'[email protected]', -
hasinhayder renamed this gist
Nov 30, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -40,11 +40,6 @@ exit; } } } echo json_encode([ -
hasinhayder revised this gist
Nov 30, 2023 . No changes.There are no files selected for viewing
-
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,19 +5,22 @@ 'email'=>'[email protected]', 'name'=>'Admin', 'password'=>'admin', 'role'=>'admin', 'token'=>hash('sha256', 'admin') ], [ 'email'=>'[email protected]', 'name'=>'John Doe', 'password'=>'john', 'role'=>'editor', 'token'=>hash('sha256', 'john') ], [ 'email'=>'[email protected]', 'name'=>'Jane Doe', 'password'=>'jane', 'role'=>'editor', 'token'=>hash('sha256', 'jane') ] ]; @@ -31,7 +34,8 @@ 'success'=>1, 'name'=>$user['name'], 'username'=>$user['email'], 'role'=>$user['role'], 'token'=>$user['token'] ]); exit; } -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ <?php header('Content-Type: application/json'); $users = [ [ 'email'=>'[email protected]', -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,5 +42,9 @@ 'success'=>0, 'error'=>'Invalid credentials' ]); } echo json_encode([ 'success'=>0, 'error'=>'Invalid credentials' ]); -
hasinhayder revised this gist
Nov 30, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,7 @@ if($user['email'] === $email && $user['password'] === $password){ echo json_encode([ 'success'=>1, 'name'=>$user['name'], 'username'=>$user['email'], 'role'=>$user['role'] ]); -
hasinhayder created this gist
Nov 30, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <?php //simple api endpoint for login with roles $users = [ [ 'email'=>'[email protected]', 'name'=>'Admin', 'password'=>'admin', 'role'=>'admin' ], [ 'email'=>'[email protected]', 'name'=>'John Doe', 'password'=>'john', 'role'=>'editor' ], [ 'email'=>'[email protected]', 'name'=>'Jane Doe', 'password'=>'jane', 'role'=>'editor' ] ]; if(isset($_POST['email']) && isset($_POST['password'])){ $email = $_POST['email']; $password = $_POST['password']; foreach($users as $user){ if($user['email'] === $email && $user['password'] === $password){ echo json_encode([ 'success'=>1, 'username'=>$user['email'], 'role'=>$user['role'] ]); exit; } } echo json_encode([ 'success'=>0, 'error'=>'Invalid credentials' ]); exit; }