├── .github └── workflows │ └── laravel.yml ├── .gitignore ├── auth-file ├── create-user.php ├── login-user.php └── read-user.php ├── composer.json ├── composer.lock ├── crud-file ├── create-product.php ├── delete-products.php ├── get-all-products.php ├── get-product-by-id.php ├── get-single-products.php └── update-products.php └── database └── Database.php /.github/workflows/laravel.yml: -------------------------------------------------------------------------------- 1 | name: Laravel 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | laravel-tests: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e 16 | with: 17 | php-version: '8.0' 18 | - uses: actions/checkout@v2 19 | - name: Copy .env 20 | run: php -r "file_exists('.env') || copy('.env.example', '.env');" 21 | - name: Install Dependencies 22 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist 23 | - name: Generate key 24 | run: php artisan key:generate 25 | - name: Directory Permissions 26 | run: chmod -R 777 storage bootstrap/cache 27 | - name: Create Database 28 | run: | 29 | mkdir -p database 30 | touch database/database.sqlite 31 | - name: Execute tests (Unit and Feature tests) via PHPUnit 32 | env: 33 | DB_CONNECTION: sqlite 34 | DB_DATABASE: database/database.sqlite 35 | run: vendor/bin/phpunit 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor -------------------------------------------------------------------------------- /auth-file/create-user.php: -------------------------------------------------------------------------------- 1 | name); 16 | $email = htmlentities($data->email); 17 | $password = htmlentities($data->password); 18 | $new_password = password_hash($password, PASSWORD_DEFAULT); 19 | // check user by email 20 | $obj->select("users", "email", null, "email='{$email}'", null, null); 21 | $is_email = $obj->getResult(); 22 | if (isset($is_email[0]['email']) == $email) { 23 | echo json_encode([ 24 | 'status' => 2, 25 | 'message' => 'Email already Exists', 26 | ]); 27 | }else{ 28 | $obj->insert('users', ['name' => $name, 'email' => $email, 'password' => $new_password, 'create_at' => date('Y-m-d')]); 29 | $data = $obj->getResult(); 30 | if ($data[0] == 1) { 31 | echo json_encode([ 32 | 'status' => 1, 33 | 'message' => 'User add Successfully', 34 | ]); 35 | } else { 36 | echo json_encode([ 37 | 'status' => 0, 38 | 'message' => 'Server Problem', 39 | ]); 40 | } 41 | } 42 | 43 | } else { 44 | echo json_encode([ 45 | 'status' => 0, 46 | 'message' => 'Access Denied', 47 | ]); 48 | } 49 | -------------------------------------------------------------------------------- /auth-file/login-user.php: -------------------------------------------------------------------------------- 1 | email); 16 | $password = htmlentities($data->password); 17 | 18 | $obj->select('users', '*', null, "email='{$email}'", null, null); 19 | $datas = $obj->getResult(); 20 | foreach ($datas as $data) { 21 | $id = $data['id']; 22 | $email = $data['email']; 23 | $name = $data['name']; 24 | // $password=$data['password']; 25 | if (!password_verify($password, $data['password'])) { 26 | echo json_encode([ 27 | 'status' => 0, 28 | 'message' => 'Invalid Carditional', 29 | ]); 30 | } else { 31 | $payload = [ 32 | 'iss' => "localhost", 33 | 'aud' => 'localhost', 34 | 'exp' => time() + 1000, //10 mint 35 | 'data' => [ 36 | 'id' => $id, 37 | 'name' => $name, 38 | 'email' => $email, 39 | ], 40 | ]; 41 | $secret_key = "Hilal ahmad khan"; 42 | $jwt = JWT::encode($payload, $secret_key, 'HS256'); 43 | echo json_encode([ 44 | 'status' => 1, 45 | 'jwt' => $jwt, 46 | 'message' => 'Login Successfully', 47 | ]); 48 | } 49 | } 50 | } else { 51 | echo json_encode([ 52 | 'status' => 0, 53 | 'message' => 'Access Denied', 54 | ]); 55 | } 56 | -------------------------------------------------------------------------------- /auth-file/read-user.php: -------------------------------------------------------------------------------- 1 | data; 22 | echo json_encode([ 23 | 'status' => 1, 24 | 'message' => $data, 25 | ]); 26 | }catch(Exception $e){ 27 | echo json_encode([ 28 | 'status' => 0, 29 | 'message' => $e->getMessage(), 30 | ]); 31 | } 32 | }else { 33 | echo json_encode([ 34 | 'status' => 0, 35 | 'message' => 'Access Denied', 36 | ]); 37 | } 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "firebase/php-jwt": "^5.5" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "06e298210783de079a2004dfded89190", 8 | "packages": [ 9 | { 10 | "name": "firebase/php-jwt", 11 | "version": "v5.5.1", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/firebase/php-jwt.git", 15 | "reference": "83b609028194aa042ea33b5af2d41a7427de80e6" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/firebase/php-jwt/zipball/83b609028194aa042ea33b5af2d41a7427de80e6", 20 | "reference": "83b609028194aa042ea33b5af2d41a7427de80e6", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.3.0" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": ">=4.8 <=9" 28 | }, 29 | "suggest": { 30 | "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" 31 | }, 32 | "type": "library", 33 | "autoload": { 34 | "psr-4": { 35 | "Firebase\\JWT\\": "src" 36 | } 37 | }, 38 | "notification-url": "https://packagist.org/downloads/", 39 | "license": [ 40 | "BSD-3-Clause" 41 | ], 42 | "authors": [ 43 | { 44 | "name": "Neuman Vong", 45 | "email": "neuman+pear@twilio.com", 46 | "role": "Developer" 47 | }, 48 | { 49 | "name": "Anant Narayanan", 50 | "email": "anant@php.net", 51 | "role": "Developer" 52 | } 53 | ], 54 | "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", 55 | "homepage": "https://github.com/firebase/php-jwt", 56 | "keywords": [ 57 | "jwt", 58 | "php" 59 | ], 60 | "support": { 61 | "issues": "https://github.com/firebase/php-jwt/issues", 62 | "source": "https://github.com/firebase/php-jwt/tree/v5.5.1" 63 | }, 64 | "time": "2021-11-08T20:18:51+00:00" 65 | } 66 | ], 67 | "packages-dev": [], 68 | "aliases": [], 69 | "minimum-stability": "stable", 70 | "stability-flags": [], 71 | "prefer-stable": false, 72 | "prefer-lowest": false, 73 | "platform": [], 74 | "platform-dev": [], 75 | "plugin-api-version": "2.2.0" 76 | } 77 | -------------------------------------------------------------------------------- /crud-file/create-product.php: -------------------------------------------------------------------------------- 1 | data->id; 23 | $title = $data->title; 24 | $content = $data->content; 25 | $price = $data->price; 26 | 27 | $obj->insert('products', ['title' => $title, 'user_id' => $id, 'content' => $content, 'price' => $price]); 28 | $result = $obj->getResult(); 29 | if ($result[0] == 1) { 30 | echo json_encode([ 31 | 'status' => 1, 32 | 'message' => "Product Add Successfully", 33 | ]); 34 | } else { 35 | echo json_encode([ 36 | 'status' => 0, 37 | 'message' => "Server Problem", 38 | ]); 39 | } 40 | } catch (Exception $e) { 41 | echo json_encode([ 42 | 'status' => 0, 43 | 'message' => $e->getMessage(), 44 | ]); 45 | } 46 | } else { 47 | echo json_encode([ 48 | 'status' => 0, 49 | 'message' => 'Access Denied', 50 | ]); 51 | } 52 | -------------------------------------------------------------------------------- /crud-file/delete-products.php: -------------------------------------------------------------------------------- 1 | id; 12 | $obj->delete("products", "id='{$id}'"); 13 | $result = $obj->getResult(); 14 | if ($result[0] == 1) { 15 | echo json_encode([ 16 | 'status' => 1, 17 | 'message' => "Product Delete Successfully", 18 | ]); 19 | } else { 20 | echo json_encode([ 21 | 'status' => 0, 22 | 'message' => "Server Problem", 23 | ]); 24 | } 25 | } else { 26 | echo json_encode([ 27 | 'status' => 0, 28 | 'message' => "Access Denied", 29 | ]); 30 | } 31 | -------------------------------------------------------------------------------- /crud-file/get-all-products.php: -------------------------------------------------------------------------------- 1 | select('products', "*", null, null, 'id DESC', null); 16 | $products = $obj->getResult(); 17 | if ($products) { 18 | echo json_encode([ 19 | 'status' => 1, 20 | 'message' => $products, 21 | ]); 22 | } else { 23 | echo json_encode([ 24 | 'status' => 0, 25 | 'message' => "server problem", 26 | ]); 27 | } 28 | } catch (Exception $e) { 29 | echo json_encode([ 30 | 'status' => 0, 31 | 'message' => $e->getMessage(), 32 | ]); 33 | } 34 | } else { 35 | echo json_encode([ 36 | 'status' => 0, 37 | 'message' => 'Access Denied', 38 | ]); 39 | } 40 | -------------------------------------------------------------------------------- /crud-file/get-product-by-id.php: -------------------------------------------------------------------------------- 1 | data->id; 23 | $obj->select('products',"*",null,"user_id='{$id}'",'id DESC',null); 24 | $products = $obj->getResult(); 25 | if ($products) { 26 | echo json_encode([ 27 | 'status' => 1, 28 | 'message' => $products, 29 | ]); 30 | } else { 31 | echo json_encode([ 32 | 'status' => 0, 33 | 'message' => "server problem", 34 | ]); 35 | } 36 | } catch (Exception $e) { 37 | echo json_encode([ 38 | 'status' => 0, 39 | 'message' => $e->getMessage(), 40 | ]); 41 | } 42 | } else { 43 | echo json_encode([ 44 | 'status' => 0, 45 | 'message' => 'Access Denied', 46 | ]); 47 | } 48 | -------------------------------------------------------------------------------- /crud-file/get-single-products.php: -------------------------------------------------------------------------------- 1 | id; 12 | $obj->select('products', "*", null, "id='{$id}'", null, null); 13 | $products = $obj->getResult(); 14 | echo json_encode([ 15 | 'status' => 1, 16 | 'message' => $products, 17 | ]); 18 | } else { 19 | echo json_encode([ 20 | 'status' => 0, 21 | 'message' => 'Access Denied', 22 | ]); 23 | } 24 | -------------------------------------------------------------------------------- /crud-file/update-products.php: -------------------------------------------------------------------------------- 1 | id; 12 | $title=$data->title; 13 | $content=$data->content; 14 | $price=$data->price; 15 | 16 | $obj->update('products', ['title'=>$title,'content'=>$content,'price'=>$price],"id='{$id}'"); 17 | $result=$obj->getResult(); 18 | if ($result[0] == 1) { 19 | echo json_encode([ 20 | 'status' => 1, 21 | 'message' => "Product Add Successfully", 22 | ]); 23 | } else { 24 | echo json_encode([ 25 | 'status' => 0, 26 | 'message' => "Server Problem", 27 | ]); 28 | } 29 | }else{ 30 | echo json_encode([ 31 | 'status' => 0, 32 | 'message' => "Access Denied", 33 | ]); 34 | } 35 | -------------------------------------------------------------------------------- /database/Database.php: -------------------------------------------------------------------------------- 1 | conn) { 17 | $this->mysqli = new mysqli($this->localhost, $this->username, $this->password, $this->database); 18 | $this->conn = true; 19 | 20 | if ($this->mysqli->connect_error) { 21 | array_push($this->result, $this->mysqli_connection_error); 22 | return false; 23 | } 24 | } else { 25 | return true; 26 | } 27 | } 28 | 29 | // insert data 30 | public function insert($table, $params = array()) 31 | { 32 | if ($this->tableExist($table)) { 33 | $table_column = implode(', ', array_keys($params)); 34 | $table_value = implode("', '", array_values($params)); 35 | 36 | $sql = "INSERT INTO $table ($table_column) VALUES ('$table_value')"; 37 | if ($this->mysqli->query($sql)) { 38 | array_push($this->result, true); 39 | return true; 40 | } else { 41 | array_push($this->result, false); 42 | return false; 43 | } 44 | } else { 45 | return false; 46 | } 47 | } 48 | 49 | // get data 50 | public function select($table, $row = "*", $join = null, $where = null, $order = null, $limit = null) 51 | { 52 | if ($this->tableExist($table)) { 53 | $sql = "SELECT $row FROM $table"; 54 | if ($join != null) { 55 | $sql .= " JOIN $join"; 56 | } 57 | if ($where != null) { 58 | $sql .= " WHERE $where"; 59 | } 60 | if ($order != null) { 61 | $sql .= " ORDER BY $order"; 62 | } 63 | if ($limit != null) { 64 | $sql .= " LIMIT $limit"; 65 | } 66 | $query = $this->mysqli->query($sql); 67 | if ($query) { 68 | $this->result = $query->fetch_all(MYSQLI_ASSOC); 69 | return true; 70 | } else { 71 | return false; 72 | } 73 | } else { 74 | return false; 75 | } 76 | } 77 | 78 | // update data 79 | public function update($table, $params = array(), $where = null) 80 | { 81 | if ($this->tableExist($table)) { 82 | $arg = array(); 83 | foreach ($params as $key => $val) { 84 | $arg[] = "$key = '{$val}'"; 85 | } 86 | $sql = "UPDATE $table SET " . implode(', ', $arg); 87 | if($where != null){ 88 | $sql .=" WHERE $where"; 89 | } 90 | if ($this->mysqli->query($sql)) { 91 | array_push($this->result, true); 92 | return true; 93 | } else { 94 | array_push($this->result, false); 95 | return false; 96 | } 97 | } else { 98 | return false; 99 | } 100 | } 101 | // delete data 102 | public function delete($table, $where = null) 103 | { 104 | if ($this->tableExist($table)) { 105 | $sql = "DELETE FROM $table"; 106 | if ($where != null) { 107 | $sql .= " WHERE $where"; 108 | } 109 | if ($this->mysqli->query($sql)) { 110 | array_push($this->result, true); 111 | return true; 112 | } else { 113 | array_push($this->result, false); 114 | return false; 115 | } 116 | } else { 117 | return false; 118 | } 119 | } 120 | // table exist 121 | private function tableExist($table) 122 | { 123 | $sql = "SHOW TABLES FROM $this->database LIKE '{$table}'"; 124 | $tableInDb = $this->mysqli->query($sql); 125 | if ($tableInDb) { 126 | if ($tableInDb->num_rows == 1) { 127 | return true; 128 | } else { 129 | array_push($this->result, $table . " Does not Exist"); 130 | } 131 | } else { 132 | return false; 133 | } 134 | } 135 | 136 | // get result 137 | public function getResult() 138 | { 139 | $val = $this->result; 140 | $this->result = array(); 141 | return $val; 142 | } 143 | 144 | // close the connection 145 | public function __destruct() 146 | { 147 | if ($this->conn) { 148 | if ($this->mysqli->close()) { 149 | $this->conn = false; 150 | return true; 151 | } 152 | } else { 153 | return false; 154 | } 155 | } 156 | } 157 | --------------------------------------------------------------------------------