From bc5c461ea54fd0d7a51d3236da833ec9105be588 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Sat, 16 Jul 2022 20:00:32 +0800 Subject: [PATCH 01/11] Create .env.example --- laravel-crud/.env.example | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 laravel-crud/.env.example diff --git a/laravel-crud/.env.example b/laravel-crud/.env.example new file mode 100644 index 0000000..a3596e8 --- /dev/null +++ b/laravel-crud/.env.example @@ -0,0 +1,58 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel_test +DB_USERNAME=root +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailhog +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_HOST= +PUSHER_PORT=443 +PUSHER_SCHEME=https +PUSHER_APP_CLUSTER=mt1 + +VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +VITE_PUSHER_HOST="${PUSHER_HOST}" +VITE_PUSHER_PORT="${PUSHER_PORT}" +VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" +VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" \ No newline at end of file From 6b4711c21f41caab4970ee9ff7146f90ca55baa3 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Sun, 17 Jul 2022 02:03:54 +0800 Subject: [PATCH 02/11] update files --- .../app/Http/Controllers/ApiController.php | 42 +++++++++++++++---- laravel-crud/routes/api.php | 3 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/laravel-crud/app/Http/Controllers/ApiController.php b/laravel-crud/app/Http/Controllers/ApiController.php index 9f98f49..73b7c3e 100644 --- a/laravel-crud/app/Http/Controllers/ApiController.php +++ b/laravel-crud/app/Http/Controllers/ApiController.php @@ -101,20 +101,46 @@ public function authenticate(Request $request) $password = DB::table('cruds')->where('password', '=', $request->input('password')) ->exists(); - if ($userExists) + //echo $request->input('username'); + //if($request->input('username') == "admin") { + //echo "admin"; + + + //} + if ($request->input('username') == "admin" && $request->input('password') == "@admin") { - if ($password) { - echo "Success"; - } else { - echo "wrong username or password"; - } + return response() + ->json(["message" => "success"], 200); + } else { - echo "wrong username or password"; - } + if ($userExists) + { + + if ($password) + { + //echo "Success"; + return response()->json(["message" => "success"], 201); + } + else + { + return response() + ->json(["message" => "not found"], 404); + //echo "wrong username or password"; + + } + } + else + { + //echo "wrong username or password"; + return response() + ->json(["message" => "not found"], 404); + } + + } } } \ No newline at end of file diff --git a/laravel-crud/routes/api.php b/laravel-crud/routes/api.php index 8eff0ec..05332c3 100644 --- a/laravel-crud/routes/api.php +++ b/laravel-crud/routes/api.php @@ -23,4 +23,5 @@ Route::post('cruds/create', 'App\Http\Controllers\ApiController@createCRUD'); Route::put('cruds/{id}', 'App\Http\Controllers\ApiController@updateCRUD'); Route::delete('cruds/{id}','App\Http\Controllers\ApiController@deleteCRUD'); -Route::post('authenticate/','App\Http\Controllers\ApiController@authenticate'); \ No newline at end of file +Route::post('authenticate/','App\Http\Controllers\ApiController@authenticate'); +//Route::get('authenticate/','App\Http\Controllers\ApiController@authenticate'); \ No newline at end of file From af08faaa28f71aa48870ab32491a3e5ec9fcf151 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Sun, 17 Jul 2022 02:14:39 +0800 Subject: [PATCH 03/11] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 92a9411..8f2db30 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # Laravel Test CRUD Create and Consume Endpoints +## Run The Project +You can download this as zip file, then extract. + +Run `cmd` set the directory to the project. + +Run `composer install` + +change `.env.example` to `.env` and make necessary changes to your database + +`php artisan serve` + ## Setup For Windows 10, download XAMPP, then download `composer`. @@ -242,3 +253,5 @@ Route::delete('cruds/{id}','App\Http\Controllers\ApiController@deleteCRUD'); `PUT http://127.0.0.1:8000/api/cruds/[id]` `DELETE http://127.0.0.1:8000/api/cruds/id` + +`POST http://127.0.0.1:8000/api/authenticate` From 947a950bc47cdad1757d7dd90f611d13588be8a9 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Sun, 17 Jul 2022 15:28:51 +0800 Subject: [PATCH 04/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f2db30..de1c516 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Create and Consume Endpoints ## Run The Project -You can download this as zip file, then extract. +You can download this as a zip file, then extract. Run `cmd` set the directory to the project. From 79342bf41bd597d8e6b1f5b4feca201f99908e55 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Sun, 17 Jul 2022 15:30:29 +0800 Subject: [PATCH 05/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de1c516..175c387 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Create and Consume Endpoints ## Run The Project You can download this as a zip file, then extract. -Run `cmd` set the directory to the project. +Run `cmd` and set the directory to the project. -Run `composer install` +Run `composer install`. change `.env.example` to `.env` and make necessary changes to your database From 48dc0c9ac388dc14bac5ccb1c63d2bd130fc22f2 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Tue, 19 Jul 2022 15:47:57 +0800 Subject: [PATCH 06/11] Update README.md --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 175c387..46fb414 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,12 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; + use App\Models\Crud; +use App\Models\User; + +use Illuminate\Support\Facades\DB; class ApiController extends Controller { @@ -134,7 +139,7 @@ class ApiController extends Controller { $cruds = Crud::get()->toJson(JSON_PRETTY_PRINT); return response($cruds, 200); - //endpoint GET http://127.0.0.1:8000/api/cruds; + //endpoint GET http://127.0.0.1:8000/api/cruds'; } @@ -142,12 +147,12 @@ class ApiController extends Controller { $cruds = new Crud; - $cruds->crud1 = $request->crud1; - $cruds->crud2 = $request->crud2; + $cruds->username = $request->username; + $cruds->password = $request->password; $cruds->save(); return response() - ->json(["message" => "crud record created"], 201); + ->json(["message" => "user created"], 201); //endpoint POST http://127.0.0.1:8000/api/cruds/create @@ -160,7 +165,7 @@ class ApiController extends Controller $cruds = Crud::where('id', $id)->get() ->toJson(JSON_PRETTY_PRINT); return response($cruds, 200); - //endpoint GET http://127.0.0.1:8000/api/cruds/[id]; + //endpoint GET http://127.0.0.1:8000/api/cruds/[id]'; } else @@ -174,8 +179,8 @@ class ApiController extends Controller if (Crud::where('id', $id)->exists()) { $cruds = Crud::find($id); - $cruds->crud1 = is_null($request->crud1) ? $cruds->crud1 : $request->crud1; - $cruds->crud2 = is_null($request->crud2) ? $cruds->crud2 : $request->crud2; + $cruds->username = is_null($request->username) ? $cruds->username : $request->username; + $cruds->password = is_null($request->password) ? $cruds->password : $request->password; $cruds->save(); return response() @@ -209,6 +214,58 @@ class ApiController extends Controller //endpoint DELETE http://127.0.0.1:8000/api/cruds/id } + + public function authenticate(Request $request) + { + + $userExists = DB::table('cruds')->where('username', '=', $request->input('username')) + ->exists(); + + $password = DB::table('cruds')->where('password', '=', $request->input('password')) + ->exists(); + + //echo $request->input('username'); + //if($request->input('username') == "admin") { + //echo "admin"; + + + //} + if ($request->input('username') == "admin" && $request->input('password') == "@admin") + { + + return response() + ->json(["message" => "success"], 200); + + } + else + { + + if ($userExists) + { + + if ($password) + { + //echo "Success"; + return response()->json(["message" => "success"], 201); + } + else + { + return response() + ->json(["message" => "not found"], 404); + //echo "wrong username or password"; + + } + } + else + { + //echo "wrong username or password"; + return response() + ->json(["message" => "not found"], 404); + } + + } + } + } ``` From 57ab43900fc43114c466faf7e47ae0c79a595461 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Tue, 19 Jul 2022 15:48:57 +0800 Subject: [PATCH 07/11] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46fb414..7980976 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,10 @@ return new class extends Migration */ public function up() { - Schema::create('cruds', function (Blueprint $table) { + Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('crud1'); - $table->string('crud2'); + $table->name(); + $table->password(); $table->timestamps(); }); } @@ -106,7 +106,7 @@ return new class extends Migration */ public function down() { - Schema::dropIfExists('cruds'); + Schema::dropIfExists('users'); } }; ``` From 370ca156b246abe5f70acd3aa517d6e4c3e38a59 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Tue, 19 Jul 2022 15:50:17 +0800 Subject: [PATCH 08/11] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 7980976..22180b4 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,8 @@ class Crud extends Model { protected $table = 'cruds'; - protected $fillable = ['crud1', 'crud2']; + protected $fillable = ['username', 'password']; } - ``` then `create_cruds_table.php` From 8451136e5984f9814840f3d0149da7fc6bde0ba3 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Fri, 4 Aug 2023 20:24:29 +0800 Subject: [PATCH 09/11] Create temp.txt --- laravel-crud/.devcontainer/temp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 laravel-crud/.devcontainer/temp.txt diff --git a/laravel-crud/.devcontainer/temp.txt b/laravel-crud/.devcontainer/temp.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/laravel-crud/.devcontainer/temp.txt @@ -0,0 +1 @@ + From 7c1f2f1cba285426ea495ad1959397f997e1ec31 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Fri, 4 Aug 2023 20:24:59 +0800 Subject: [PATCH 10/11] Add files via upload --- laravel-crud/.devcontainer/Dockerfile | 56 +++++++++++++++++++ laravel-crud/.devcontainer/devcontainer.json | 38 +++++++++++++ laravel-crud/.devcontainer/docker-compose.yml | 22 ++++++++ 3 files changed, 116 insertions(+) create mode 100644 laravel-crud/.devcontainer/Dockerfile create mode 100644 laravel-crud/.devcontainer/devcontainer.json create mode 100644 laravel-crud/.devcontainer/docker-compose.yml diff --git a/laravel-crud/.devcontainer/Dockerfile b/laravel-crud/.devcontainer/Dockerfile new file mode 100644 index 0000000..12dfbb4 --- /dev/null +++ b/laravel-crud/.devcontainer/Dockerfile @@ -0,0 +1,56 @@ +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +FROM php:7-cli + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux, +# this user's GID/UID must match your local user UID/GID to avoid permission issues +# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See +# https://aka.ms/vscode-remote/containers/non-root-user for details. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + && apt-get -y install curl git iproute2 procps lsb-release unzip zip openssl gnupg \ + + # Install xdebug + #&& yes | pecl install xdebug \ + #&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ + #&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ + #&& echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ + + # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. + && groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # [Optional] Add sudo support for the non-root user + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Install Composer from: https://hub.docker.com/_/composer +COPY --from=composer /usr/bin/composer /usr/bin/composer +RUN echo 'export PATH="$PATH:$HOME/.composer/vendor/bin:/root/.composer/vendor/bin:vendor/bin"' >> /root/.bashrc +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - +RUN apt-get install -y nodejs +RUN apt-get install -y libzip-dev \ + && docker-php-ext-configure zip \ + && docker-php-ext-install zip \ + && docker-php-ext-install bcmath mysqli pdo pdo_mysql +RUN su $USERNAME -c "composer global require laravel/installer" +RUN echo "alias art='php artisan'" >> /root/.bashrc && \ + echo "alias serve='php artisan serve --port=8000 --host=0.0.0.0'" >> /root/.bashrc && \ + echo "alias ls='ls -B -h --color=auto -ltr'" >> /root/.bashrc && \ + echo "alias _='sudo'" >> /root/.bashrc && \ + echo "alias apt='sudo apt'" >> /root/.bashrc && \ + echo "alias apt-get='sudo apt-get'" >> /root/.bashrc + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= diff --git a/laravel-crud/.devcontainer/devcontainer.json b/laravel-crud/.devcontainer/devcontainer.json new file mode 100644 index 0000000..0ffe880 --- /dev/null +++ b/laravel-crud/.devcontainer/devcontainer.json @@ -0,0 +1,38 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at +// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/php-7 +{ + "name": "PHP 7", + "dockerComposeFile": "docker-compose.yml", + "service": "php", + // Use 'settings' to set *default* container specific settings.json values on container create. + // You can edit these settings after create using File > Preferences > Settings > Remote. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "phpSniffer.executablesFolder": "./vendor/bin/", + "phpSniffer.run": "onSave" + }, + + // Uncomment the next line if you want to publish any ports. + "forwardPorts": [8000], + + // Uncomment the next line to run commands after the container is created. + "postCreateCommand": "", + + // Uncomment the next line to use a non-root user. On Linux, this will prevent + // new files getting created as root, but you may need to update the USER_UID + // and USER_GID in .devcontainer/Dockerfile to match your user if not 1000. + "runArgs": [ + "-u", "vscode" , + "-v", "${env:HOME}${env:USERPROFILE}/.ssh:/home/vscode/.ssh" + ], + + + // Add the IDs of extensions you want installed when the container is created in the array below. + "extensions": [ + "bmewburn.vscode-intelephense-client", + "MehediDracula.php-namespace-resolver", + "MS-vsliveshare.vsliveshare-pack", + "EditorConfig.EditorConfig", + "wongjn.php-sniffer" + ] +} \ No newline at end of file diff --git a/laravel-crud/.devcontainer/docker-compose.yml b/laravel-crud/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..2c7cdb4 --- /dev/null +++ b/laravel-crud/.devcontainer/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3" + +services: + php: + build: . + volumes: + - ..:/workspace:cached + ports: + # For use with PHP (e.g. `php -S localhost:8080`) + - "8000:8000" + command: sleep infinity + mariadb: + image: mariadb:10.4 + expose: + # Expose mariadb port to php service (Access as hostname "mariadb" from within php container) + - "3306" + # Uncomment to allow access to mariadb from external tools + # ports: + # - "3306:3306" + environment: + MYSQL_ROOT_PASSWORD: secret + MYSQL_DATABASE: laravel From 7025cdbab8c70b7e7bb8915541d0c2fd74e31779 Mon Sep 17 00:00:00 2001 From: jdevstatic Date: Fri, 4 Aug 2023 20:25:21 +0800 Subject: [PATCH 11/11] Delete temp.txt --- laravel-crud/.devcontainer/temp.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 laravel-crud/.devcontainer/temp.txt diff --git a/laravel-crud/.devcontainer/temp.txt b/laravel-crud/.devcontainer/temp.txt deleted file mode 100644 index 8b13789..0000000 --- a/laravel-crud/.devcontainer/temp.txt +++ /dev/null @@ -1 +0,0 @@ -