├── .cloud ├── docker │ ├── Dockerfile │ └── Dockerfile.prod └── nginx │ └── nginx.conf ├── .dockerignore ├── .editorconfig ├── .env.example ├── .env.gitlab ├── .env.testing ├── .gitattributes ├── .github ├── FUNDING.yml └── renovate.json ├── .gitignore ├── .gitlab-ci.yml ├── .insomnia ├── README.md └── todolist-backend-laravel.json ├── .php_cs ├── LICENSE ├── README.md ├── app ├── Broadcasting │ └── TaskChannel.php ├── Console │ ├── Commands │ │ └── StatsTasks.php │ └── Kernel.php ├── Events │ ├── TaskCreated.php │ ├── TaskDeleted.php │ ├── TaskUpdated.php │ └── TasksDeleted.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ └── VerificationController.php │ │ ├── Controller.php │ │ └── V1 │ │ │ ├── Auth │ │ │ ├── AuthController.php │ │ │ └── RegisterController.php │ │ │ ├── TasksController.php │ │ │ └── UsersController.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── CheckForMaintenanceMode.php │ │ ├── EncryptCookies.php │ │ ├── ForceJson.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php │ ├── Requests │ │ ├── Task │ │ │ ├── TaskRequest.php │ │ │ └── UpdateTaskRequest.php │ │ └── User │ │ │ ├── RegisterRequest.php │ │ │ └── UserRequest.php │ └── Resources │ │ ├── TaskResource.php │ │ └── UserResource.php ├── Models │ ├── Task.php │ └── User.php ├── Policies │ ├── TaskPolicy.php │ └── UserPolicy.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php └── Rules │ └── CurrentPassword.php ├── artisan ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── cors.php ├── database.php ├── filesystems.php ├── hashing.php ├── jwt.php ├── logging.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ ├── TaskFactory.php │ └── UserFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2018_01_14_192421_create_tasks_table.php │ └── 2018_04_09_203418_update_date_to_boolean_for_completed_tasks.php └── seeds │ ├── DatabaseSeeder.php │ └── dev │ └── DevDatabaseSeeder.php ├── docker-compose.yml ├── docs ├── .gitignore ├── README.md ├── docker-compose.yml ├── docs │ ├── .vuepress │ │ ├── config.js │ │ ├── public │ │ │ ├── _redirects │ │ │ └── screenshot.png │ │ └── styles │ │ │ └── palette.styl │ ├── README.md │ └── api │ │ ├── README.md │ │ ├── tasks.md │ │ └── users.md ├── netlify.toml ├── package.json └── yarn.lock ├── hosts.example ├── phpunit.xml ├── playbook.yml ├── public ├── .htaccess ├── favicon.ico ├── index.php ├── robots.txt └── web.config ├── resources └── lang │ ├── en │ ├── auth.php │ ├── pagination.php │ ├── passwords.php │ └── validation.php │ └── vendor │ └── backup │ └── en │ └── notifications.php ├── roles ├── app │ ├── tasks │ │ └── main.yml │ └── templates │ │ └── .env.j2 └── docker │ └── tasks │ └── main.yml ├── routes ├── api.php ├── channels.php └── console.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore └── tests ├── CreatesApplication.php ├── Feature └── V1 │ ├── Auth │ └── AuthTest.php │ ├── TaskTest.php │ └── UserTest.php ├── TestCase.php └── Unit └── TaskTest.php /.cloud/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.3-fpm-stretch 2 | LABEL maintainer="guillaumebriday@gmail.com" 3 | 4 | # Installing dependencies 5 | RUN apt-get update && apt-get install -y --no-install-recommends \ 6 | build-essential \ 7 | mysql-client \ 8 | libpng-dev \ 9 | libzip-dev \ 10 | locales \ 11 | zip 12 | 13 | # Clear cache 14 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* 15 | 16 | # Installing extensions 17 | RUN docker-php-ext-install pdo_mysql gd mbstring zip opcache 18 | 19 | # Installing composer 20 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 21 | 22 | # Changing Workdir 23 | WORKDIR /var/www 24 | -------------------------------------------------------------------------------- /.cloud/docker/Dockerfile.prod: -------------------------------------------------------------------------------- 1 | # Nginx 2 | FROM nginx:latest as nginx 3 | 4 | LABEL traefik.enable="true" 5 | LABEL traefik.http.services.todolist.loadbalancer.server.port="8000" 6 | LABEL traefik.http.routers.todolist.entrypoints="websecure" 7 | LABEL traefik.http.routers.todolist.rule="Host(`todolist-api.guillaumebriday.me`)" 8 | 9 | COPY .cloud/nginx/nginx.conf /etc/nginx/conf.d/default.conf 10 | COPY public /var/www/public 11 | 12 | # Composer 13 | FROM composer:1.10 as vendor 14 | 15 | COPY database/ database/ 16 | 17 | COPY composer.json composer.json 18 | COPY composer.lock composer.lock 19 | 20 | RUN composer install \ 21 | --ignore-platform-reqs \ 22 | --no-interaction \ 23 | --no-plugins \ 24 | --no-scripts \ 25 | --prefer-dist 26 | 27 | # PHP 28 | FROM php:7.3-fpm-stretch as application 29 | 30 | LABEL maintainer="hello@guillaumebriday.fr" 31 | 32 | WORKDIR /var/www 33 | 34 | # Installing dependencies 35 | RUN apt-get update && apt-get install -y \ 36 | build-essential \ 37 | mysql-client \ 38 | libpng-dev \ 39 | libzip-dev \ 40 | locales \ 41 | zip 42 | 43 | # Clear cache 44 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* 45 | 46 | # Installing extensions 47 | RUN docker-php-ext-install pdo_mysql gd mbstring zip opcache 48 | 49 | COPY . /var/www 50 | COPY --from=vendor /app/vendor/ /var/www/vendor/ 51 | 52 | RUN chown -R www-data:www-data \ 53 | /var/www/storage \ 54 | /var/www/bootstrap/cache 55 | -------------------------------------------------------------------------------- /.cloud/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 8000; 3 | index index.php index.html index.htm; 4 | root /var/www/public; # default Laravel's entry point for all requests 5 | 6 | access_log /var/log/nginx/access.log; 7 | error_log /var/log/nginx/error.log; 8 | 9 | location / { 10 | # try to serve file directly, fallback to index.php 11 | try_files $uri /index.php?$args; 12 | } 13 | 14 | location ~ \.php$ { 15 | fastcgi_index index.php; 16 | fastcgi_pass todolist-server:9000; # address of a fastCGI server 17 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 18 | fastcgi_param PATH_INFO $fastcgi_path_info; 19 | include fastcgi_params; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | docker-compose.yml 3 | node_modules/ 4 | vendor/ 5 | storage/tmp/ 6 | storage/logs/ 7 | storage/framework/cache/ 8 | storage/framework/sessions/ 9 | storage/framework/views/ 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.yml] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | JWT_SECRET= 5 | JWT_TTL=2880 6 | APP_DEBUG=true 7 | APP_URL=http://localhost:8000 8 | 9 | LOG_CHANNEL=single 10 | 11 | DB_CONNECTION=mysql 12 | DB_HOST=mysql 13 | DB_DATABASE=laravel-todolist 14 | DB_USERNAME=root 15 | DB_PASSWORD=secret 16 | 17 | BROADCAST_DRIVER=log 18 | CACHE_DRIVER=file 19 | QUEUE_CONNECTION=sync 20 | SESSION_DRIVER=file 21 | SESSION_LIFETIME=120 22 | 23 | REDIS_HOST=127.0.0.1 24 | REDIS_PASSWORD=null 25 | REDIS_PORT=6379 26 | 27 | MAIL_DRIVER=smtp 28 | MAIL_HOST=mailtrap.io 29 | MAIL_PORT=2525 30 | MAIL_USERNAME=null 31 | MAIL_PASSWORD=null 32 | MAIL_ENCRYPTION=null 33 | 34 | AWS_ACCESS_KEY_ID= 35 | AWS_SECRET_ACCESS_KEY= 36 | AWS_DEFAULT_REGION=us-east-1 37 | 38 | PUSHER_APP_ID= 39 | PUSHER_APP_KEY= 40 | PUSHER_APP_SECRET= 41 | PUSHER_APP_CLUSTER= 42 | 43 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 44 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 45 | 46 | GITHUB_ID= 47 | GITHUB_SECRET= 48 | GITHUB_URL= 49 | 50 | TWITTER_ID= 51 | TWITTER_SECRET= 52 | TWITTER_URL= 53 | -------------------------------------------------------------------------------- /.env.gitlab: -------------------------------------------------------------------------------- 1 | APP_ENV=testing 2 | APP_KEY=base64:HGT19Mfm6j77W2N6K3GXqJqqNgUromHg41lRFHesEJc= 3 | 4 | LOG_CHANNEL=single 5 | 6 | DB_HOST=mysql 7 | DB_DATABASE=testing 8 | DB_USERNAME=root 9 | DB_PASSWORD=testing 10 | -------------------------------------------------------------------------------- /.env.testing: -------------------------------------------------------------------------------- 1 | APP_KEY=base64:HGT19Mfm6j77W2N6K3GXqJqqNgUromHg41lRFHesEJc= 2 | 3 | DB_HOST=mysql-test 4 | DB_DATABASE=testing 5 | DB_USERNAME=root 6 | DB_PASSWORD=secret 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: guillaumebriday 2 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | ":automergeDigest", 5 | ":automergePatch", 6 | ":automergeMinor", 7 | ":automergeBranchPush", 8 | ":skipStatusChecks", 9 | "schedule:monthly" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | /.idea 7 | /.vagrant 8 | Homestead.json 9 | Homestead.yaml 10 | npm-debug.log 11 | yarn-error.log 12 | .env 13 | .php_cs.cache 14 | /storage/debugbar 15 | /storage/tmp 16 | /log 17 | hosts 18 | .phpunit.result.cache 19 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: "php:7.3-fpm-stretch" 2 | 3 | stages: 4 | - test 5 | - build 6 | - deploy 7 | 8 | variables: 9 | MYSQL_DATABASE: testing 10 | MYSQL_USER: root 11 | MYSQL_ROOT_PASSWORD: testing 12 | IMAGE_TAG_APPLICATION: registry.gitlab.com/guillaumebriday/todolist-backend-laravel/application:${CI_COMMIT_REF_SLUG} 13 | IMAGE_TAG_NGINX: registry.gitlab.com/guillaumebriday/todolist-backend-laravel/nginx:${CI_COMMIT_REF_SLUG} 14 | REGISTRY_URL: registry.gitlab.com 15 | 16 | cache: 17 | paths: 18 | - vendor/ 19 | 20 | .setup_test_env: &setup_test_env 21 | before_script: 22 | # Install node and some other deps 23 | - apt-get update -yqq 24 | - apt-get install zip unzip git libjpeg-dev libpng-dev libfreetype6-dev -yqq --no-install-recommends 25 | - docker-php-ext-install gd pdo_mysql 26 | - curl -sS https://getcomposer.org/installer | php 27 | - php composer.phar install --no-progress --no-interaction --optimize-autoloader 28 | - cp .env.gitlab .env.testing 29 | 30 | # Stage: Test 31 | phpunit: 32 | <<: *setup_test_env 33 | services: 34 | - mysql:5.7 35 | stage: test 36 | script: 37 | - vendor/bin/phpunit --testdox 38 | 39 | php-cs-fixer: 40 | <<: *setup_test_env 41 | stage: test 42 | script: 43 | - vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --dry-run --diff 44 | 45 | # Stage: Build 46 | .setup_build_env: &setup_build_env 47 | stage: build 48 | image: docker:stable 49 | services: 50 | - docker:dind 51 | only: 52 | - master 53 | 54 | build_application_image: 55 | <<: *setup_build_env 56 | script: 57 | - docker build -f .cloud/docker/Dockerfile.prod --target application -t ${IMAGE_TAG_APPLICATION} . 58 | - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} 59 | - docker push ${IMAGE_TAG_APPLICATION} 60 | 61 | build_nginx_image: 62 | <<: *setup_build_env 63 | script: 64 | - docker build -f .cloud/docker/Dockerfile.prod --target nginx -t ${IMAGE_TAG_NGINX} . 65 | - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} 66 | - docker push ${IMAGE_TAG_NGINX} 67 | 68 | # Stage: deploy 69 | .setup_deploy_env: &setup_deploy_env 70 | image: kroniak/ssh-client 71 | before_script: 72 | - eval $(ssh-agent -s) 73 | - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null 74 | - mkdir -p ~/.ssh 75 | - chmod 700 ~/.ssh 76 | - ssh-keyscan -H '51.15.244.250' >> ~/.ssh/known_hosts 77 | 78 | deploy_prod: 79 | <<: *setup_deploy_env 80 | stage: deploy 81 | script: 82 | # log into Docker registry 83 | - ssh root@51.15.244.250 " 84 | docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${REGISTRY_URL} && 85 | docker pull ${IMAGE_TAG_APPLICATION} && 86 | docker pull ${IMAGE_TAG_NGINX} && 87 | docker stop todolist-nginx || true && 88 | docker stop todolist-server || true && 89 | docker run --restart unless-stopped --name todolist-server --link todolist-db --env-file /var/www/todolist-backend/.env -d ${IMAGE_TAG_APPLICATION} && 90 | docker run --restart unless-stopped -d --name todolist-nginx --link todolist-server ${IMAGE_TAG_NGINX}" 91 | 92 | only: 93 | - master 94 | when: manual 95 | environment: 96 | name: production 97 | url: https://todolist-api.guillaumebriday.me/ 98 | -------------------------------------------------------------------------------- /.insomnia/README.md: -------------------------------------------------------------------------------- 1 | # Insomnia Workspace 2 | 3 | This is my [Insomnia](https://insomnia.rest/) Workspace to work with this API. 4 | 5 | You can import the `todolist-backend-laravel.json` file or from [this url](https://raw.githubusercontent.com/guillaumebriday/todolist-backend-laravel/master/.insomnia/todolist-backend-laravel.json). 6 | 7 | ## Setup 8 | 9 | You need to setup two [environment variables](https://support.insomnia.rest/article/18-environment-variables) before starting. 10 | 11 | The `base_url` which is already defined with the default location of this project, but you can change it as you wish. 12 | 13 | And the `token_api`, that you can retrieve with the `User/Login` request. Copy the value of the `access_token` in the response preview and past it as the value of the `token_api` environment variable. 14 | -------------------------------------------------------------------------------- /.insomnia/todolist-backend-laravel.json: -------------------------------------------------------------------------------- 1 | { 2 | "_type": "export", 3 | "__export_format": 3, 4 | "__export_date": "2018-08-25T21:44:04.919Z", 5 | "__export_source": "insomnia.desktop.app:v6.0.2", 6 | "resources": [ 7 | { 8 | "_id": "wrk_5c851061be424397981acc9d202933f7", 9 | "created": 1535209774459, 10 | "description": "", 11 | "modified": 1535209774459, 12 | "name": "Todolist", 13 | "parentId": null, 14 | "_type": "workspace" 15 | }, 16 | { 17 | "_id": "env_55bbab11c25a43129bfe12df688ed612", 18 | "color": null, 19 | "created": 1535209774470, 20 | "data": {}, 21 | "isPrivate": false, 22 | "metaSortKey": 1535209774470, 23 | "modified": 1535211281006, 24 | "name": "New Environment", 25 | "parentId": "wrk_5c851061be424397981acc9d202933f7", 26 | "_type": "environment" 27 | }, 28 | { 29 | "_id": "jar_7429efc60a2948c6ab34954d84a2962b", 30 | "cookies": [], 31 | "created": 1535209774473, 32 | "modified": 1535209774473, 33 | "name": "Default Jar", 34 | "parentId": "wrk_5c851061be424397981acc9d202933f7", 35 | "_type": "cookie_jar" 36 | }, 37 | { 38 | "_id": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 39 | "created": 1535209893635, 40 | "description": "", 41 | "environment": {}, 42 | "metaSortKey": -1535209893635, 43 | "modified": 1535209893635, 44 | "name": "User", 45 | "parentId": "wrk_5c851061be424397981acc9d202933f7", 46 | "_type": "request_group" 47 | }, 48 | { 49 | "_id": "fld_446bcfe88fbe4503993ac1cd364b0cde", 50 | "created": 1535209899665, 51 | "description": "", 52 | "environment": {}, 53 | "metaSortKey": -1535209899665, 54 | "modified": 1535210232114, 55 | "name": "Tasks", 56 | "parentId": "wrk_5c851061be424397981acc9d202933f7", 57 | "_type": "request_group" 58 | }, 59 | { 60 | "_id": "env_6b33b2ccf5234829b835086f7e3724ea", 61 | "color": "#7d69cb", 62 | "created": 1535209971504, 63 | "data": { 64 | "base_url": "http://localhost:8000/api/v1", 65 | "token_api": "" 66 | }, 67 | "isPrivate": false, 68 | "metaSortKey": 1535209971504, 69 | "modified": 1535233429258, 70 | "name": "Development", 71 | "parentId": "env_55bbab11c25a43129bfe12df688ed612", 72 | "_type": "environment" 73 | }, 74 | { 75 | "_id": "req_0e1fcd0071d1449d892e1605ccb10532", 76 | "authentication": {}, 77 | "body": { 78 | "mimeType": "application/json", 79 | "text": "{\n \"email\": \"darthvader@deathstar.ds\",\n \"password\": \"4nak1n\"\n}" 80 | }, 81 | "created": 1535209830512, 82 | "description": "", 83 | "headers": [ 84 | { 85 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 86 | "name": "Content-Type", 87 | "value": "application/json" 88 | } 89 | ], 90 | "isPrivate": false, 91 | "metaSortKey": -1535209830512, 92 | "method": "POST", 93 | "modified": 1535233420039, 94 | "name": "Login", 95 | "parameters": [], 96 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 97 | "settingDisableRenderRequestBody": false, 98 | "settingEncodeUrl": true, 99 | "settingMaxTimelineDataSize": 1000, 100 | "settingRebuildPath": true, 101 | "settingSendCookies": true, 102 | "settingStoreCookies": true, 103 | "url": "{{ base_url }}/auth/login", 104 | "_type": "request" 105 | }, 106 | { 107 | "_id": "req_1b1bbde347d344a1afc8248d7ed93962", 108 | "authentication": {}, 109 | "body": { 110 | "mimeType": "application/json", 111 | "text": "{\n \"name\": \"Anakin\",\n \"email\": \"darthvader@deathstar.ds\",\n \"password\": \"4nak1n\",\n \"password_confirmation\": \"4nak1n\"\n}\n" 112 | }, 113 | "created": 1535210750389, 114 | "description": "", 115 | "headers": [ 116 | { 117 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 118 | "name": "Content-Type", 119 | "value": "application/json" 120 | } 121 | ], 122 | "isPrivate": false, 123 | "metaSortKey": -1535209830462, 124 | "method": "POST", 125 | "modified": 1535233410082, 126 | "name": "Registrer", 127 | "parameters": [], 128 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 129 | "settingDisableRenderRequestBody": false, 130 | "settingEncodeUrl": true, 131 | "settingMaxTimelineDataSize": 1000, 132 | "settingRebuildPath": true, 133 | "settingSendCookies": true, 134 | "settingStoreCookies": true, 135 | "url": "{{ base_url }}/auth/login", 136 | "_type": "request" 137 | }, 138 | { 139 | "_id": "req_23ca5c6ee6fc4919afa2715a435a9867", 140 | "authentication": { 141 | "token": "{{ token_api }}", 142 | "type": "bearer" 143 | }, 144 | "body": {}, 145 | "created": 1535210785294, 146 | "description": "", 147 | "headers": [ 148 | { 149 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 150 | "name": "Content-Type", 151 | "value": "application/json" 152 | } 153 | ], 154 | "isPrivate": false, 155 | "metaSortKey": -1535209830487, 156 | "method": "DELETE", 157 | "modified": 1535211265147, 158 | "name": "Logout", 159 | "parameters": [], 160 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 161 | "settingDisableRenderRequestBody": false, 162 | "settingEncodeUrl": true, 163 | "settingMaxTimelineDataSize": 1000, 164 | "settingRebuildPath": true, 165 | "settingSendCookies": true, 166 | "settingStoreCookies": true, 167 | "url": "{{ base_url }}/auth/logout", 168 | "_type": "request" 169 | }, 170 | { 171 | "_id": "req_aad0334ca5c148e9bb1b8caa88f550aa", 172 | "authentication": { 173 | "token": "{{ token_api }}", 174 | "type": "bearer" 175 | }, 176 | "body": {}, 177 | "created": 1535210823125, 178 | "description": "", 179 | "headers": [ 180 | { 181 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 182 | "name": "Content-Type", 183 | "value": "application/json" 184 | } 185 | ], 186 | "isPrivate": false, 187 | "metaSortKey": -1535209830412, 188 | "method": "GET", 189 | "modified": 1535233417266, 190 | "name": "Me", 191 | "parameters": [], 192 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 193 | "settingDisableRenderRequestBody": false, 194 | "settingEncodeUrl": true, 195 | "settingMaxTimelineDataSize": 1000, 196 | "settingRebuildPath": true, 197 | "settingSendCookies": true, 198 | "settingStoreCookies": true, 199 | "url": "{{ base_url }}/auth/me", 200 | "_type": "request" 201 | }, 202 | { 203 | "_id": "req_e018c28c385741bfb1f5800a143f39ea", 204 | "authentication": { 205 | "token": "{{ token_api }}", 206 | "type": "bearer" 207 | }, 208 | "body": {}, 209 | "created": 1535210847403, 210 | "description": "", 211 | "headers": [ 212 | { 213 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 214 | "name": "Content-Type", 215 | "value": "application/json" 216 | } 217 | ], 218 | "isPrivate": false, 219 | "metaSortKey": -1535209830362, 220 | "method": "POST", 221 | "modified": 1535233417874, 222 | "name": "Refresh token", 223 | "parameters": [], 224 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 225 | "settingDisableRenderRequestBody": false, 226 | "settingEncodeUrl": true, 227 | "settingMaxTimelineDataSize": 1000, 228 | "settingRebuildPath": true, 229 | "settingSendCookies": true, 230 | "settingStoreCookies": true, 231 | "url": "{{ base_url }}/auth/refresh", 232 | "_type": "request" 233 | }, 234 | { 235 | "_id": "req_d7fd174be2b049dd8e4fc072687d731a", 236 | "authentication": { 237 | "token": "{{ token_api }}", 238 | "type": "bearer" 239 | }, 240 | "body": { 241 | "mimeType": "application/json", 242 | "text": "{\n \"name\": \"Ben\",\n \"email\": \"ben@kenobi.jo\",\n \"current_password\": \"4nak1n\",\n \"password\": \"4_n3w_h0p3\",\n \"password_confirmation\": \"4_n3w_h0p3\"\n}\n" 243 | }, 244 | "created": 1535210869403, 245 | "description": "", 246 | "headers": [ 247 | { 248 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 249 | "name": "Content-Type", 250 | "value": "application/json" 251 | } 252 | ], 253 | "isPrivate": false, 254 | "metaSortKey": -1535209830312, 255 | "method": "PUT", 256 | "modified": 1535233418285, 257 | "name": "Update your account", 258 | "parameters": [], 259 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 260 | "settingDisableRenderRequestBody": false, 261 | "settingEncodeUrl": true, 262 | "settingMaxTimelineDataSize": 1000, 263 | "settingRebuildPath": true, 264 | "settingSendCookies": true, 265 | "settingStoreCookies": true, 266 | "url": "{{ base_url }}/users/1", 267 | "_type": "request" 268 | }, 269 | { 270 | "_id": "req_c161c039b0d44264ab96ca67ccafba6f", 271 | "authentication": { 272 | "token": "{{ token_api }}", 273 | "type": "bearer" 274 | }, 275 | "body": {}, 276 | "created": 1535210925031, 277 | "description": "", 278 | "headers": [ 279 | { 280 | "id": "pair_6a68f2145df345329a992a73c5b5bffd", 281 | "name": "Content-Type", 282 | "value": "application/json" 283 | } 284 | ], 285 | "isPrivate": false, 286 | "metaSortKey": -1535209830262, 287 | "method": "DELETE", 288 | "modified": 1535233418881, 289 | "name": "Delete your account", 290 | "parameters": [], 291 | "parentId": "fld_3aec1347fb194a6d8c5197855f5aeaf7", 292 | "settingDisableRenderRequestBody": false, 293 | "settingEncodeUrl": true, 294 | "settingMaxTimelineDataSize": 1000, 295 | "settingRebuildPath": true, 296 | "settingSendCookies": true, 297 | "settingStoreCookies": true, 298 | "url": "{{ base_url }}/users/1", 299 | "_type": "request" 300 | }, 301 | { 302 | "_id": "req_6f0b6c7d8325460d91129c7566600a4f", 303 | "authentication": { 304 | "prefix": "", 305 | "token": "{{ token_api }}", 306 | "type": "bearer" 307 | }, 308 | "body": {}, 309 | "created": 1535210221391, 310 | "description": "", 311 | "headers": [], 312 | "isPrivate": false, 313 | "metaSortKey": -1535210294293.5, 314 | "method": "GET", 315 | "modified": 1535233420779, 316 | "name": " Retrieve all tasks", 317 | "parameters": [], 318 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 319 | "settingDisableRenderRequestBody": false, 320 | "settingEncodeUrl": true, 321 | "settingMaxTimelineDataSize": 1000, 322 | "settingRebuildPath": true, 323 | "settingSendCookies": true, 324 | "settingStoreCookies": true, 325 | "url": "{{ base_url }}/tasks", 326 | "_type": "request" 327 | }, 328 | { 329 | "_id": "req_a6861dce1ee94177aa7a76fe7f854d86", 330 | "authentication": { 331 | "prefix": "", 332 | "token": "{{ token_api }}", 333 | "type": "bearer" 334 | }, 335 | "body": {}, 336 | "created": 1535210380574, 337 | "description": "", 338 | "headers": [], 339 | "isPrivate": false, 340 | "metaSortKey": -1535210062402.75, 341 | "method": "GET", 342 | "modified": 1535233429592, 343 | "name": "Retrieve a task", 344 | "parameters": [], 345 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 346 | "settingDisableRenderRequestBody": false, 347 | "settingEncodeUrl": true, 348 | "settingMaxTimelineDataSize": 1000, 349 | "settingRebuildPath": true, 350 | "settingSendCookies": true, 351 | "settingStoreCookies": true, 352 | "url": "{{ base_url }}/tasks/1", 353 | "_type": "request" 354 | }, 355 | { 356 | "_id": "req_39bb686233a643cb9bf58d4f92680863", 357 | "authentication": { 358 | "prefix": "", 359 | "token": "{{ token_api }}", 360 | "type": "bearer" 361 | }, 362 | "body": { 363 | "mimeType": "application/json", 364 | "text": "{\n \"title\": \"A newly created task\"\n}\n\t" 365 | }, 366 | "created": 1535210545300, 367 | "description": "", 368 | "headers": [ 369 | { 370 | "id": "pair_4eafa9807814408bbb1f5f4798dc4c15", 371 | "name": "Content-Type", 372 | "value": "application/json" 373 | } 374 | ], 375 | "isPrivate": false, 376 | "metaSortKey": -1535209946457.375, 377 | "method": "POST", 378 | "modified": 1535233399957, 379 | "name": "Store a task", 380 | "parameters": [], 381 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 382 | "settingDisableRenderRequestBody": false, 383 | "settingEncodeUrl": true, 384 | "settingMaxTimelineDataSize": 1000, 385 | "settingRebuildPath": true, 386 | "settingSendCookies": true, 387 | "settingStoreCookies": true, 388 | "url": "{{ base_url }}/tasks", 389 | "_type": "request" 390 | }, 391 | { 392 | "_id": "req_e0bcbf50056b4ca5b83d364ad890423b", 393 | "authentication": { 394 | "prefix": "", 395 | "token": "{{ token_api }}", 396 | "type": "bearer" 397 | }, 398 | "body": { 399 | "mimeType": "application/json", 400 | "text": "{\n \"title\": \"An updated task\",\n \"is_completed\": true\n}\n" 401 | }, 402 | "created": 1535210653072, 403 | "description": "", 404 | "headers": [ 405 | { 406 | "id": "pair_4eafa9807814408bbb1f5f4798dc4c15", 407 | "name": "Content-Type", 408 | "value": "application/json" 409 | } 410 | ], 411 | "isPrivate": false, 412 | "metaSortKey": -1535209888484.6875, 413 | "method": "PUT", 414 | "modified": 1535233396916, 415 | "name": "Update a task", 416 | "parameters": [], 417 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 418 | "settingDisableRenderRequestBody": false, 419 | "settingEncodeUrl": true, 420 | "settingMaxTimelineDataSize": 1000, 421 | "settingRebuildPath": true, 422 | "settingSendCookies": true, 423 | "settingStoreCookies": true, 424 | "url": "{{ base_url }}/tasks/236", 425 | "_type": "request" 426 | }, 427 | { 428 | "_id": "req_903e4a3ee3de4e99a8ff2025c472765c", 429 | "authentication": { 430 | "prefix": "", 431 | "token": "{{ token_api }}", 432 | "type": "bearer" 433 | }, 434 | "body": {}, 435 | "created": 1535210701989, 436 | "description": "", 437 | "headers": [ 438 | { 439 | "id": "pair_4eafa9807814408bbb1f5f4798dc4c15", 440 | "name": "Content-Type", 441 | "value": "application/json" 442 | } 443 | ], 444 | "isPrivate": false, 445 | "metaSortKey": -1535209859498.3438, 446 | "method": "DELETE", 447 | "modified": 1535233401920, 448 | "name": "Delete a task", 449 | "parameters": [], 450 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 451 | "settingDisableRenderRequestBody": false, 452 | "settingEncodeUrl": true, 453 | "settingMaxTimelineDataSize": 1000, 454 | "settingRebuildPath": true, 455 | "settingSendCookies": true, 456 | "settingStoreCookies": true, 457 | "url": "{{ base_url }}/tasks/1", 458 | "_type": "request" 459 | }, 460 | { 461 | "_id": "req_8329457446e848b2b68870b6436ccd6b", 462 | "authentication": { 463 | "prefix": "", 464 | "token": "{{ token_api }}", 465 | "type": "bearer" 466 | }, 467 | "body": {}, 468 | "created": 1535210728191, 469 | "description": "", 470 | "headers": [ 471 | { 472 | "id": "pair_4eafa9807814408bbb1f5f4798dc4c15", 473 | "name": "Content-Type", 474 | "value": "application/json" 475 | } 476 | ], 477 | "isPrivate": false, 478 | "metaSortKey": -1535209845005.1719, 479 | "method": "DELETE", 480 | "modified": 1535233404200, 481 | "name": "Delete all completed tasks", 482 | "parameters": [], 483 | "parentId": "fld_446bcfe88fbe4503993ac1cd364b0cde", 484 | "settingDisableRenderRequestBody": false, 485 | "settingEncodeUrl": true, 486 | "settingMaxTimelineDataSize": 1000, 487 | "settingRebuildPath": true, 488 | "settingSendCookies": true, 489 | "settingStoreCookies": true, 490 | "url": "{{ base_url }}/tasks", 491 | "_type": "request" 492 | } 493 | ] 494 | } -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | exclude('bootstrap/cache') 8 | ->exclude('storage') 9 | ->exclude('vendor') 10 | ->in(__DIR__) 11 | ->ignoreDotFiles(true) 12 | ->ignoreVCS(true); 13 | 14 | return Config::create() 15 | ->setRules([ 16 | '@PSR2' => true, 17 | 'array_syntax' => ['syntax' => 'short'], 18 | 'ordered_imports' => ['sortAlgorithm' => 'alpha'], 19 | 'no_unused_imports' => true, 20 | 'no_useless_else' => true, 21 | 'no_useless_return' => true, 22 | 'no_superfluous_elseif' => true, 23 | 'no_unneeded_curly_braces' => true, 24 | 'phpdoc_order' => true, 25 | 'phpdoc_types_order' => true, 26 | 'align_multiline_comment' => true, 27 | ]) 28 | ->setUsingCache(false) 29 | ->setFinder($finder); 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Guillaume Briday 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Todolist-backend Application 2 | 3 | [![pipeline status](https://gitlab.com/guillaumebriday/todolist-backend-laravel/badges/master/pipeline.svg)](https://gitlab.com/guillaumebriday/todolist-backend-laravel/pipelines) 4 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/guillaumebriday) 5 | 6 | > Backend for https://github.com/guillaumebriday/todolist-frontend-vuejs app, built for a serie of articles on my [blog](https://guillaumebriday.fr/). 7 | 8 | The purpose of this repository is to provide API with [Laravel 5.8](http://laravel.com/) and connecting JavaScript front-end frameworks like [Vue.js 2](https://vuejs.org) or other clients to them. 9 | 10 | Beside Laravel, this project uses other tools like : 11 | 12 | - [PHP-CS-Fixer](https://github.com/FriendsOfPhp/PHP-CS-Fixer) 13 | - [Travis CI](https://travis-ci.org/) 14 | - [tymon/jwt-auth](https://github.com/tymondesigns/jwt-auth) 15 | - [spatie/laravel-cors](https://github.com/spatie/laravel-cors) 16 | - [spatie/laravel-backup](https://github.com/spatie/laravel-backup) 17 | - [Pusher](https://pusher.com/) 18 | 19 | ## Installation 20 | 21 | Development environment requirements : 22 | - [Docker](https://www.docker.com) >= 17.06 CE 23 | - [Docker Compose](https://docs.docker.com/compose/install/) 24 | 25 | Setting up your development environment on your local machine : 26 | ``` 27 | $ git clone https://github.com/guillaumebriday/todolist-backend-laravel.git 28 | $ cd todolist-backend-laravel 29 | $ cp .env.example .env 30 | $ docker-compose run --rm --no-deps todolist-server composer install 31 | $ docker-compose run --rm --no-deps todolist-server php artisan key:generate 32 | $ docker-compose run --rm --no-deps todolist-server php artisan jwt:secret 33 | $ docker-compose up -d 34 | ``` 35 | 36 | ## Before starting 37 | You need to run the migrations : 38 | ``` 39 | $ docker-compose run --rm todolist-server php artisan migrate 40 | ``` 41 | 42 | Seed the database : 43 | ``` 44 | $ docker-compose run --rm todolist-server php artisan db:seed 45 | ``` 46 | 47 | This will create a new user that you can use to sign in : 48 | ``` 49 | Email : darthvader@deathstar.ds 50 | Password : 4nak1n 51 | ``` 52 | 53 | ## Useful commands 54 | Running tests : 55 | ``` 56 | $ docker-compose run --rm todolist-server ./vendor/bin/phpunit --cache-result --order-by=defects --stop-on-defect 57 | ``` 58 | 59 | Running php-cs-fixer : 60 | ``` 61 | $ docker-compose run --rm --no-deps todolist-server ./vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --dry-run --diff 62 | ``` 63 | 64 | Generating backup : 65 | ``` 66 | $ docker-compose run --rm todolist-server php artisan backup:run --only-db 67 | ``` 68 | 69 | Discover package 70 | ``` 71 | $ docker-compose run --rm --no-deps todolist-server php artisan package:discover 72 | ``` 73 | 74 | Generating fake data : 75 | ```bash 76 | $ docker-compose run --rm todolist-server php artisan db:seed --class=DevDatabaseSeeder 77 | ``` 78 | 79 | ## Accessing the API 80 | 81 | Clients can access to the REST API. API requests require authentication via JWT. You can create a new one with you credentials. 82 | 83 | ```bash 84 | $ curl -X POST http://localhost:8000/api/v1/auth/login -d "email=your_email&password=your_password" 85 | ``` 86 | 87 | Then, you can use this token either as url parameter or in Authorization header : 88 | 89 | ```bash 90 | # Url parameter 91 | curl -X POST http://localhost:8000/api/v1/auth/me?token=your_jwt_token_here 92 | 93 | # Authorization Header 94 | curl -X POST --header "Authorization: Bearer your_jwt_token_here" http://localhost:8000/api/v1/auth/me 95 | ``` 96 | 97 | API are prefixed by ```api``` and the API version number like so ```v1```. 98 | 99 | Do not forget to set the ```X-Requested-With``` header to ```XMLHttpRequest```. Otherwise, Laravel won't recognize the call as an AJAX request. 100 | 101 | To list all the available routes for API : 102 | 103 | ```bash 104 | $ docker-compose run --rm --no-deps todolist-server php artisan route:list 105 | ``` 106 | 107 | You can import my [Insomnia](https://insomnia.rest/) workspace configured to work with the API : `.insomnia/todolist-backend-laravel.json`. 108 | 109 | ## Broadcasting & WebSockets 110 | 111 | Before using WebSockets, you need to set the ```PUSHER``` related keys in your .env file. 112 | 113 | You could find this keys on [https://pusher.com/](https://pusher.com/). 114 | 115 | You also need to set the ```BROADCAST_DRIVER``` key : 116 | 117 | ``` 118 | BROADCAST_DRIVER=pusher 119 | ``` 120 | 121 | ## Deploy in production 122 | 123 | You can serve your application with [nginx](https://nginx.org/) in production. 124 | 125 | You can deploy this application with [Ansible](https://www.ansible.com). 126 | 127 | Copy the hosts example file and change the values to your needs : 128 | 129 | ```bash 130 | $ cp hosts.example hosts 131 | ``` 132 | 133 | Setup your variables in the ```playbook.yml```. 134 | 135 | And then run : 136 | 137 | ```bash 138 | $ ansible-playbook -i hosts playbook.yml 139 | ``` 140 | 141 | Build the images : 142 | ```bash 143 | $ docker build -f .cloud/docker/Dockerfile.prod --target application -t todolist-backend-laravel-application . 144 | 145 | $ docker build -f .cloud/docker/Dockerfile.prod --target nginx -t todolist-backend-laravel-nginx . 146 | ``` 147 | 148 | Run the containers : 149 | ```bash 150 | $ docker run --rm -it --name todolist-server --link some-mysql:mysql --env-file .env --network todolist-backend todolist-backend-laravel-application 151 | 152 | $ docker run --rm -it -p 8000:8000 --network todolist-backend todolist-backend-laravel-nginx 153 | ``` 154 | 155 | ## Consume the API 156 | 157 | The application is available on [https://todolist-api.guillaumebriday.me/api/v1/](https://todolist-api.guillaumebriday.me/api/v1/). 158 | 159 | The documentation is available in the `docs` folder or on [https://todolist-docs.guillaumebriday.me](https://todolist-docs.guillaumebriday.me). 160 | 161 | You can consume the API with any client. 162 | 163 | Some examples of projects who use this API: 164 | + [https://github.com/guillaumebriday/todolist-frontend-vuejs](https://github.com/guillaumebriday/todolist-frontend-vuejs) (Vue.js) 165 | + [https://github.com/benoitrongeard/todolist-angular](https://github.com/benoitrongeard/todolist-angular) (Angular 6) 166 | 167 | Don't forget to let me know if you want to add your project to this list ! 168 | 169 | ## More details 170 | 171 | More details are available on my blog post : [https://guillaumebriday.fr/laravel-vuejs-faire-une-todo-list-partie-1-presentation-et-objectifs](https://guillaumebriday.fr/laravel-vuejs-faire-une-todo-list-partie-1-presentation-et-objectifs) (French). 172 | 173 | ## Contributing 174 | 175 | Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome. 176 | 177 | ## License 178 | 179 | This project is released under the [MIT](http://opensource.org/licenses/MIT) license. 180 | -------------------------------------------------------------------------------- /app/Broadcasting/TaskChannel.php: -------------------------------------------------------------------------------- 1 | id == $id; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Console/Commands/StatsTasks.php: -------------------------------------------------------------------------------- 1 | pluck('tasks_count')->average() 56 | ], 57 | [ 58 | 'New tasks last week', 59 | Task::where('created_at', '>=', now()->subWeek())->count() 60 | ], 61 | [ 62 | 'New tasks last month', 63 | Task::where('created_at', '>=', now()->subMonth())->count() 64 | ], 65 | [ 66 | 'New tasks last year', 67 | Task::where('created_at', '>=', now()->subYear())->count() 68 | ], 69 | [ 70 | 'Tasks with due_at date', 71 | Task::whereNotNull('due_at')->count() 72 | ], 73 | [ 74 | 'Tasks without due_at date', 75 | Task::whereNull('due_at')->count() 76 | ], 77 | [ 78 | 'Tasks completed', 79 | Task::completed()->count() 80 | ], 81 | [ 82 | 'Tasks not completed', 83 | Task::whereIsCompleted(false)->count() 84 | ] 85 | ]; 86 | 87 | $this->table($headers, $data); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('backup:clean')->daily()->at('01:00'); 28 | $schedule->command('backup:run')->daily()->at('02:00'); 29 | } 30 | 31 | /** 32 | * Register the commands for the application. 33 | * 34 | * @return void 35 | */ 36 | protected function commands() 37 | { 38 | $this->load(__DIR__.'/Commands'); 39 | 40 | require base_path('routes/console.php'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Events/TaskCreated.php: -------------------------------------------------------------------------------- 1 | task = $task; 26 | } 27 | 28 | /** 29 | * Get the channels the event should broadcast on. 30 | * 31 | * @return array|\Illuminate\Broadcasting\PrivateChannel 32 | */ 33 | public function broadcastOn() 34 | { 35 | return new PrivateChannel("App.User." . auth()->user()->id); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Events/TaskDeleted.php: -------------------------------------------------------------------------------- 1 | task = $task; 26 | } 27 | 28 | /** 29 | * Get the channels the event should broadcast on. 30 | * 31 | * @return array|\Illuminate\Broadcasting\PrivateChannel 32 | */ 33 | public function broadcastOn() 34 | { 35 | return new PrivateChannel("App.User." . auth()->user()->id); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Events/TaskUpdated.php: -------------------------------------------------------------------------------- 1 | task = $task; 26 | } 27 | 28 | /** 29 | * Get the channels the event should broadcast on. 30 | * 31 | * @return array|\Illuminate\Broadcasting\PrivateChannel 32 | */ 33 | public function broadcastOn() 34 | { 35 | return new PrivateChannel("App.User." . auth()->user()->id); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Events/TasksDeleted.php: -------------------------------------------------------------------------------- 1 | user()->id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 38 | $this->middleware('signed')->only('verify'); 39 | $this->middleware('throttle:6,1')->only('verify', 'resend'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | json([ 21 | 'access_token' => $token, 22 | 'token_type' => 'bearer', 23 | 'expires_in' => auth()->factory()->getTTL() * 60, 24 | 'user_id' => auth()->user()->id 25 | ]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Controllers/V1/Auth/AuthController.php: -------------------------------------------------------------------------------- 1 | validate([ 18 | 'email' => 'required|email', 19 | 'password' => 'required|string', 20 | ]); 21 | 22 | if (! $token = auth()->attempt($credentials)) { 23 | return response()->json([ 24 | 'errors' => [ 25 | 'email' => [__('auth.failed')] 26 | ] 27 | ], 401); 28 | } 29 | 30 | return $this->respondWithToken($token); 31 | } 32 | 33 | /** 34 | * Get the authenticated User 35 | */ 36 | public function me(): UserResource 37 | { 38 | return new UserResource(auth()->user()); 39 | } 40 | 41 | /** 42 | * Log the user out (Invalidate the token) 43 | */ 44 | public function logout(): JsonResponse 45 | { 46 | auth()->logout(); 47 | 48 | return response()->json(['message' => 'Successfully logged out']); 49 | } 50 | 51 | /** 52 | * Refresh a token. 53 | */ 54 | public function refresh(): JsonResponse 55 | { 56 | return $this->respondWithToken(auth()->refresh()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/Http/Controllers/V1/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | respondWithToken( 18 | auth()->login( 19 | User::create($request->validated()) 20 | ) 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Controllers/V1/TasksController.php: -------------------------------------------------------------------------------- 1 | authorizeResource(Task::class, 'task'); 28 | } 29 | 30 | /** 31 | * Display a listing of the resource. 32 | */ 33 | public function index(): ResourceCollection 34 | { 35 | return TaskResource::collection( 36 | auth()->user()->tasks()->get() 37 | ); 38 | } 39 | 40 | /** 41 | * Display the specified resource. 42 | */ 43 | public function show(Task $task): TaskResource 44 | { 45 | return new TaskResource($task); 46 | } 47 | 48 | /** 49 | * Store a newly created resource in storage. 50 | */ 51 | public function store(TaskRequest $request): TaskResource 52 | { 53 | $task = auth()->user()->tasks()->create($request->validated()); 54 | 55 | broadcast(new TaskCreated($task))->toOthers(); 56 | 57 | return new TaskResource($task); 58 | } 59 | 60 | /** 61 | * Update the specified resource in storage. 62 | */ 63 | public function update(UpdateTaskRequest $request, Task $task): TaskResource 64 | { 65 | $task->update($request->validated()); 66 | 67 | broadcast(new TaskUpdated($task))->toOthers(); 68 | 69 | return new TaskResource($task); 70 | } 71 | 72 | /** 73 | * Remove the specified resource from storage. 74 | */ 75 | public function destroy(Request $request, Task $task): Response 76 | { 77 | broadcast(new TaskDeleted($task))->toOthers(); 78 | 79 | $task->delete(); 80 | 81 | return response()->noContent(); 82 | } 83 | 84 | /** 85 | * Remove the all completed tasks from storage. 86 | */ 87 | public function deleteCompletedTasks(Request $request): Response 88 | { 89 | broadcast(new TasksDeleted)->toOthers(); 90 | 91 | auth()->user()->tasks()->completed()->delete(); 92 | 93 | return response()->noContent(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/Http/Controllers/V1/UsersController.php: -------------------------------------------------------------------------------- 1 | update($request->validated()); 21 | 22 | return new UserResource($user); 23 | } 24 | 25 | /** 26 | * Remove the specified resource from storage. 27 | */ 28 | public function destroy(Request $request, User $user): Response 29 | { 30 | DB::transaction(function () use ($user) { 31 | $user->tasks()->delete(); 32 | $user->delete(); 33 | }); 34 | 35 | return response()->noContent(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 33 | 'throttle:60,1', 34 | 'bindings', 35 | ], 36 | ]; 37 | 38 | /** 39 | * The application's route middleware. 40 | * 41 | * These middleware may be assigned to groups or used individually. 42 | * 43 | * @var array 44 | */ 45 | protected $routeMiddleware = [ 46 | 'auth' => \App\Http\Middleware\Authenticate::class, 47 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 48 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 49 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 50 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 51 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 52 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 53 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 54 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 55 | ]; 56 | } 57 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | headers->set('Accept', 'application/json'); 16 | 17 | return $next($request); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/home'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | 'required|string|max:255', 24 | 'due_at' => 'nullable|date', 25 | 'is_completed' => 'boolean', 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Requests/Task/UpdateTaskRequest.php: -------------------------------------------------------------------------------- 1 | 'string|max:255', 22 | ]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Requests/User/RegisterRequest.php: -------------------------------------------------------------------------------- 1 | 'required|alpha_dash|max:255', 24 | 'email' => 'required|email|max:255|unique:users', 25 | 'password' => 'required|string|min:8|confirmed', 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Requests/User/UserRequest.php: -------------------------------------------------------------------------------- 1 | 'alpha_dash|max:255', 26 | 'email' => [ 27 | 'email', 28 | 'max:255', 29 | Rule::unique('users')->ignore(auth()->user()->id), 30 | ], 31 | 'current_password' => [ 32 | 'required_with:password', 33 | new CurrentPassword 34 | ], 35 | 'password' => 'string|min:8|confirmed' 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Resources/TaskResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 16 | 'title' => $this->title, 17 | 'due_at' => optional($this->due_at)->toATOMString(), 18 | 'is_completed' => $this->is_completed ?? false, 19 | 'author' => new UserResource($this->author), 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Resources/UserResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 16 | 'name' => $this->name, 17 | 'email' => $this->email, 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Models/Task.php: -------------------------------------------------------------------------------- 1 | 'datetime', 31 | 'is_completed' => 'boolean' 32 | ]; 33 | 34 | /** 35 | * Set the task's due_at date in UTC. 36 | */ 37 | public function setDueAtAttribute(?string $carbon): void 38 | { 39 | $this->attributes['due_at'] = null; 40 | 41 | if (filled($carbon)) { 42 | $this->attributes['due_at'] = Carbon::parse($carbon)->setTimezone("UTC"); 43 | } 44 | } 45 | 46 | /** 47 | * Return the task's author 48 | */ 49 | public function author(): BelongsTo 50 | { 51 | return $this->belongsTo(User::class, 'user_id'); 52 | } 53 | 54 | /** 55 | * Scope a query to only include completed tasks. 56 | */ 57 | public function scopeCompleted(Builder $query): Builder 58 | { 59 | return $query->whereIsCompleted(true); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | attributes['password'] = Hash::make($password); 39 | } 40 | 41 | /** 42 | * Return the user's tasks 43 | */ 44 | public function tasks(): HasMany 45 | { 46 | return $this->hasMany(Task::class); 47 | } 48 | 49 | /** 50 | * Get the identifier that will be stored in the subject claim of the JWT. 51 | * 52 | * @return mixed 53 | */ 54 | public function getJWTIdentifier() 55 | { 56 | return $this->getKey(); 57 | } 58 | 59 | /** 60 | * Return a key value array, containing any custom claims to be added to the JWT. 61 | */ 62 | public function getJWTCustomClaims(): array 63 | { 64 | return []; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/Policies/TaskPolicy.php: -------------------------------------------------------------------------------- 1 | id === $task->user_id; 19 | } 20 | 21 | /** 22 | * Determine whether the user can create tasks. 23 | */ 24 | public function create(User $user): bool 25 | { 26 | return true; 27 | } 28 | 29 | /** 30 | * Determine whether the user can update the task. 31 | */ 32 | public function update(User $user, Task $task): bool 33 | { 34 | return $user->id === $task->user_id; 35 | } 36 | 37 | /** 38 | * Determine whether the user can delete the task. 39 | */ 40 | public function delete(User $user, Task $task): bool 41 | { 42 | return $user->id === $task->user_id; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Policies/UserPolicy.php: -------------------------------------------------------------------------------- 1 | id === $model->id; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | UserPolicy::class, 20 | Task::class => TaskPolicy::class 21 | ]; 22 | 23 | /** 24 | * Register any authentication / authorization services. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | $this->registerPolicies(); 31 | 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | parent::boot(); 31 | 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | // 41 | } 42 | 43 | /** 44 | * Define the "api" routes for the application. 45 | * 46 | * These routes are typically stateless. 47 | * 48 | * @return void 49 | */ 50 | protected function mapApiRoutes() 51 | { 52 | Route::prefix('api') 53 | ->middleware('api') 54 | ->namespace($this->namespace) 55 | ->group(base_path('routes/api.php')); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/Rules/CurrentPassword.php: -------------------------------------------------------------------------------- 1 | user()->password); 16 | } 17 | 18 | /** 19 | * Get the validation error message. 20 | */ 21 | public function message(): string 22 | { 23 | return trans('validation.current_password'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guillaumebriday/todolist-backend-laravel", 3 | "description": "Todolist Backend", 4 | "keywords": ["todolist", "laravel"], 5 | "license": "MIT", 6 | "type": "project", 7 | "require": { 8 | "php": "^7.2", 9 | "fideloper/proxy": "4.4.0", 10 | "laravel/framework": "5.8.38", 11 | "laravel/slack-notification-channel": "2.2.0", 12 | "laravel/tinker": "1.0.10", 13 | "pusher/pusher-php-server": "4.1.4", 14 | "spatie/laravel-backup": "6.7.8", 15 | "spatie/laravel-cors": "1.6.0", 16 | "spatie/laravel-tail": "3.3.0", 17 | "tymon/jwt-auth": "1.0.0" 18 | }, 19 | "require-dev": { 20 | "beyondcode/laravel-dump-server": "1.4.0", 21 | "filp/whoops": "2.7.3", 22 | "friendsofphp/php-cs-fixer": "2.16.4", 23 | "fzaninotto/faker": "1.9.1", 24 | "mockery/mockery": "1.2.4", 25 | "nunomaduro/collision": "3.0.1", 26 | "nunomaduro/phpinsights": "1.9.0", 27 | "phpunit/phpunit": "8.4.3" 28 | }, 29 | "autoload": { 30 | "classmap": [ 31 | "database/seeds", 32 | "database/factories" 33 | ], 34 | "psr-4": { 35 | "App\\": "app/" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "Tests\\": "tests/" 41 | } 42 | }, 43 | "extra": { 44 | "laravel": { 45 | "dont-discover": [ 46 | ] 47 | } 48 | }, 49 | "scripts": { 50 | "post-root-package-install": [ 51 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 52 | ], 53 | "post-create-project-cmd": [ 54 | "@php artisan key:generate" 55 | ], 56 | "post-autoload-dump": [ 57 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 58 | "@php artisan package:discover" 59 | ] 60 | }, 61 | "config": { 62 | "preferred-install": "dist", 63 | "sort-packages": true, 64 | "optimize-autoloader": true 65 | }, 66 | "minimum-stability": "dev", 67 | "prefer-stable": true 68 | } 69 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | your application so that it is used when running Artisan tasks. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. We have gone 64 | | ahead and set this to a sensible default for you out of the box. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by the translation service provider. You are free to set this value 77 | | to any of the locales which will be supported by the application. 78 | | 79 | */ 80 | 81 | 'locale' => 'en', 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Application Fallback Locale 86 | |-------------------------------------------------------------------------- 87 | | 88 | | The fallback locale determines the locale to use when the current one 89 | | is not available. You may change the value to correspond to any of 90 | | the language folders that are provided through your application. 91 | | 92 | */ 93 | 94 | 'fallback_locale' => 'en', 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Encryption Key 99 | |-------------------------------------------------------------------------- 100 | | 101 | | This key is used by the Illuminate encrypter service and should be set 102 | | to a random, 32 character string, otherwise these encrypted strings 103 | | will not be safe. Please do this before deploying an application! 104 | | 105 | */ 106 | 107 | 'key' => env('APP_KEY'), 108 | 109 | 'cipher' => 'AES-256-CBC', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Autoloaded Service Providers 114 | |-------------------------------------------------------------------------- 115 | | 116 | | The service providers listed here will be automatically loaded on the 117 | | request to your application. Feel free to add your own services to 118 | | this array to grant expanded functionality to your applications. 119 | | 120 | */ 121 | 122 | 'providers' => [ 123 | 124 | /* 125 | * Laravel Framework Service Providers... 126 | */ 127 | Illuminate\Auth\AuthServiceProvider::class, 128 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 129 | Illuminate\Bus\BusServiceProvider::class, 130 | Illuminate\Cache\CacheServiceProvider::class, 131 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 132 | Illuminate\Cookie\CookieServiceProvider::class, 133 | Illuminate\Database\DatabaseServiceProvider::class, 134 | Illuminate\Encryption\EncryptionServiceProvider::class, 135 | Illuminate\Filesystem\FilesystemServiceProvider::class, 136 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 137 | Illuminate\Hashing\HashServiceProvider::class, 138 | Illuminate\Mail\MailServiceProvider::class, 139 | Illuminate\Notifications\NotificationServiceProvider::class, 140 | Illuminate\Pagination\PaginationServiceProvider::class, 141 | Illuminate\Pipeline\PipelineServiceProvider::class, 142 | Illuminate\Queue\QueueServiceProvider::class, 143 | Illuminate\Redis\RedisServiceProvider::class, 144 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 145 | Illuminate\Session\SessionServiceProvider::class, 146 | Illuminate\Translation\TranslationServiceProvider::class, 147 | Illuminate\Validation\ValidationServiceProvider::class, 148 | Illuminate\View\ViewServiceProvider::class, 149 | 150 | /* 151 | * Package Service Providers... 152 | */ 153 | 154 | /* 155 | * Application Service Providers... 156 | */ 157 | App\Providers\AppServiceProvider::class, 158 | App\Providers\AuthServiceProvider::class, 159 | App\Providers\BroadcastServiceProvider::class, 160 | App\Providers\EventServiceProvider::class, 161 | App\Providers\RouteServiceProvider::class, 162 | 163 | ], 164 | 165 | /* 166 | |-------------------------------------------------------------------------- 167 | | Class Aliases 168 | |-------------------------------------------------------------------------- 169 | | 170 | | This array of class aliases will be registered when this application 171 | | is started. However, feel free to register as many as you wish as 172 | | the aliases are "lazy" loaded so they don't hinder performance. 173 | | 174 | */ 175 | 176 | 'aliases' => [ 177 | 178 | 'App' => Illuminate\Support\Facades\App::class, 179 | 'Arr' => Illuminate\Support\Arr::class, 180 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 181 | 'Auth' => Illuminate\Support\Facades\Auth::class, 182 | 'Blade' => Illuminate\Support\Facades\Blade::class, 183 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 184 | 'Bus' => Illuminate\Support\Facades\Bus::class, 185 | 'Cache' => Illuminate\Support\Facades\Cache::class, 186 | 'Config' => Illuminate\Support\Facades\Config::class, 187 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 188 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 189 | 'DB' => Illuminate\Support\Facades\DB::class, 190 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 191 | 'Event' => Illuminate\Support\Facades\Event::class, 192 | 'File' => Illuminate\Support\Facades\File::class, 193 | 'Gate' => Illuminate\Support\Facades\Gate::class, 194 | 'Hash' => Illuminate\Support\Facades\Hash::class, 195 | 'Lang' => Illuminate\Support\Facades\Lang::class, 196 | 'Log' => Illuminate\Support\Facades\Log::class, 197 | 'Mail' => Illuminate\Support\Facades\Mail::class, 198 | 'Notification' => Illuminate\Support\Facades\Notification::class, 199 | 'Password' => Illuminate\Support\Facades\Password::class, 200 | 'Queue' => Illuminate\Support\Facades\Queue::class, 201 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 202 | 'Redis' => Illuminate\Support\Facades\Redis::class, 203 | 'Request' => Illuminate\Support\Facades\Request::class, 204 | 'Response' => Illuminate\Support\Facades\Response::class, 205 | 'Route' => Illuminate\Support\Facades\Route::class, 206 | 'Schema' => Illuminate\Support\Facades\Schema::class, 207 | 'Session' => Illuminate\Support\Facades\Session::class, 208 | 'Storage' => Illuminate\Support\Facades\Storage::class, 209 | 'Str' => Illuminate\Support\Str::class, 210 | 'URL' => Illuminate\Support\Facades\URL::class, 211 | 'Validator' => Illuminate\Support\Facades\Validator::class, 212 | 'View' => Illuminate\Support\Facades\View::class, 213 | 214 | ], 215 | 216 | ]; 217 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'api', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'api' => [ 40 | 'driver' => 'jwt', 41 | 'provider' => 'users', 42 | 'hash' => false, 43 | ], 44 | ], 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | User Providers 49 | |-------------------------------------------------------------------------- 50 | | 51 | | All authentication drivers have a user provider. This defines how the 52 | | users are actually retrieved out of your database or other storage 53 | | mechanisms used by this application to persist your user's data. 54 | | 55 | | If you have multiple user tables or models you may configure multiple 56 | | sources which represent each model / table. These sources may then 57 | | be assigned to any extra authentication guards you have defined. 58 | | 59 | | Supported: "database", "eloquent" 60 | | 61 | */ 62 | 63 | 'providers' => [ 64 | 'users' => [ 65 | 'driver' => 'eloquent', 66 | 'model' => App\Models\User::class, 67 | ], 68 | 69 | // 'users' => [ 70 | // 'driver' => 'database', 71 | // 'table' => 'users', 72 | // ], 73 | ], 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Resetting Passwords 78 | |-------------------------------------------------------------------------- 79 | | 80 | | You may specify multiple password reset configurations if you have more 81 | | than one user table or model in the application and you want to have 82 | | separate password reset settings based on the specific user types. 83 | | 84 | | The expire time is the number of minutes that the reset token should be 85 | | considered valid. This security feature keeps tokens short-lived so 86 | | they have less time to be guessed. You may change this as needed. 87 | | 88 | */ 89 | 90 | 'passwords' => [ 91 | 'users' => [ 92 | 'provider' => 'users', 93 | 'table' => 'password_resets', 94 | 'expire' => 60, 95 | ], 96 | ], 97 | 98 | ]; 99 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'encrypted' => true 41 | ], 42 | ], 43 | 44 | 'redis' => [ 45 | 'driver' => 'redis', 46 | 'connection' => 'default', 47 | ], 48 | 49 | 'log' => [ 50 | 'driver' => 'log', 51 | ], 52 | 53 | 'null' => [ 54 | 'driver' => 'null', 55 | ], 56 | 57 | ], 58 | 59 | ]; 60 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Cache Stores 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may define all of the cache "stores" for your application as 29 | | well as their drivers. You may even define multiple stores for the 30 | | same cache driver to group types of items stored in your caches. 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'apc' => [ 37 | 'driver' => 'apc', 38 | ], 39 | 40 | 'array' => [ 41 | 'driver' => 'array', 42 | ], 43 | 44 | 'database' => [ 45 | 'driver' => 'database', 46 | 'table' => 'cache', 47 | 'connection' => null, 48 | ], 49 | 50 | 'file' => [ 51 | 'driver' => 'file', 52 | 'path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => 'cache', 77 | ], 78 | 79 | 'dynamodb' => [ 80 | 'driver' => 'dynamodb', 81 | 'key' => env('AWS_ACCESS_KEY_ID'), 82 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 83 | 'region' => env('AWS_REGION', 'us-east-1'), 84 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 85 | ], 86 | 87 | ], 88 | 89 | /* 90 | |-------------------------------------------------------------------------- 91 | | Cache Key Prefix 92 | |-------------------------------------------------------------------------- 93 | | 94 | | When utilizing a RAM based store such as APC or Memcached, there might 95 | | be other applications utilizing the same cache. So, we'll specify a 96 | | value to get prefixed to all our keys so we can avoid collisions. 97 | | 98 | */ 99 | 100 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), 101 | 102 | ]; 103 | -------------------------------------------------------------------------------- /config/cors.php: -------------------------------------------------------------------------------- 1 | Spatie\Cors\CorsProfile\DefaultProfile::class, 14 | 15 | /* 16 | * This configuration is used by `DefaultProfile`. 17 | */ 18 | 'default_profile' => [ 19 | 20 | 'allow_origins' => [ 21 | '*', 22 | ], 23 | 24 | 'allow_methods' => [ 25 | 'POST', 26 | 'GET', 27 | 'OPTIONS', 28 | 'PUT', 29 | 'PATCH', 30 | 'DELETE', 31 | ], 32 | 33 | 'allow_headers' => [ 34 | 'Content-Type', 35 | 'X-Auth-Token', 36 | 'X-Socket-Id', 37 | 'Origin', 38 | 'Authorization', 39 | 'X-Requested-With', 40 | ], 41 | 42 | /* 43 | * Preflight request will respond with value for the max age header. 44 | */ 45 | 'max_age' => 60 * 60 * 24, 46 | ], 47 | ]; 48 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'mysql'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Database Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here are each of the database connections setup for your application. 24 | | Of course, examples of configuring each database platform that is 25 | | supported by Laravel is shown below to make development simple. 26 | | 27 | | 28 | | All database work in Laravel is done through the PHP PDO facilities 29 | | so make sure you have the driver for your particular database of 30 | | choice installed on your machine before you begin development. 31 | | 32 | */ 33 | 34 | 'connections' => [ 35 | 36 | 'sqlite' => [ 37 | 'driver' => 'sqlite', 38 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 39 | 'prefix' => '', 40 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 41 | ], 42 | 43 | 'mysql' => [ 44 | 'driver' => 'mysql', 45 | 'host' => env('DB_HOST', '127.0.0.1'), 46 | 'port' => env('DB_PORT', '3306'), 47 | 'database' => env('DB_DATABASE', 'forge'), 48 | 'username' => env('DB_USERNAME', 'forge'), 49 | 'password' => env('DB_PASSWORD', ''), 50 | 'unix_socket' => env('DB_SOCKET', ''), 51 | 'charset' => 'utf8mb4', 52 | 'collation' => 'utf8mb4_unicode_ci', 53 | 'prefix' => '', 54 | 'prefix_indexes' => true, 55 | 'strict' => true, 56 | 'engine' => null, 57 | 'options' => array_filter([ 58 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 59 | ]), 60 | ], 61 | 62 | 'pgsql' => [ 63 | 'driver' => 'pgsql', 64 | 'host' => env('DB_HOST', '127.0.0.1'), 65 | 'port' => env('DB_PORT', '5432'), 66 | 'database' => env('DB_DATABASE', 'forge'), 67 | 'username' => env('DB_USERNAME', 'forge'), 68 | 'password' => env('DB_PASSWORD', ''), 69 | 'charset' => 'utf8', 70 | 'prefix' => '', 71 | 'prefix_indexes' => true, 72 | 'schema' => 'public', 73 | 'sslmode' => 'prefer', 74 | ], 75 | 76 | 'sqlsrv' => [ 77 | 'driver' => 'sqlsrv', 78 | 'host' => env('DB_HOST', 'localhost'), 79 | 'port' => env('DB_PORT', '1433'), 80 | 'database' => env('DB_DATABASE', 'forge'), 81 | 'username' => env('DB_USERNAME', 'forge'), 82 | 'password' => env('DB_PASSWORD', ''), 83 | 'charset' => 'utf8', 84 | 'prefix' => '', 85 | 'prefix_indexes' => true, 86 | ], 87 | 88 | ], 89 | 90 | /* 91 | |-------------------------------------------------------------------------- 92 | | Migration Repository Table 93 | |-------------------------------------------------------------------------- 94 | | 95 | | This table keeps track of all the migrations that have already run for 96 | | your application. Using this information, we can determine which of 97 | | the migrations on disk haven't actually been run in the database. 98 | | 99 | */ 100 | 101 | 'migrations' => 'migrations', 102 | 103 | /* 104 | |-------------------------------------------------------------------------- 105 | | Redis Databases 106 | |-------------------------------------------------------------------------- 107 | | 108 | | Redis is an open source, fast, and advanced key-value store that also 109 | | provides a richer body of commands than a typical key-value system 110 | | such as APC or Memcached. Laravel makes it easy to dig right in. 111 | | 112 | */ 113 | 114 | 'redis' => [ 115 | 116 | 'client' => env('REDIS_CLIENT', 'predis'), 117 | 118 | 'options' => [ 119 | 'cluster' => env('REDIS_CLUSTER', 'predis'), 120 | ], 121 | 122 | 'default' => [ 123 | 'host' => env('REDIS_HOST', '127.0.0.1'), 124 | 'password' => env('REDIS_PASSWORD', null), 125 | 'port' => env('REDIS_PORT', 6379), 126 | 'database' => env('REDIS_DB', 0), 127 | ], 128 | 129 | 'cache' => [ 130 | 'host' => env('REDIS_HOST', '127.0.0.1'), 131 | 'password' => env('REDIS_PASSWORD', null), 132 | 'port' => env('REDIS_PORT', 6379), 133 | 'database' => env('REDIS_CACHE_DB', 1), 134 | ], 135 | 136 | ], 137 | 138 | ]; 139 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | ], 66 | 67 | ], 68 | 69 | ]; 70 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/jwt.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | return [ 13 | 14 | /* 15 | |-------------------------------------------------------------------------- 16 | | JWT Authentication Secret 17 | |-------------------------------------------------------------------------- 18 | | 19 | | Don't forget to set this in your .env file, as it will be used to sign 20 | | your tokens. A helper command is provided for this: 21 | | `php artisan jwt:secret` 22 | | 23 | | Note: This will be used for Symmetric algorithms only (HMAC), 24 | | since RSA and ECDSA use a private/public key combo (See below). 25 | | 26 | */ 27 | 28 | 'secret' => env('JWT_SECRET'), 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | JWT Authentication Keys 33 | |-------------------------------------------------------------------------- 34 | | 35 | | The algorithm you are using, will determine whether your tokens are 36 | | signed with a random string (defined in `JWT_SECRET`) or using the 37 | | following public & private keys. 38 | | 39 | | Symmetric Algorithms: 40 | | HS256, HS384 & HS512 will use `JWT_SECRET`. 41 | | 42 | | Asymmetric Algorithms: 43 | | RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below. 44 | | 45 | */ 46 | 47 | 'keys' => [ 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Public Key 52 | |-------------------------------------------------------------------------- 53 | | 54 | | A path or resource to your public key. 55 | | 56 | | E.g. 'file://path/to/public/key' 57 | | 58 | */ 59 | 60 | 'public' => env('JWT_PUBLIC_KEY'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Private Key 65 | |-------------------------------------------------------------------------- 66 | | 67 | | A path or resource to your private key. 68 | | 69 | | E.g. 'file://path/to/private/key' 70 | | 71 | */ 72 | 73 | 'private' => env('JWT_PRIVATE_KEY'), 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Passphrase 78 | |-------------------------------------------------------------------------- 79 | | 80 | | The passphrase for your private key. Can be null if none set. 81 | | 82 | */ 83 | 84 | 'passphrase' => env('JWT_PASSPHRASE'), 85 | 86 | ], 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | JWT time to live 91 | |-------------------------------------------------------------------------- 92 | | 93 | | Specify the length of time (in minutes) that the token will be valid for. 94 | | Defaults to 1 hour. 95 | | 96 | | You can also set this to null, to yield a never expiring token. 97 | | Some people may want this behaviour for e.g. a mobile app. 98 | | This is not particularly recommended, so make sure you have appropriate 99 | | systems in place to revoke the token if necessary. 100 | | 101 | */ 102 | 103 | 'ttl' => env('JWT_TTL', 60), 104 | 105 | /* 106 | |-------------------------------------------------------------------------- 107 | | Refresh time to live 108 | |-------------------------------------------------------------------------- 109 | | 110 | | Specify the length of time (in minutes) that the token can be refreshed 111 | | within. I.E. The user can refresh their token within a 2 week window of 112 | | the original token being created until they must re-authenticate. 113 | | Defaults to 2 weeks. 114 | | 115 | | You can also set this to null, to yield an infinite refresh time. 116 | | Some may want this instead of never expiring tokens for e.g. a mobile app. 117 | | This is not particularly recommended, so make sure you have appropriate 118 | | systems in place to revoke the token if necessary. 119 | | 120 | */ 121 | 122 | 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), 123 | 124 | /* 125 | |-------------------------------------------------------------------------- 126 | | JWT hashing algorithm 127 | |-------------------------------------------------------------------------- 128 | | 129 | | Specify the hashing algorithm that will be used to sign the token. 130 | | 131 | | See here: https://github.com/namshi/jose/tree/master/src/Namshi/JOSE/Signer/OpenSSL 132 | | for possible values. 133 | | 134 | */ 135 | 136 | 'algo' => env('JWT_ALGO', 'HS256'), 137 | 138 | /* 139 | |-------------------------------------------------------------------------- 140 | | Required Claims 141 | |-------------------------------------------------------------------------- 142 | | 143 | | Specify the required claims that must exist in any token. 144 | | A TokenInvalidException will be thrown if any of these claims are not 145 | | present in the payload. 146 | | 147 | */ 148 | 149 | 'required_claims' => [ 150 | 'iss', 151 | 'iat', 152 | 'exp', 153 | 'nbf', 154 | 'sub', 155 | 'jti', 156 | ], 157 | 158 | /* 159 | |-------------------------------------------------------------------------- 160 | | Persistent Claims 161 | |-------------------------------------------------------------------------- 162 | | 163 | | Specify the claim keys to be persisted when refreshing a token. 164 | | `sub` and `iat` will automatically be persisted, in 165 | | addition to the these claims. 166 | | 167 | | Note: If a claim does not exist then it will be ignored. 168 | | 169 | */ 170 | 171 | 'persistent_claims' => [ 172 | // 'foo', 173 | // 'bar', 174 | ], 175 | 176 | /* 177 | |-------------------------------------------------------------------------- 178 | | Blacklist Enabled 179 | |-------------------------------------------------------------------------- 180 | | 181 | | In order to invalidate tokens, you must have the blacklist enabled. 182 | | If you do not want or need this functionality, then set this to false. 183 | | 184 | */ 185 | 186 | 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), 187 | 188 | /* 189 | | ------------------------------------------------------------------------- 190 | | Blacklist Grace Period 191 | | ------------------------------------------------------------------------- 192 | | 193 | | When multiple concurrent requests are made with the same JWT, 194 | | it is possible that some of them fail, due to token regeneration 195 | | on every request. 196 | | 197 | | Set grace period in seconds to prevent parallel request failure. 198 | | 199 | */ 200 | 201 | 'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0), 202 | 203 | /* 204 | |-------------------------------------------------------------------------- 205 | | Cookies encryption 206 | |-------------------------------------------------------------------------- 207 | | 208 | | By default Laravel encrypt cookies for security reason. 209 | | If you decide to not decrypt cookies, you will have to configure Laravel 210 | | to not encrypt your cookie token by adding its name into the $except 211 | | array available in the middleware "EncryptCookies" provided by Laravel. 212 | | see https://laravel.com/docs/master/responses#cookies-and-encryption 213 | | for details. 214 | | 215 | | Set it to false if you don't want to decrypt cookies. 216 | | 217 | */ 218 | 219 | 'decrypt_cookies' => true, 220 | 221 | /* 222 | |-------------------------------------------------------------------------- 223 | | Providers 224 | |-------------------------------------------------------------------------- 225 | | 226 | | Specify the various providers used throughout the package. 227 | | 228 | */ 229 | 230 | 'providers' => [ 231 | 232 | /* 233 | |-------------------------------------------------------------------------- 234 | | JWT Provider 235 | |-------------------------------------------------------------------------- 236 | | 237 | | Specify the provider that is used to create and decode the tokens. 238 | | 239 | */ 240 | 241 | 'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class, 242 | 243 | /* 244 | |-------------------------------------------------------------------------- 245 | | Authentication Provider 246 | |-------------------------------------------------------------------------- 247 | | 248 | | Specify the provider that is used to authenticate users. 249 | | 250 | */ 251 | 252 | 'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class, 253 | 254 | /* 255 | |-------------------------------------------------------------------------- 256 | | Storage Provider 257 | |-------------------------------------------------------------------------- 258 | | 259 | | Specify the provider that is used to store tokens in the blacklist. 260 | | 261 | */ 262 | 263 | 'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class, 264 | 265 | ], 266 | 267 | ]; 268 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Log Channels 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the log channels for your application. Out of 26 | | the box, Laravel uses the Monolog PHP logging library. This gives 27 | | you a variety of powerful log handlers / formatters to utilize. 28 | | 29 | | Available Drivers: "single", "daily", "slack", "syslog", 30 | | "errorlog", "monolog", 31 | | "custom", "stack" 32 | | 33 | */ 34 | 35 | 'channels' => [ 36 | 'stack' => [ 37 | 'driver' => 'stack', 38 | 'channels' => ['daily', 'slack'], 39 | ], 40 | 41 | 'single' => [ 42 | 'driver' => 'single', 43 | 'path' => storage_path('logs/laravel.log'), 44 | 'level' => 'debug', 45 | ], 46 | 47 | 'daily' => [ 48 | 'driver' => 'daily', 49 | 'path' => storage_path('logs/laravel.log'), 50 | 'level' => 'debug', 51 | 'days' => 7, 52 | ], 53 | 54 | 'slack' => [ 55 | 'driver' => 'slack', 56 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 57 | 'username' => 'Laravel Log', 58 | 'emoji' => ':boom:', 59 | 'level' => 'error', 60 | ], 61 | 62 | 'stderr' => [ 63 | 'driver' => 'monolog', 64 | 'handler' => StreamHandler::class, 65 | 'with' => [ 66 | 'stream' => 'php://stderr', 67 | ], 68 | ], 69 | 70 | 'syslog' => [ 71 | 'driver' => 'syslog', 72 | 'level' => 'debug', 73 | ], 74 | 75 | 'errorlog' => [ 76 | 'driver' => 'errorlog', 77 | 'level' => 'debug', 78 | ], 79 | ], 80 | 81 | ]; 82 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => [ 59 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 60 | 'name' => env('MAIL_FROM_NAME', 'Example'), 61 | ], 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | E-Mail Encryption Protocol 66 | |-------------------------------------------------------------------------- 67 | | 68 | | Here you may specify the encryption protocol that should be used when 69 | | the application send e-mail messages. A sensible default using the 70 | | transport layer security protocol should provide great security. 71 | | 72 | */ 73 | 74 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | SMTP Server Username 79 | |-------------------------------------------------------------------------- 80 | | 81 | | If your SMTP server requires a username for authentication, you should 82 | | set it here. This will get used to authenticate with your server on 83 | | connection. You may also set the "password" value below this one. 84 | | 85 | */ 86 | 87 | 'username' => env('MAIL_USERNAME'), 88 | 89 | 'password' => env('MAIL_PASSWORD'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Sendmail System Path 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using the "sendmail" driver to send e-mails, we will need to know 97 | | the path to where Sendmail lives on this server. A default path has 98 | | been provided here, which will work well on most of your systems. 99 | | 100 | */ 101 | 102 | 'sendmail' => '/usr/sbin/sendmail -bs', 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Markdown Mail Settings 107 | |-------------------------------------------------------------------------- 108 | | 109 | | If you are using Markdown based email rendering, you may configure your 110 | | theme and component paths here, allowing you to customize the design 111 | | of the emails. Or, you may simply stick with the Laravel defaults! 112 | | 113 | */ 114 | 115 | 'markdown' => [ 116 | 'theme' => 'default', 117 | 118 | 'paths' => [ 119 | resource_path('views/vendor/mail'), 120 | ], 121 | ], 122 | 123 | /* 124 | |-------------------------------------------------------------------------- 125 | | Log Channel 126 | |-------------------------------------------------------------------------- 127 | | 128 | | If you are using the "log" driver, you may specify the logging channel 129 | | if you prefer to keep mail messages separate from other log entries 130 | | for simpler reading. Otherwise, the default channel will be used. 131 | | 132 | */ 133 | 134 | 'log_channel' => env('MAIL_LOG_CHANNEL'), 135 | 136 | ]; 137 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | 'block_for' => 0, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => env('AWS_ACCESS_KEY_ID'), 55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 58 | 'region' => env('AWS_REGION', 'us-east-1'), 59 | ], 60 | 61 | 'redis' => [ 62 | 'driver' => 'redis', 63 | 'connection' => 'default', 64 | 'queue' => env('REDIS_QUEUE', 'default'), 65 | 'retry_after' => 90, 66 | 'block_for' => null, 67 | ], 68 | 69 | ], 70 | 71 | /* 72 | |-------------------------------------------------------------------------- 73 | | Failed Queue Jobs 74 | |-------------------------------------------------------------------------- 75 | | 76 | | These options configure the behavior of failed queue job logging so you 77 | | can control which database and table are used to store the jobs that 78 | | have failed. You may change them to any database / table you wish. 79 | | 80 | */ 81 | 82 | 'failed' => [ 83 | 'database' => env('DB_CONNECTION', 'mysql'), 84 | 'table' => 'failed_jobs', 85 | ], 86 | 87 | ]; 88 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'postmark' => [ 24 | 'token' => env('POSTMARK_TOKEN'), 25 | ], 26 | 27 | 'ses' => [ 28 | 'key' => env('AWS_ACCESS_KEY_ID'), 29 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 30 | 'region' => env('AWS_REGION', 'us-east-1'), 31 | ], 32 | 33 | 'sparkpost' => [ 34 | 'secret' => env('SPARKPOST_SECRET'), 35 | ], 36 | 37 | 'stripe' => [ 38 | 'model' => App\User::class, 39 | 'key' => env('STRIPE_KEY'), 40 | 'secret' => env('STRIPE_SECRET'), 41 | 'webhook' => [ 42 | 'secret' => env('STRIPE_WEBHOOK_SECRET'), 43 | 'tolerance' => env('STRIPE_WEBHOOK_TOLERANCE', 300), 44 | ], 45 | ], 46 | 47 | ]; 48 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to immediately expire on the browser closing, set that option. 31 | | 32 | */ 33 | 34 | 'lifetime' => env('SESSION_LIFETIME', 120), 35 | 36 | 'expire_on_close' => false, 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Session Encryption 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This option allows you to easily specify that all of your session data 44 | | should be encrypted before it is stored. All encryption will be run 45 | | automatically by Laravel and you can use the Session like normal. 46 | | 47 | */ 48 | 49 | 'encrypt' => false, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Session File Location 54 | |-------------------------------------------------------------------------- 55 | | 56 | | When using the native session driver, we need a location where session 57 | | files may be stored. A default has been set for you but a different 58 | | location may be specified. This is only needed for file sessions. 59 | | 60 | */ 61 | 62 | 'files' => storage_path('framework/sessions'), 63 | 64 | /* 65 | |-------------------------------------------------------------------------- 66 | | Session Database Connection 67 | |-------------------------------------------------------------------------- 68 | | 69 | | When using the "database" or "redis" session drivers, you may specify a 70 | | connection that should be used to manage these sessions. This should 71 | | correspond to a connection in your database configuration options. 72 | | 73 | */ 74 | 75 | 'connection' => env('SESSION_CONNECTION', null), 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Session Database Table 80 | |-------------------------------------------------------------------------- 81 | | 82 | | When using the "database" session driver, you may specify the table we 83 | | should use to manage the sessions. Of course, a sensible default is 84 | | provided for you; however, you are free to change this as needed. 85 | | 86 | */ 87 | 88 | 'table' => 'sessions', 89 | 90 | /* 91 | |-------------------------------------------------------------------------- 92 | | Session Cache Store 93 | |-------------------------------------------------------------------------- 94 | | 95 | | When using the "apc", "memcached", or "dynamodb" session drivers you may 96 | | list a cache store that should be used for these sessions. This value 97 | | must match with one of the application's configured cache "stores". 98 | | 99 | */ 100 | 101 | 'store' => env('SESSION_STORE', null), 102 | 103 | /* 104 | |-------------------------------------------------------------------------- 105 | | Session Sweeping Lottery 106 | |-------------------------------------------------------------------------- 107 | | 108 | | Some session drivers must manually sweep their storage location to get 109 | | rid of old sessions from storage. Here are the chances that it will 110 | | happen on a given request. By default, the odds are 2 out of 100. 111 | | 112 | */ 113 | 114 | 'lottery' => [2, 100], 115 | 116 | /* 117 | |-------------------------------------------------------------------------- 118 | | Session Cookie Name 119 | |-------------------------------------------------------------------------- 120 | | 121 | | Here you may change the name of the cookie used to identify a session 122 | | instance by ID. The name specified here will get used every time a 123 | | new session cookie is created by the framework for every driver. 124 | | 125 | */ 126 | 127 | 'cookie' => env( 128 | 'SESSION_COOKIE', 129 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session' 130 | ), 131 | 132 | /* 133 | |-------------------------------------------------------------------------- 134 | | Session Cookie Path 135 | |-------------------------------------------------------------------------- 136 | | 137 | | The session cookie path determines the path for which the cookie will 138 | | be regarded as available. Typically, this will be the root path of 139 | | your application but you are free to change this when necessary. 140 | | 141 | */ 142 | 143 | 'path' => '/', 144 | 145 | /* 146 | |-------------------------------------------------------------------------- 147 | | Session Cookie Domain 148 | |-------------------------------------------------------------------------- 149 | | 150 | | Here you may change the domain of the cookie used to identify a session 151 | | in your application. This will determine which domains the cookie is 152 | | available to in your application. A sensible default has been set. 153 | | 154 | */ 155 | 156 | 'domain' => env('SESSION_DOMAIN', null), 157 | 158 | /* 159 | |-------------------------------------------------------------------------- 160 | | HTTPS Only Cookies 161 | |-------------------------------------------------------------------------- 162 | | 163 | | By setting this option to true, session cookies will only be sent back 164 | | to the server if the browser has a HTTPS connection. This will keep 165 | | the cookie from being sent to you if it can not be done securely. 166 | | 167 | */ 168 | 169 | 'secure' => env('SESSION_SECURE_COOKIE', false), 170 | 171 | /* 172 | |-------------------------------------------------------------------------- 173 | | HTTP Access Only 174 | |-------------------------------------------------------------------------- 175 | | 176 | | Setting this value to true will prevent JavaScript from accessing the 177 | | value of the cookie and the cookie will only be accessible through 178 | | the HTTP protocol. You are free to modify this option if needed. 179 | | 180 | */ 181 | 182 | 'http_only' => true, 183 | 184 | /* 185 | |-------------------------------------------------------------------------- 186 | | Same-Site Cookies 187 | |-------------------------------------------------------------------------- 188 | | 189 | | This option determines how your cookies behave when cross-site requests 190 | | take place, and can be used to mitigate CSRF attacks. By default, we 191 | | do not enable this as other CSRF protection services are in place. 192 | | 193 | | Supported: "lax", "strict" 194 | | 195 | */ 196 | 197 | 'same_site' => null, 198 | 199 | ]; 200 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/TaskFactory.php: -------------------------------------------------------------------------------- 1 | define(Task::class, function (Faker $faker) { 8 | return [ 9 | 'title' => $faker->sentence, 10 | 'due_at' => null, 11 | 'is_completed' => false, 12 | 'user_id' => function () { 13 | return factory(User::class)->create()->id; 14 | }, 15 | ]; 16 | }); 17 | 18 | $factory->state(Task::class, 'completed', function (Faker $faker) { 19 | return [ 20 | 'is_completed' => true 21 | ]; 22 | }); 23 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(User::class, function (Faker $faker) { 20 | static $password; 21 | 22 | return [ 23 | 'name' => $faker->name, 24 | 'email' => $faker->unique()->safeEmail, 25 | 'password' => $password ?: $password = Hash::make('secret'), 26 | 'remember_token' => Str::random(10), 27 | ]; 28 | }); 29 | 30 | $factory->state(User::class, 'anakin', function () { 31 | return [ 32 | 'name' => 'Anakin', 33 | 'email' => 'anakin@skywalker.st', 34 | 'password' => '4nak1n' 35 | ]; 36 | }); 37 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->string('password'); 21 | $table->rememberToken(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('users'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2018_01_14_192421_create_tasks_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | 19 | $table->string('title'); 20 | $table->datetime('due_at')->nullable(); 21 | $table->softDeletes(); 22 | 23 | $table->integer('user_id')->unsigned(); 24 | $table->foreign('user_id')->references('id')->on('users'); 25 | 26 | $table->timestamps(); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('tasks'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /database/migrations/2018_04_09_203418_update_date_to_boolean_for_completed_tasks.php: -------------------------------------------------------------------------------- 1 | dropSoftDeletes(); 18 | 19 | $table->boolean('is_completed')->default(false); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::table('tasks', function (Blueprint $table) { 31 | $table->softDeletes(); 32 | 33 | $table->dropColumn('is_completed'); 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | 'darthvader@deathstar.ds'], 16 | [ 17 | 'name' => 'anakin', 18 | 'password' => '4nak1n5kyw4lk3r' 19 | ] 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /database/seeds/dev/DevDatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | todolist-server: 5 | build: .cloud/docker 6 | image: todolist-backend 7 | depends_on: 8 | - mysql 9 | - mysql-test 10 | volumes: 11 | - ./:/var/www:cached 12 | 13 | mysql: 14 | image: mysql:8 15 | command: --default-authentication-plugin=mysql_native_password 16 | ports: 17 | - "3306:3306" 18 | environment: 19 | - MYSQL_ROOT_PASSWORD=secret 20 | - MYSQL_DATABASE=laravel-todolist 21 | volumes: 22 | - db-data:/var/lib/mysql:cached 23 | 24 | mysql-test: 25 | image: mysql:8 26 | command: --default-authentication-plugin=mysql_native_password 27 | ports: 28 | - "3307:3306" 29 | environment: 30 | - MYSQL_ROOT_PASSWORD=secret 31 | - MYSQL_DATABASE=testing 32 | 33 | nginx: 34 | image: nginx 35 | ports: 36 | - "8000:8000" 37 | volumes: 38 | - .cloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:cached 39 | - ./public:/var/www/public:cached 40 | depends_on: 41 | - todolist-server 42 | 43 | volumes: 44 | db-data: 45 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | docs/.vuepress/dist 2 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Todolist docs 2 | 3 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/guillaumebriday) 4 | [![Netlify Status](https://api.netlify.com/api/v1/badges/49aa81a3-b064-4418-a40f-3e9f4e19d309/deploy-status)](https://app.netlify.com/sites/todolist-docs/deploys) 5 | 6 | > Documentation for https://github.com/guillaumebriday/todolist-backend-laravel app, built for a serie of articles on my [blog](https://guillaumebriday.fr/). 7 | 8 | ## Some of the tools used in this project 9 | 10 | - [Vuepress](https://vuepress.vuejs.org/) 11 | 12 | ## Installation 13 | 14 | Development environment requirements : 15 | - [Docker](https://www.docker.com) 16 | - [Docker Compose](https://docs.docker.com/compose/install/) 17 | 18 | Setting up your development environment on your local machine : 19 | ``` 20 | $ git clone https://github.com/guillaumebriday/todolist-backend-laravel.git 21 | $ cd todolist-backend-laravel 22 | $ docker-compose run --rm node yarn 23 | $ docker-compose run --service-ports --rm node yarn dev 24 | ``` 25 | 26 | ## Useful commands 27 | Building the app : 28 | ```bash 29 | $ docker-compose run --rm node yarn dev 30 | 31 | # or 32 | 33 | $ docker-compose run --rm node yarn production 34 | ``` 35 | 36 | ## Deploy in production 37 | 38 | This application is hosted on [Netlify](https://www.netlify.com/) and available on [https://todolist-docs.guillaumebriday.me/](https://todolist-docs.guillaumebriday.me/). 39 | 40 | ## Contributing 41 | 42 | Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome. 43 | 44 | ## License 45 | 46 | This project is released under the [MIT](http://opensource.org/licenses/MIT) license. 47 | -------------------------------------------------------------------------------- /docs/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | node: 5 | image: node 6 | working_dir: /app 7 | ports: 8 | - "8080:8080" 9 | volumes: 10 | - .:/app:cached 11 | -------------------------------------------------------------------------------- /docs/docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | title: 'Todolist docs', 3 | description: 'Todolist API documentation', 4 | themeConfig: { 5 | repo: 'guillaumebriday/todolist-backend-laravel', 6 | docsRepo: 'guillaumebriday/todolist-backend-laravel', 7 | docsDir: 'docs', 8 | editLinks: true, 9 | lastUpdated: true, 10 | serviceWorker: true, 11 | nav: [ 12 | { text: 'API', link: '/api/' }, 13 | ], 14 | sidebar: { 15 | '/api/': [ 16 | { 17 | title: 'API', 18 | collapsable: false, 19 | children: [ 20 | '', 21 | 'users', 22 | 'tasks' 23 | ] 24 | } 25 | ] 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /docs/docs/.vuepress/public/_redirects: -------------------------------------------------------------------------------- 1 | https://todolist-docs.netlify.com/* https://todolist-docs.guillaumebriday.me/:splat 301! 2 | -------------------------------------------------------------------------------- /docs/docs/.vuepress/public/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumebriday/todolist-backend-laravel/71ee99b7d57b2da9f6a730200f697d71e89082a7/docs/docs/.vuepress/public/screenshot.png -------------------------------------------------------------------------------- /docs/docs/.vuepress/styles/palette.styl: -------------------------------------------------------------------------------- 1 | // showing default values 2 | $accentColor = #6574cd 3 | -------------------------------------------------------------------------------- /docs/docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | heroImage: /screenshot.png 4 | actionText: Get Started → 5 | actionLink: /api/ 6 | features: 7 | - title: Never forget your tasks 8 | details: You can add unlimited tasks and let the application manage it for you. You can add due date or completed status. 9 | - title: Real time application 10 | details: Add a task on your computer and see it pop on your phone or tablet instantly. 11 | - title: Authentication with JWT 12 | details: JWT are an important piece in ensuring trust and security in your application. JWT allow claims, such as user data, to be represented in a secure manner. 13 | footer: MIT Licensed | Copyright © 2018-present Guillaume Briday 14 | --- 15 | -------------------------------------------------------------------------------- /docs/docs/api/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | [Todolist-backend Application](https://github.com/guillaumebriday/todolist-backend-laravel) offers several tools and APIs to manage a real world Todolist application. 4 | 5 | [Todolist-frontend Application](https://github.com/guillaumebriday/todolist-frontend-vuejs) is an example of a client for this API build with Vue.js 6 | 7 | In this documentation, you'll find tips to help you get up and running on a new client application. 8 | 9 | ## Content type 10 | 11 | The API only respond with the `Content-Type` header to `application/json`. 12 | 13 | ## API Version 14 | 15 | API are prefixed by `api` and the API version number like so `/api/v1`. 16 | 17 | ## Ajax header 18 | 19 | Do not forget to set the `X-Requested-With` header to `XMLHttpRequest`. Otherwise, Laravel won't recognize the call as an AJAX request. 20 | 21 | Example with axios : 22 | 23 | ```js 24 | window.axios.defaults.headers.common = { 25 | 'X-Requested-With': 'XMLHttpRequest', 26 | } 27 | ``` 28 | 29 | ## Authentication 30 | 31 | Clients can access to the REST API. API requests require authentication via JWT. 32 | 33 | Then, you can use this token either as url parameter or in Authorization header : 34 | 35 | ```bash 36 | # Url parameter 37 | $ curl -X POST /api/v1/auth/me?token=your_jwt_token_here 38 | 39 | # Authorization Header 40 | $ curl -X POST --header "Authorization: Bearer your_jwt_token_here" /api/v1/auth/me 41 | ``` 42 | 43 | ## Rate limit 44 | 45 | An authenticated user may access the API **60 times** per **minute**. 46 | -------------------------------------------------------------------------------- /docs/docs/api/tasks.md: -------------------------------------------------------------------------------- 1 | # Tasks 2 | 3 | The following endpoints can be used to manage your tasks. 4 | 5 | ## Retrieve all tasks 6 | 7 | ```bash 8 | $ GET /api/v1/tasks 9 | ``` 10 | 11 | ### Responses 12 | 13 | ::: tip Success 14 | **Status**: 200 OK 15 | ::: 16 | 17 | Example : 18 | ```json 19 | { 20 | "data": [ 21 | { 22 | "id": 1, 23 | "title": "Buy pizza on the way to work", 24 | "due_at": null, 25 | "is_completed": false, 26 | "author": { 27 | "id": 1, 28 | "name": "Anakin", 29 | "email": "darthvader@deathstar.ds" 30 | } 31 | }, 32 | { 33 | "id": 2, 34 | "title": "Give a star to this repo", 35 | "due_at": "2018-05-25T12:25:51+02:00", 36 | "is_completed": true, 37 | "author": { 38 | "id": 1, 39 | "name": "Anakin", 40 | "email": "darthvader@deathstar.ds" 41 | } 42 | } 43 | ] 44 | } 45 | ``` 46 | 47 | ::: danger Error 48 | **Status**: 401 Unauthorized 49 | ::: 50 | 51 | Example : 52 | 53 | ```json 54 | { 55 | "message": "Unauthenticated." 56 | } 57 | ``` 58 | 59 | ## Retrieve a task 60 | 61 | ```bash 62 | $ GET /api/v1/tasks/:id 63 | ``` 64 | 65 | ### Responses 66 | 67 | ::: tip Success 68 | **Status**: 200 OK 69 | ::: 70 | 71 | Example : 72 | ```json 73 | { 74 | "data": { 75 | "id": 1, 76 | "title": "Buy pizza on the way to work", 77 | "due_at": null, 78 | "is_completed": false, 79 | "author": { 80 | "id": 1, 81 | "name": "Anakin", 82 | "email": "darthvader@deathstar.ds" 83 | } 84 | } 85 | } 86 | ``` 87 | 88 | ::: danger Error 89 | **Status**: 401 Unauthorized 90 | ::: 91 | 92 | Example : 93 | 94 | ```json 95 | { 96 | "message": "Unauthenticated." 97 | } 98 | ``` 99 | 100 | ::: danger Error 101 | **Status**: 404 Not Found 102 | ::: 103 | 104 | Example : 105 | 106 | ```json 107 | { 108 | "message": "No query results for model [App\\Models\\Task]." 109 | } 110 | ``` 111 | 112 | ## Store a new task 113 | 114 | ```bash 115 | $ POST /api/v1/tasks 116 | ``` 117 | 118 | ### Request 119 | 120 | The `due_at` date will be converted from the timezone you specified and returned in UTC. You need to manage it in your application. 121 | 122 | Query Parameters : 123 | 124 | | Name | Rules | Description | 125 | |--------------|---------------------------|----------------------------| 126 | | title | `required|string|max:255` | Title of the task | 127 | | due_at | `nullable|date` | Due date of the task | 128 | | is_completed | `boolean` | Check if task is completed | 129 | 130 | Example : 131 | ```json 132 | { 133 | "title": "A newly created task" 134 | } 135 | ``` 136 | 137 | ### Responses 138 | 139 | ::: tip Success 140 | **Status**: 200 OK 141 | ::: 142 | 143 | Example : 144 | ```json 145 | { 146 | "data": { 147 | "id": 1, 148 | "title": "A newly created task", 149 | "due_at": null, 150 | "is_completed": false, 151 | "author": { 152 | "id": 1, 153 | "name": "Anakin", 154 | "email": "darthvader@deathstar.ds" 155 | } 156 | } 157 | } 158 | ``` 159 | 160 | ::: danger Error 161 | **Status**: 401 Unauthorized 162 | ::: 163 | 164 | Example : 165 | 166 | ```json 167 | { 168 | "message": "Unauthenticated." 169 | } 170 | ``` 171 | 172 | ::: danger Error 173 | **Status**: 422 Unprocessable Entity 174 | ::: 175 | 176 | Example : 177 | 178 | ```json 179 | { 180 | "message": "The given data was invalid.", 181 | "errors": { 182 | "title": [ 183 | "The title field is required." 184 | ] 185 | } 186 | } 187 | ``` 188 | 189 | ::: danger Error 190 | **Status**: 404 Not Found 191 | ::: 192 | 193 | Example : 194 | 195 | ```json 196 | { 197 | "message": "No query results for model [App\\Models\\Task]." 198 | } 199 | ``` 200 | 201 | ## Update a task 202 | 203 | Update and returns a task. 204 | 205 | ```bash 206 | $ PATCH|PUT /api/v1/tasks/:id 207 | ``` 208 | 209 | ### Request 210 | 211 | Query Parameters : 212 | 213 | | Name | Rules | Description | 214 | |--------------|------------------|----------------------------| 215 | | title | `string|max:255` | Title of the task | 216 | | due_at | `nullable|date` | Due date of the task | 217 | | is_completed | `boolean` | Check if task is completed | 218 | 219 | Example : 220 | ```json 221 | { 222 | "title": "An updated task", 223 | "is_completed": true 224 | } 225 | ``` 226 | 227 | ### Responses 228 | 229 | ::: tip Success 230 | **Status**: 200 OK 231 | ::: 232 | 233 | Example : 234 | ```json 235 | { 236 | "data": { 237 | "id": 1, 238 | "title": "An updated task", 239 | "due_at": null, 240 | "is_completed": true, 241 | "author": { 242 | "id": 1, 243 | "name": "Anakin", 244 | "email": "darthvader@deathstar.ds" 245 | } 246 | } 247 | } 248 | ``` 249 | 250 | ::: danger Error 251 | **Status**: 401 Unauthorized 252 | ::: 253 | 254 | Example : 255 | 256 | ```json 257 | { 258 | "message": "Unauthenticated." 259 | } 260 | ``` 261 | 262 | ::: danger Error 263 | **Status**: 422 Unprocessable Entity 264 | ::: 265 | 266 | Example : 267 | 268 | ```json 269 | { 270 | "message": "The given data was invalid.", 271 | "errors": { 272 | "is_completed": [ 273 | "The is completed field must be true or false." 274 | ] 275 | } 276 | } 277 | ``` 278 | 279 | ::: danger Error 280 | **Status**: 404 Not Found 281 | ::: 282 | 283 | Example : 284 | 285 | ```json 286 | { 287 | "message": "No query results for model [App\\Models\\Task]." 288 | } 289 | ``` 290 | 291 | ## Delete a task 292 | 293 | ```bash 294 | $ DELETE /api/v1/tasks/:id 295 | ``` 296 | 297 | ### Responses 298 | 299 | ::: tip Success 300 | **Status**: 204 No Content 301 | ::: 302 | 303 | ::: danger Error 304 | **Status**: 401 Unauthorized 305 | ::: 306 | 307 | Example : 308 | 309 | ```json 310 | { 311 | "message": "Unauthenticated." 312 | } 313 | ``` 314 | 315 | ::: danger Error 316 | **Status**: 404 Not Found 317 | ::: 318 | 319 | Example : 320 | 321 | ```json 322 | { 323 | "message": "No query results for model [App\\Models\\Task]." 324 | } 325 | ``` 326 | 327 | ## Delete all completed tasks 328 | 329 | ```bash 330 | $ DELETE /api/v1/tasks 331 | ``` 332 | 333 | ### Responses 334 | 335 | ::: tip Success 336 | **Status**: 204 No Content 337 | ::: 338 | 339 | ::: danger Error 340 | **Status**: 401 Unauthorized 341 | ::: 342 | 343 | Example : 344 | 345 | ```json 346 | { 347 | "message": "Unauthenticated." 348 | } 349 | ``` 350 | -------------------------------------------------------------------------------- /docs/docs/api/users.md: -------------------------------------------------------------------------------- 1 | # Accounts and users 2 | 3 | The following endpoints can be used to manage your account. 4 | 5 | ## Register 6 | 7 | Register an account and returns JWT informations. 8 | 9 | ```bash 10 | $ POST /api/v1/auth/register 11 | ``` 12 | 13 | ### Request 14 | 15 | Query Parameters : 16 | 17 | | Name | Rules | Description | 18 | |----------|---------------------------------------|---------------| 19 | | name | `required|alpha_dash|max:255` | Your name | 20 | | email | `required|email|max:255|unique:users` | Your email | 21 | | password | `required|string|min:6|confirmed` | Your password | 22 | 23 | Example : 24 | ```json 25 | { 26 | "name": "Anakin", 27 | "email": "darthvader@deathstar.ds", 28 | "password": "4nak1n", 29 | "password_confirmation": "4nak1n" 30 | } 31 | ``` 32 | 33 | ### Responses 34 | 35 | ::: tip Success 36 | **Status**: 200 OK 37 | ::: 38 | 39 | Example : 40 | ```json 41 | { 42 | "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", 43 | "token_type": "bearer", 44 | "expires_in": "86400", 45 | "user_id": 1 46 | } 47 | ``` 48 | 49 | ::: danger Error 50 | **Status**: 422 Unprocessable Entity 51 | ::: 52 | 53 | Example : 54 | ```json 55 | { 56 | "message": "The given data was invalid.", 57 | "errors": { 58 | "password": [ 59 | "The password field is required." 60 | ] 61 | } 62 | } 63 | ``` 64 | 65 | ## Login 66 | 67 | Login an account and returns JWT information. 68 | 69 | ```bash 70 | $ POST /api/v1/auth/login 71 | ``` 72 | 73 | ### Request 74 | 75 | Query Parameters : 76 | 77 | | Name | Rules | Description | 78 | |----------|-------------------|---------------| 79 | | email | `required|email` | Your name | 80 | | password | `required|string` | Your password | 81 | 82 | Example : 83 | ```json 84 | { 85 | "email": "darthvader@deathstar.ds", 86 | "password": "4nak1n" 87 | } 88 | ``` 89 | 90 | ### Responses 91 | 92 | ::: tip Success 93 | **Status**: 200 OK 94 | ::: 95 | 96 | Example : 97 | ```json 98 | { 99 | "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", 100 | "token_type": "bearer", 101 | "expires_in": "86400", 102 | "user_id": 1 103 | } 104 | ``` 105 | 106 | ::: danger Error 107 | **Status**: 401 Unauthorized 108 | ::: 109 | 110 | Example : 111 | ```json 112 | { 113 | "errors": { 114 | "email": [ 115 | "These credentials do not match our records." 116 | ] 117 | } 118 | } 119 | ``` 120 | 121 | ::: danger Error 122 | **Status**: 422 Unprocessable Entity 123 | ::: 124 | 125 | Example : 126 | ```json 127 | { 128 | "message": "The given data was invalid.", 129 | "errors": { 130 | "password": [ 131 | "The password field is required." 132 | ] 133 | } 134 | } 135 | ``` 136 | 137 | ## Logout 138 | 139 | Log the user out - which will invalidate the current token and unset the authenticated user. 140 | 141 | ```bash 142 | $ DELETE /api/v1/auth/logout 143 | ``` 144 | 145 | ### Responses 146 | 147 | ::: tip Success 148 | **Status**: 200 OK 149 | ::: 150 | 151 | Example : 152 | ```json 153 | { 154 | "message": "Successfully logged out" 155 | } 156 | ``` 157 | 158 | ::: danger Error 159 | **Status**: 401 Unauthorized 160 | ::: 161 | 162 | Example : 163 | ```json 164 | { 165 | "message": "Unauthenticated." 166 | } 167 | ``` 168 | 169 | ## Me 170 | 171 | Returns informations about the authenticated user. 172 | 173 | ```bash 174 | $ GET /api/v1/auth/me 175 | ``` 176 | 177 | ### Responses 178 | 179 | ::: tip Success 180 | **Status**: 200 OK 181 | ::: 182 | 183 | Example : 184 | ```json 185 | { 186 | "data": { 187 | "id": 1, 188 | "name": "Anakin", 189 | "email": "darthvader@deathstar.ds" 190 | } 191 | } 192 | ``` 193 | 194 | ::: danger Error 195 | **Status**: 401 Unauthorized 196 | ::: 197 | 198 | Example : 199 | ```json 200 | { 201 | "message": "Unauthenticated." 202 | } 203 | ``` 204 | 205 | ## Refresh token 206 | 207 | Refresh a token, which invalidates the current one 208 | 209 | ```bash 210 | $ POST /api/v1/auth/refresh 211 | ``` 212 | 213 | ### Responses 214 | 215 | ::: tip Success 216 | **Status**: 200 OK 217 | ::: 218 | 219 | Example : 220 | ```json 221 | { 222 | "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", 223 | "token_type": "bearer", 224 | "expires_in": "86400", 225 | "user_id": 1 226 | } 227 | ``` 228 | 229 | ::: danger Error 230 | **Status**: 401 Unauthorized 231 | ::: 232 | 233 | Example : 234 | ```json 235 | { 236 | "message": "Unauthenticated." 237 | } 238 | ``` 239 | 240 | ## Update your account 241 | 242 | Update and returns an user. You can only update your own account. 243 | 244 | Params are optionals and fields won't be updated if the params are undefined. 245 | 246 | ```bash 247 | $ PATCH|PUT /api/v1/users/:id 248 | ``` 249 | 250 | ### Request 251 | 252 | Query Parameters : 253 | 254 | | Name | Rules | Description | 255 | |------------------|------------------------------|-----------------------| 256 | | name | `alpha_dash|max:255` | Your name | 257 | | email | `email|max:255|unique:users` | Your email | 258 | | current_password | `required_with:password` | Your current password | 259 | | password | `string|min:6|confirmed` | Your new password | 260 | 261 | Example : 262 | ```json 263 | { 264 | "name": "Ben", 265 | "email": "ben@kenobi.jo", 266 | "current_password": "4nak1n", 267 | "password": "4_n3w_h0p3", 268 | "password_confirmation": "4_n3w_h0p3" 269 | } 270 | ``` 271 | 272 | ### Responses 273 | 274 | ::: tip Success 275 | **Status**: 200 OK 276 | ::: 277 | 278 | Example : 279 | ```json 280 | { 281 | "data": { 282 | "id": 1, 283 | "name": "Ben", 284 | "email": "ben@kenobi.jo" 285 | } 286 | } 287 | ``` 288 | 289 | ::: danger Error 290 | **Status**: 401 Unauthorized 291 | ::: 292 | 293 | Example : 294 | 295 | ```json 296 | { 297 | "message": "Unauthenticated." 298 | } 299 | ``` 300 | 301 | ::: danger Error 302 | **Status**: 403 Forbidden 303 | ::: 304 | 305 | Example : 306 | 307 | ```json 308 | { 309 | "message": "This action is unauthorized." 310 | } 311 | ``` 312 | 313 | ::: danger Error 314 | **Status**: 422 Unprocessable Entity 315 | ::: 316 | 317 | Example : 318 | 319 | ```json 320 | { 321 | "message": "The given data was invalid.", 322 | "errors": { 323 | "current_password": [ 324 | "The current password field is required when password is present." 325 | ], 326 | "password": [ 327 | "The password confirmation does not match." 328 | ] 329 | } 330 | } 331 | ``` 332 | 333 | ::: danger Error 334 | **Status**: 404 Not Found 335 | ::: 336 | 337 | Example : 338 | 339 | ```json 340 | { 341 | "message": "No query results for model [App\\Models\\User]." 342 | } 343 | ``` 344 | 345 | ## Delete your account 346 | 347 | Deleting your account will also delete your tasks. 348 | 349 | ```bash 350 | $ DELETE /api/v1/users/:id 351 | ``` 352 | 353 | ### Responses 354 | 355 | ::: tip Success 356 | **Status**: 204 No Content 357 | ::: 358 | 359 | ::: danger Error 360 | **Status**: 401 Unauthorized 361 | ::: 362 | 363 | Example : 364 | 365 | ```json 366 | { 367 | "message": "Unauthenticated." 368 | } 369 | ``` 370 | 371 | ::: danger Error 372 | **Status**: 403 Forbidden 373 | ::: 374 | 375 | Example : 376 | 377 | ```json 378 | { 379 | "message": "This action is unauthorized." 380 | } 381 | ``` 382 | 383 | ::: danger Error 384 | **Status**: 404 Not Found 385 | ::: 386 | 387 | Example : 388 | 389 | ```json 390 | { 391 | "message": "No query results for model [App\\Models\\User]." 392 | } 393 | ``` 394 | -------------------------------------------------------------------------------- /docs/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "yarn build" 3 | publish = "docs/.vuepress/dist" 4 | 5 | [build.environment] 6 | CI = "true" 7 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todolist-docs", 3 | "description": "Todolist docs", 4 | "version": "1.0.0", 5 | "author": "Guillaume Briday ", 6 | "license": "MIT", 7 | "private": true, 8 | "scripts": { 9 | "dev": "vuepress dev docs", 10 | "build": "vuepress build docs" 11 | }, 12 | "dependencies": { 13 | "vuepress": "1.5.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /hosts.example: -------------------------------------------------------------------------------- 1 | [webservers] 2 | example.com 3 | 4 | [all:vars] 5 | ansible_python_interpreter=/usr/bin/python3 6 | 7 | [webservers:vars] 8 | app_url=example.com 9 | 10 | app_key=generate-me 11 | jwt_secret=generate-me 12 | 13 | db_database=change-me 14 | db_username=root 15 | db_password=change-me 16 | 17 | mail_driver=smtp 18 | mail_host=smtp.example.com 19 | mail_port=25 20 | mail_username=change-me 21 | mail_password=change-me 22 | 23 | pusher_app_id=a1b2c3d4 24 | pusher_app_key=a1b2c3d4 25 | pusher_app_secret=a1b2c3d4 26 | pusher_app_cluster=eu -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/Unit 14 | 15 | 16 | 17 | ./tests/Feature 18 | 19 | 20 | 21 | 22 | ./app 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Provisionning webservers group 3 | hosts: webservers 4 | vars: 5 | app_dir: /var/www/todolist-backend 6 | roles: 7 | - app 8 | - docker 9 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Handle Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumebriday/todolist-backend-laravel/71ee99b7d57b2da9f6a730200f697d71e89082a7/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least eight characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, dashes and underscores.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_format' => 'The :attribute does not match the format :format.', 36 | 'different' => 'The :attribute and :other must be different.', 37 | 'digits' => 'The :attribute must be :digits digits.', 38 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 39 | 'dimensions' => 'The :attribute has invalid image dimensions.', 40 | 'distinct' => 'The :attribute field has a duplicate value.', 41 | 'email' => 'The :attribute must be a valid email address.', 42 | 'exists' => 'The selected :attribute is invalid.', 43 | 'file' => 'The :attribute must be a file.', 44 | 'filled' => 'The :attribute field must have a value.', 45 | 'gt' => [ 46 | 'numeric' => 'The :attribute must be greater than :value.', 47 | 'file' => 'The :attribute must be greater than :value kilobytes.', 48 | 'string' => 'The :attribute must be greater than :value characters.', 49 | 'array' => 'The :attribute must have more than :value items.', 50 | ], 51 | 'gte' => [ 52 | 'numeric' => 'The :attribute must be greater than or equal :value.', 53 | 'file' => 'The :attribute must be greater than or equal :value kilobytes.', 54 | 'string' => 'The :attribute must be greater than or equal :value characters.', 55 | 'array' => 'The :attribute must have :value items or more.', 56 | ], 57 | 'image' => 'The :attribute must be an image.', 58 | 'in' => 'The selected :attribute is invalid.', 59 | 'in_array' => 'The :attribute field does not exist in :other.', 60 | 'integer' => 'The :attribute must be an integer.', 61 | 'ip' => 'The :attribute must be a valid IP address.', 62 | 'ipv4' => 'The :attribute must be a valid IPv4 address.', 63 | 'ipv6' => 'The :attribute must be a valid IPv6 address.', 64 | 'json' => 'The :attribute must be a valid JSON string.', 65 | 'lt' => [ 66 | 'numeric' => 'The :attribute must be less than :value.', 67 | 'file' => 'The :attribute must be less than :value kilobytes.', 68 | 'string' => 'The :attribute must be less than :value characters.', 69 | 'array' => 'The :attribute must have less than :value items.', 70 | ], 71 | 'lte' => [ 72 | 'numeric' => 'The :attribute must be less than or equal :value.', 73 | 'file' => 'The :attribute must be less than or equal :value kilobytes.', 74 | 'string' => 'The :attribute must be less than or equal :value characters.', 75 | 'array' => 'The :attribute must not have more than :value items.', 76 | ], 77 | 'max' => [ 78 | 'numeric' => 'The :attribute may not be greater than :max.', 79 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 80 | 'string' => 'The :attribute may not be greater than :max characters.', 81 | 'array' => 'The :attribute may not have more than :max items.', 82 | ], 83 | 'mimes' => 'The :attribute must be a file of type: :values.', 84 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 85 | 'min' => [ 86 | 'numeric' => 'The :attribute must be at least :min.', 87 | 'file' => 'The :attribute must be at least :min kilobytes.', 88 | 'string' => 'The :attribute must be at least :min characters.', 89 | 'array' => 'The :attribute must have at least :min items.', 90 | ], 91 | 'not_in' => 'The selected :attribute is invalid.', 92 | 'not_regex' => 'The :attribute format is invalid.', 93 | 'numeric' => 'The :attribute must be a number.', 94 | 'present' => 'The :attribute field must be present.', 95 | 'regex' => 'The :attribute format is invalid.', 96 | 'required' => 'The :attribute field is required.', 97 | 'required_if' => 'The :attribute field is required when :other is :value.', 98 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 99 | 'required_with' => 'The :attribute field is required when :values is present.', 100 | 'required_with_all' => 'The :attribute field is required when :values is present.', 101 | 'required_without' => 'The :attribute field is required when :values is not present.', 102 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 103 | 'same' => 'The :attribute and :other must match.', 104 | 'size' => [ 105 | 'numeric' => 'The :attribute must be :size.', 106 | 'file' => 'The :attribute must be :size kilobytes.', 107 | 'string' => 'The :attribute must be :size characters.', 108 | 'array' => 'The :attribute must contain :size items.', 109 | ], 110 | 'string' => 'The :attribute must be a string.', 111 | 'timezone' => 'The :attribute must be a valid zone.', 112 | 'unique' => 'The :attribute has already been taken.', 113 | 'uploaded' => 'The :attribute failed to upload.', 114 | 'url' => 'The :attribute format is invalid.', 115 | 'current_password' => "The current password is invalid.", 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Custom Validation Language Lines 120 | |-------------------------------------------------------------------------- 121 | | 122 | | Here you may specify custom validation messages for attributes using the 123 | | convention "attribute.rule" to name the lines. This makes it quick to 124 | | specify a specific custom language line for a given attribute rule. 125 | | 126 | */ 127 | 128 | 'custom' => [ 129 | 'attribute-name' => [ 130 | 'rule-name' => 'custom-message', 131 | ], 132 | ], 133 | 134 | /* 135 | |-------------------------------------------------------------------------- 136 | | Custom Validation Attributes 137 | |-------------------------------------------------------------------------- 138 | | 139 | | The following language lines are used to swap attribute place-holders 140 | | with something more reader friendly such as E-Mail Address instead 141 | | of "email". This simply helps us make messages a little cleaner. 142 | | 143 | */ 144 | 145 | 'attributes' => [], 146 | 147 | ]; 148 | -------------------------------------------------------------------------------- /resources/lang/vendor/backup/en/notifications.php: -------------------------------------------------------------------------------- 1 | 'Exception message: :message', 5 | 'exception_trace' => 'Exception trace: :trace', 6 | 'exception_message_title' => 'Exception message', 7 | 'exception_trace_title' => 'Exception trace', 8 | 9 | 'backup_failed_subject' => 'Failed back up of :application_name', 10 | 'backup_failed_body' => 'Important: An error occurred while backing up :application_name', 11 | 12 | 'backup_successful_subject' => 'Successful new backup of :application_name', 13 | 'backup_successful_subject_title' => 'Successful new backup!', 14 | 'backup_successful_body' => 'Great news, a new backup of :application_name was successfully created on the disk named :disk_name.', 15 | 16 | 'cleanup_failed_subject' => 'Cleaning up the backups of :application_name failed.', 17 | 'cleanup_failed_body' => 'An error occurred while cleaning up the backups of :application_name', 18 | 19 | 'cleanup_successful_subject' => 'Clean up of :application_name backups successful', 20 | 'cleanup_successful_subject_title' => 'Clean up of backups successful!', 21 | 'cleanup_successful_body' => 'The clean up of the :application_name backups on the disk named :disk_name was successful.', 22 | 23 | 'healthy_backup_found_subject' => 'The backups for :application_name on disk :disk_name are healthy', 24 | 'healthy_backup_found_subject_title' => 'The backups for :application_name are healthy', 25 | 'healthy_backup_found_body' => 'The backups for :application_name are considered healthy. Good job!', 26 | 27 | 'unhealthy_backup_found_subject' => 'Important: The backups for :application_name are unhealthy', 28 | 'unhealthy_backup_found_subject_title' => 'Important: The backups for :application_name are unhealthy. :problem', 29 | 'unhealthy_backup_found_body' => 'The backups for :application_name on disk :disk_name are unhealthy.', 30 | 'unhealthy_backup_found_not_reachable' => 'The backup destination cannot be reached. :error', 31 | 'unhealthy_backup_found_empty' => 'There are no backups of this application at all.', 32 | 'unhealthy_backup_found_old' => 'The latest backup made on :date is considered too old.', 33 | 'unhealthy_backup_found_unknown' => 'Sorry, an exact reason cannot be determined.', 34 | 'unhealthy_backup_found_full' => 'The backups are using too much storage. Current usage is :disk_usage which is higher than the allowed limit of :disk_limit.', 35 | ]; 36 | -------------------------------------------------------------------------------- /roles/app/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensures todolist-backend dirs exist 3 | file: 4 | path: "{{ app_dir }}" 5 | state: directory 6 | 7 | - name: Adding .env file 8 | template: 9 | src: ../templates/.env.j2 10 | dest: "{{ app_dir }}/.env" 11 | -------------------------------------------------------------------------------- /roles/app/templates/.env.j2: -------------------------------------------------------------------------------- 1 | APP_NAME="Todolist Backend" 2 | APP_ENV=production 3 | APP_KEY={{ app_key }} 4 | JWT_SECRET={{ jwt_secret }} 5 | JWT_TTL=2880 6 | APP_DEBUG=false 7 | APP_URL={{ app_url }} 8 | 9 | LOG_CHANNEL=stack 10 | LOG_SLACK_WEBHOOK_URL={{ log_slack_webhook_url }} 11 | 12 | DB_CONNECTION=mysql 13 | DB_HOST=todolist-db 14 | DB_DATABASE={{ db_database }} 15 | DB_USERNAME={{ db_username }} 16 | DB_PASSWORD={{ db_password }} 17 | 18 | BROADCAST_DRIVER=pusher 19 | CACHE_DRIVER=file 20 | QUEUE_CONNECTION=sync 21 | SESSION_DRIVER=file 22 | SESSION_LIFETIME=120 23 | 24 | REDIS_HOST=redis 25 | REDIS_PASSWORD=null 26 | REDIS_PORT=6379 27 | 28 | MAIL_DRIVER={{ mail_driver }} 29 | MAIL_HOST={{ mail_host }} 30 | MAIL_PORT={{ mail_port }} 31 | MAIL_USERNAME={{ mail_username }} 32 | MAIL_PASSWORD={{ mail_password }} 33 | MAIL_ENCRYPTION=null 34 | 35 | PUSHER_APP_ID={{ pusher_app_id }} 36 | PUSHER_APP_KEY={{ pusher_app_key }} 37 | PUSHER_APP_SECRET={{ pusher_app_secret }} 38 | PUSHER_APP_CLUSTER={{ pusher_app_cluster }} 39 | -------------------------------------------------------------------------------- /roles/docker/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Pull docker images 3 | docker_image: 4 | name: "{{ item }}" 5 | source: pull 6 | with_items: 7 | - mysql:8 8 | - nginx:latest 9 | - php:7.3-fpm-stretch 10 | 11 | - name: Create the todolist-backend network 12 | docker_network: 13 | name: todolist-backend 14 | 15 | - name: Create the mysql container 16 | docker_container: 17 | name: todolist-db 18 | image: mysql:8 19 | restart_policy: unless-stopped 20 | command: "--default-authentication-plugin=mysql_native_password" 21 | networks: 22 | - name: todolist-backend 23 | volumes: 24 | - "{{ app_dir }}/storage/db:/var/lib/mysql" 25 | env: 26 | MYSQL_DATABASE: "{{ db_database }}" 27 | MYSQL_ROOT_PASSWORD: "{{ db_password }}" 28 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | namespace('V1')->group(function () { 16 | Route::middleware('guest:api')->prefix('auth')->namespace('Auth')->group(function () { 17 | Route::post('register', 'RegisterController@register'); 18 | Route::post('login', 'AuthController@login'); 19 | }); 20 | 21 | Route::middleware('auth:api')->group(function () { 22 | Route::prefix('auth')->namespace('Auth')->group(function () { 23 | Route::delete('logout', 'AuthController@logout'); 24 | Route::post('refresh', 'AuthController@refresh'); 25 | Route::get('me', 'AuthController@me'); 26 | }); 27 | 28 | Route::ApiResource('users', 'UsersController')->only(['update', 'destroy'])->middleware('can:manage,user'); 29 | Route::ApiResource('tasks', 'TasksController'); 30 | Route::delete('tasks', 'TasksController@deleteCompletedTasks'); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | 'auth:api']); 17 | Broadcast::channel('App.User.{id}', TaskChannel::class); 18 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/V1/Auth/AuthTest.php: -------------------------------------------------------------------------------- 1 | anakin(); 16 | 17 | $this->json('POST', '/api/v1/auth/login', [ 18 | 'email' => 'anakin@skywalker.st', 19 | 'password' => '4nak1n' 20 | ]) 21 | ->assertStatus(200) 22 | ->assertJsonStructure([ 23 | 'access_token', 24 | 'token_type', 25 | 'expires_in', 26 | 'user_id', 27 | ]) 28 | ->assertJson([ 29 | 'token_type' => 'bearer', 30 | 'expires_in' => 3600 31 | ]); 32 | } 33 | 34 | /** @test */ 35 | public function user_cannot_retrieve_a_jwt() 36 | { 37 | $this->json('POST', '/api/v1/auth/login', [ 38 | 'email' => 'anakin@skywalker.st', 39 | 'password' => 'Luk3' 40 | ]) 41 | ->assertStatus(401) 42 | ->assertJson([ 43 | 'errors' => [ 44 | 'email' => ['These credentials do not match our records.'] 45 | ] 46 | ]); 47 | } 48 | 49 | /** @test */ 50 | public function user_can_be_authenticated_with_jwt() 51 | { 52 | $anakin = $this->anakin(); 53 | $anakin->wasRecentlyCreated = false; 54 | 55 | $this->actingAs($anakin) 56 | ->json('GET', '/api/v1/auth/me') 57 | ->assertStatus(200) 58 | ->assertJsonStructure([ 59 | 'data' => [ 60 | 'name', 61 | 'email', 62 | ] 63 | ]) 64 | ->assertJson([ 65 | 'data' => [ 66 | 'name' => 'Anakin', 67 | 'email' => 'anakin@skywalker.st' 68 | ] 69 | ]); 70 | } 71 | 72 | /** @test */ 73 | public function user_must_be_authenticated() 74 | { 75 | $this->json('GET', '/api/v1/auth/me') 76 | ->assertStatus(401) 77 | ->assertJson([ 78 | 'message' => 'Unauthenticated.' 79 | ]); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /tests/Feature/V1/TaskTest.php: -------------------------------------------------------------------------------- 1 | anakin(); 17 | factory(Task::class, 3)->create(['user_id' => $anakin]); 18 | 19 | $this->actingAs($anakin) 20 | ->json('GET', '/api/v1/tasks') 21 | ->assertStatus(200) 22 | ->assertJsonStructure([ 23 | 'data' => [[ 24 | 'id', 25 | 'title', 26 | 'due_at', 27 | 'is_completed', 28 | 'author' => [ 29 | 'id', 30 | 'name', 31 | 'email' 32 | ] 33 | ]], 34 | ]) 35 | ->assertJsonCount(3, 'data'); 36 | } 37 | 38 | /** @test */ 39 | public function user_cannot_retrieve_another_tasks() 40 | { 41 | $anakin = $this->anakin(); 42 | factory(Task::class, 3)->create(['user_id' => $anakin]); 43 | factory(Task::class, 3)->create(); 44 | 45 | $this->assertEquals(Task::count(), 6); 46 | 47 | $this->actingAs($anakin) 48 | ->json('GET', '/api/v1/tasks') 49 | ->assertStatus(200) 50 | ->assertJsonCount(3, 'data'); 51 | } 52 | 53 | /** @test */ 54 | public function user_can_retrieve_a_task() 55 | { 56 | $anakin = $this->anakin(); 57 | $task = factory(Task::class)->create(['user_id' => $anakin]); 58 | 59 | $this->actingAs($anakin) 60 | ->json('GET', "/api/v1/tasks/{$task->id}") 61 | ->assertStatus(200) 62 | ->assertJsonStructure([ 63 | 'data' => [ 64 | 'id', 65 | 'title', 66 | 'due_at', 67 | 'author' => [ 68 | 'id', 69 | 'name', 70 | 'email' 71 | ] 72 | ], 73 | ]) 74 | ->assertJson([ 75 | 'data' => [ 76 | 'id' => $task->id, 77 | 'title' => $task->title, 78 | 'due_at' => null, 79 | 'is_completed' => false, 80 | 'author' => [ 81 | 'id' => $anakin->id, 82 | 'name' => $anakin->name, 83 | 'email' => $anakin->email 84 | ] 85 | ] 86 | ]) 87 | ->assertJsonCount(1); 88 | } 89 | 90 | /** @test */ 91 | public function user_cannot_retrieve_a_task() 92 | { 93 | $anakin = $this->anakin(); 94 | $task = factory(Task::class)->create(['user_id' => $anakin]); 95 | 96 | $this->actingAs($this->user()) 97 | ->json('GET', "/api/v1/tasks/{$task->id}") 98 | ->assertStatus(403) 99 | ->assertJson([ 100 | 'message' => 'This action is unauthorized.' 101 | ]); 102 | } 103 | 104 | /** @test */ 105 | public function user_can_update_a_task() 106 | { 107 | $anakin = $this->anakin(); 108 | $task = factory(Task::class)->create(['user_id' => $anakin]); 109 | 110 | $this->actingAs($anakin) 111 | ->json('PATCH', "/api/v1/tasks/{$task->id}", [ 112 | 'title' => 'Get groceries', 113 | 'due_at' => now()->toDateTimeString(), 114 | 'is_completed' => true, 115 | ]) 116 | ->assertStatus(200) 117 | ->assertJsonStructure([ 118 | 'data' => [ 119 | 'id', 120 | 'title', 121 | 'due_at', 122 | 'author' => [ 123 | 'id', 124 | 'name', 125 | 'email' 126 | ] 127 | ], 128 | ]) 129 | ->assertJson([ 130 | 'data' => [ 131 | 'id' => $task->id, 132 | 'title' => 'Get groceries', 133 | 'due_at' => now()->toATOMString(), 134 | 'is_completed' => true, 135 | 'author' => [ 136 | 'id' => $anakin->id, 137 | 'name' => $anakin->name, 138 | 'email' => $anakin->email 139 | ] 140 | ] 141 | ]) 142 | ->assertJsonCount(1); 143 | } 144 | 145 | /** @test */ 146 | public function user_cannot_update_a_task() 147 | { 148 | $anakin = $this->anakin(); 149 | $task = factory(Task::class)->create(['user_id' => $anakin]); 150 | 151 | $this->actingAs($this->user()) 152 | ->json('PATCH', "/api/v1/tasks/{$task->id}", [ 153 | 'title' => 'Get groceries' 154 | ]) 155 | ->assertStatus(403) 156 | ->assertJson([ 157 | 'message' => 'This action is unauthorized.' 158 | ]); 159 | } 160 | 161 | /** @test */ 162 | public function user_can_complete_a_task_without_updating_title() 163 | { 164 | $anakin = $this->anakin(); 165 | $task = factory(Task::class)->create(['user_id' => $anakin]); 166 | 167 | $this->actingAs($anakin) 168 | ->json('PATCH', "/api/v1/tasks/{$task->id}", [ 169 | 'is_completed' => true, 170 | ]) 171 | ->assertStatus(200) 172 | ->assertJsonStructure([ 173 | 'data' => [ 174 | 'id', 175 | 'title', 176 | 'due_at', 177 | 'author' => [ 178 | 'id', 179 | 'name', 180 | 'email' 181 | ] 182 | ], 183 | ]) 184 | ->assertJson([ 185 | 'data' => [ 186 | 'id' => $task->id, 187 | 'title' => $task->title, 188 | 'due_at' => $task->due_at, 189 | 'is_completed' => true, 190 | 'author' => [ 191 | 'id' => $anakin->id, 192 | 'name' => $anakin->name, 193 | 'email' => $anakin->email 194 | ] 195 | ] 196 | ]) 197 | ->assertJsonCount(1); 198 | 199 | $this->assertEquals($task->title, $task->refresh()->title); 200 | $this->assertTrue($task->is_completed); 201 | } 202 | 203 | /** @test */ 204 | public function user_can_create_a_task_with_timezone() 205 | { 206 | $anakin = $this->anakin(); 207 | 208 | $this->actingAs($anakin) 209 | ->json('POST', "/api/v1/tasks", [ 210 | 'title' => 'Get groceries', 211 | 'due_at' => '2018-08-25T12:00:00+02:00' 212 | ]) 213 | ->assertStatus(201) 214 | ->assertJsonStructure([ 215 | 'data' => [ 216 | 'id', 217 | 'title', 218 | 'due_at', 219 | 'author' => [ 220 | 'id', 221 | 'name', 222 | 'email' 223 | ] 224 | ], 225 | ]) 226 | ->assertJson([ 227 | 'data' => [ 228 | 'title' => 'Get groceries', 229 | 'due_at' => '2018-08-25T10:00:00+00:00', 230 | 'is_completed' => false, 231 | 'author' => [ 232 | 'id' => $anakin->id, 233 | 'name' => $anakin->name, 234 | 'email' => $anakin->email 235 | ] 236 | ] 237 | ]) 238 | ->assertJsonCount(1); 239 | } 240 | 241 | /** @test */ 242 | public function user_can_create_a_task_without_timezone() 243 | { 244 | $anakin = $this->anakin(); 245 | 246 | $this->actingAs($anakin) 247 | ->json('POST', "/api/v1/tasks", [ 248 | 'title' => 'Get groceries', 249 | 'due_at' => '2018-08-25 12:00:00' 250 | ]) 251 | ->assertStatus(201) 252 | ->assertJson([ 253 | 'data' => [ 254 | 'due_at' => '2018-08-25T12:00:00+00:00' 255 | ] 256 | ]); 257 | } 258 | 259 | /** @test */ 260 | public function user_can_remove_the_due_at_date() 261 | { 262 | $anakin = $this->anakin(); 263 | $task = factory(Task::class)->create([ 264 | 'user_id' => $anakin, 265 | 'due_at' => now() 266 | ]); 267 | 268 | $this->actingAs($anakin) 269 | ->json('PATCH', "/api/v1/tasks/{$task->id}", [ 270 | 'due_at' => null, 271 | ]) 272 | ->assertStatus(200) 273 | ->assertJson([ 274 | 'data' => [ 275 | 'due_at' => null 276 | ] 277 | ]); 278 | } 279 | 280 | /** @test */ 281 | public function user_can_delete_a_task() 282 | { 283 | $anakin = $this->anakin(); 284 | $task = factory(Task::class)->create(['user_id' => $anakin]); 285 | 286 | $this->actingAs($anakin) 287 | ->json('DELETE', "/api/v1/tasks/{$task->id}") 288 | ->assertStatus(204); 289 | 290 | $this->assertDatabaseMissing('tasks', $task->toArray()); 291 | } 292 | 293 | /** @test */ 294 | public function user_cannot_delete_a_task() 295 | { 296 | $anakin = $this->anakin(); 297 | $task = factory(Task::class)->create(['user_id' => $anakin]); 298 | 299 | $this->actingAs($this->user()) 300 | ->json('DELETE', "/api/v1/tasks/{$task->id}") 301 | ->assertStatus(403) 302 | ->assertJson([ 303 | 'message' => 'This action is unauthorized.' 304 | ]); 305 | 306 | $this->assertDatabaseHas('tasks', $task->toArray()); 307 | } 308 | 309 | /** @test */ 310 | public function user_can_delete_all_completed_tasks() 311 | { 312 | $anakin = $this->anakin(); 313 | factory(Task::class, 2)->create(['user_id' => $anakin]); 314 | factory(Task::class, 2)->states('completed')->create(['user_id' => $anakin]); 315 | 316 | $this->actingAs($anakin) 317 | ->json('DELETE', '/api/v1/tasks') 318 | ->assertStatus(204); 319 | 320 | $this->assertEmpty(Task::completed()->get()); 321 | $this->assertCount(2, Task::all()); 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /tests/Feature/V1/UserTest.php: -------------------------------------------------------------------------------- 1 | anakin(); 18 | $tasks = factory(Task::class, 3)->create(['user_id' => $anakin]); 19 | 20 | $this->actingAs($anakin) 21 | ->json('DELETE', "/api/v1/users/{$anakin->id}") 22 | ->assertStatus(204); 23 | 24 | $this->assertEmpty(Task::all()); 25 | $this->assertDatabaseMissing('users', $anakin->toArray()); 26 | } 27 | 28 | /** @test */ 29 | public function user_can_update_his_account() 30 | { 31 | $anakin = $this->anakin(); 32 | 33 | $this->actingAs($anakin) 34 | ->json('PATCH', "/api/v1/users/{$anakin->id}", [ 35 | 'email' => 'ben@kenobi.jo', 36 | 'name' => 'Ben', 37 | ]) 38 | ->assertStatus(200) 39 | ->assertJsonStructure([ 40 | 'data' => [ 41 | 'id', 42 | 'name', 43 | 'email', 44 | ], 45 | ]) 46 | ->assertJson([ 47 | 'data' => [ 48 | 'id' => $anakin->id, 49 | 'name' => 'Ben', 50 | 'email' => 'ben@kenobi.jo', 51 | ] 52 | ]) 53 | ->assertJsonCount(1); 54 | 55 | $anakin->refresh(); 56 | 57 | $this->assertEquals('ben@kenobi.jo', $anakin->email); 58 | $this->assertEquals('Ben', $anakin->name); 59 | } 60 | 61 | /** @test */ 62 | public function user_cannot_update_another_account() 63 | { 64 | $user = $this->user(); 65 | 66 | $this->actingAs($this->anakin()) 67 | ->json('PATCH', "/api/v1/users/{$user->id}", [ 68 | 'email' => 'ben@kenobi.jo', 69 | 'name' => 'Ben', 70 | ]) 71 | ->assertStatus(403) 72 | ->assertJson([ 73 | 'message' => 'This action is unauthorized.' 74 | ]); 75 | } 76 | 77 | /** @test */ 78 | public function user_can_update_his_password() 79 | { 80 | $anakin = $this->anakin(); 81 | 82 | $this->actingAs($anakin) 83 | ->json('PATCH', "/api/v1/users/{$anakin->id}", [ 84 | 'current_password' => '4nak1n', 85 | 'password' => '4_n3w_h0p3', 86 | 'password_confirmation' => '4_n3w_h0p3' 87 | ]) 88 | ->assertStatus(200) 89 | ->assertJsonStructure([ 90 | 'data' => [ 91 | 'id', 92 | 'name', 93 | 'email', 94 | ], 95 | ]) 96 | ->assertJson([ 97 | 'data' => [ 98 | 'id' => $anakin->id, 99 | 'name' => $anakin->name, 100 | 'email' => $anakin->email, 101 | ] 102 | ]) 103 | ->assertJsonCount(1); 104 | 105 | $this->assertTrue(Hash::check('4_n3w_h0p3', $anakin->refresh()->password)); 106 | } 107 | 108 | /** @test */ 109 | public function user_cannot_update_his_password_without_current_password_and_password_confirmation() 110 | { 111 | $anakin = $this->anakin(); 112 | 113 | $this->actingAs($anakin) 114 | ->json('PATCH', "/api/v1/users/{$anakin->id}", [ 115 | 'password' => '4_n3w_h0p3', 116 | ]) 117 | ->assertStatus(422) 118 | ->assertJsonStructure([ 119 | 'message', 120 | 'errors' => [ 121 | 'current_password', 122 | 'password', 123 | ], 124 | ]) 125 | ->assertJson([ 126 | 'message' => 'The given data was invalid.', 127 | 'errors' => [ 128 | 'current_password' => [ 129 | 'The current password field is required when password is present.' 130 | ], 131 | 'password' => [ 132 | 'The password confirmation does not match.' 133 | ], 134 | ] 135 | ]); 136 | 137 | $this->assertFalse(Hash::check('4_n3w_h0p3', $anakin->refresh()->password)); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | states('anakin')->create($overrides); 21 | } 22 | 23 | /** 24 | * Return an user 25 | * @return User 26 | */ 27 | protected function user($overrides = []) 28 | { 29 | return factory(User::class)->create($overrides); 30 | } 31 | 32 | /** 33 | * Acting as an user 34 | */ 35 | protected function actingAsUser() 36 | { 37 | $this->actingAs($this->user()); 38 | 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Unit/TaskTest.php: -------------------------------------------------------------------------------- 1 | anakin(); 17 | $this->actingAs($anakin); 18 | 19 | $NotCompletedTask = factory(Task::class)->create(['user_id' => $anakin->id]); 20 | $completedTask = factory(Task::class)->states('completed')->create(['user_id' => $anakin->id]); 21 | 22 | $this->assertTrue($completedTask->is_completed); 23 | $this->assertFalse($NotCompletedTask->is_completed); 24 | } 25 | 26 | /** @test */ 27 | public function only_completed_tasks_are_returned() 28 | { 29 | $anakin = $this->anakin(); 30 | $this->actingAs($anakin); 31 | 32 | factory(Task::class, 2)->create(['user_id' => $anakin->id]); 33 | factory(Task::class, 2)->states('completed')->create(['user_id' => $anakin->id]); 34 | 35 | $onlyCompleted = true; 36 | foreach (Task::completed()->get() as $task) { 37 | $onlyCompleted = $task->is_completed; 38 | 39 | if (! $onlyCompleted) { 40 | break; 41 | } 42 | } 43 | 44 | $this->assertTrue($onlyCompleted); 45 | $this->assertCount(4, Task::all()); 46 | $this->assertCount(2, Task::completed()->get()); 47 | } 48 | } 49 | --------------------------------------------------------------------------------