Skip to content

Commit bf5c648

Browse files
committed
init
0 parents  commit bf5c648

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+7899
-0
lines changed

.env.example

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the later taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_URL=http://localhost:8000/
18+
APP_ENV=dev
19+
APP_SECRET=0391653b377d8c616c0b0d0e8d0d042f
20+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
21+
#TRUSTED_HOSTS='^localhost|example\.com$'
22+
###< symfony/framework-bundle ###
23+
###> doctrine/doctrine-bundle ###
24+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
25+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
26+
# Configure your db driver and server_version in config/packages/doctrine.yaml
27+
DATABASE_URL=mysql://root:000000@127.0.0.1:3306/resftul
28+
###< doctrine/doctrine-bundle ###
29+
30+
###> lexik/jwt-authentication-bundle ###
31+
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
32+
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
33+
JWT_PASSPHRASE=overseasmedia
34+
###< lexik/jwt-authentication-bundle ###
35+
36+
###> nelmio/cors-bundle ###
37+
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
38+
###< nelmio/cors-bundle ###

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Symfony Todo API
2+
---
3+
### About the series
4+
[Playlist to all the videos](https://www.youtube.com/playlist?list=PLqhuffi3fiMN_jVxqlIAILEp4avoBH4wc)
5+
This series goes over how to create a really __BASIC__ Symfony API, yeah i didn't use API platform but that's okay, Below is a list of all the libraries that were used in the series.
6+
7+
## Libraries
8+
* [FOSRestBundle
9+
](https://github.com/FriendsOfSymfony/FOSRestBundle)
10+
* [LexikJWTAuthenticationBundle
11+
](https://github.com/lexik/LexikJWTAuthenticationBundle)
12+
* [JWTRefreshTokenBundle
13+
](https://github.com/gesdinet/JWTRefreshTokenBundle)
14+
* [NelmioCorsBundle
15+
](https://github.com/nelmio/NelmioCorsBundle)
16+
* Will update if i forgot something
17+
18+
## Mistakes were made
19+
I admit that a lot of the time i either said something that was misleading or i used the incorrect thing, let me explain.
20+
* Sometimes i returned a status code of 200 instead of 201 when __CREATING__.
21+
* __CLARIFICATION__: PATCH vs PUT, i said that PATCH is used to update a part of the document, i might have said it's used to update just one field or property but that's not true, it's used to update multiple parts but not the entire document, otherwise why you would use PATCH instead of PUT, thign mistake happened because the example i was looking had just one property and i said it used to update just one.
22+
23+
# Create a user manually (for testing)
24+
25+
This is a complete section by itself because it seems like couple of people have had their share of headaches because of this, to create a user manually and save it in the dabase here's what i personally do, __IT WORKS__
26+
27+
### Encode the password using the symfony command
28+
29+
This is extremely important especially if you have no idea what the hell is happening, use the following command to generate a hashed version of your password and then jut copy the value that was printed to you and put in your database.
30+
Command: __php bin/console security:encode-password__
31+
You will be prompted to enter the plaintext password that you want to be hashed, after clicking the return key (enter key) the hashed key will be generated for you.
32+
33+
### Fields that i care about in the database
34+
35+
There are three main fields that i care about, and they are the email, password, roles.
36+
Theses are the value that i enter for my testing user just to make sure that my authentication system works.
37+
38+
* email: __admin@admin.com__
39+
* roles: __["ROLE_USER"]__
40+
* password: __\$2y\$13\$XPRUnZV1V9NI7Tya/a7fh.8/86VIZTA3LIA.4mKeuadnFDy2HqFNu__
41+
42+
43+
__NOTE ABOUT THE PASSWORD: This password is the hashed version of [000000], just six zeros, and i got this result because the algorithm in the security file is set to auto, if you have bcrypt it could be different if you have a2rgony or whatever the hell that one is called, you will get something different__
44+
45+
# Troubleshooting and stuff
46+
47+
## Bad credentials error
48+
49+
This one error could happen because of multiple error due to the very bad error reporting of this library or whatever is responsible for that, the main thing to keep in mind is anything could lead to this type of problems
50+
51+
## Examples
52+
* Database server not running will throw this error.
53+
* The password is not encoded in the correct way.
54+
* You didn't generate the public and private keys files correctly.
55+
* The passphrase used during public and private key generation does not match the one used in the configuration file.
56+
* TODO (Add more as more emails come in)
57+
58+
# Contributing
59+
This project is open for everyone, if you notice anything wrong with my code, or even this readme, any mistakes are welcome.
60+
61+
# Questions
62+
Maybe this should've been above with the Contribution section but doesn't matter, if you have any question i think it would be nice to create an issue (Please open an issue no matter how _trivial_ you think the question is, no one will charge you money for it) that way people with similar questions can look them up.

bin/console

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
9+
set_time_limit(0);
10+
11+
require dirname(__DIR__).'/vendor/autoload.php';
12+
13+
if (!class_exists(Application::class)) {
14+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
15+
}
16+
17+
$input = new ArgvInput();
18+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
19+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
20+
}
21+
22+
if ($input->hasParameterOption('--no-debug', true)) {
23+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
24+
}
25+
26+
require dirname(__DIR__).'/config/bootstrap.php';
27+
28+
if ($_SERVER['APP_DEBUG']) {
29+
umask(0000);
30+
31+
if (class_exists(Debug::class)) {
32+
Debug::enable();
33+
}
34+
}
35+
36+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
37+
$application = new Application($kernel);
38+
$application->run($input);

composer.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"type": "project",
3+
"license": "proprietary",
4+
"require": {
5+
"php": "^7.1.3",
6+
"ext-ctype": "*",
7+
"ext-iconv": "*",
8+
"friendsofsymfony/rest-bundle": "^2.5",
9+
"gesdinet/jwt-refresh-token-bundle": "^0.6.2",
10+
"lexik/jwt-authentication-bundle": "^2.6",
11+
"nelmio/cors-bundle": "^1.5",
12+
"sensio/framework-extra-bundle": "^5.3",
13+
"symfony/asset": "4.2.*",
14+
"symfony/console": "4.2.*",
15+
"symfony/dotenv": "4.2.*",
16+
"symfony/flex": "^1.1",
17+
"symfony/framework-bundle": "4.2.*",
18+
"symfony/maker-bundle": "^1.11",
19+
"symfony/orm-pack": "^1.0",
20+
"symfony/serializer-pack": "^1.0",
21+
"symfony/twig-bundle": "4.2.*",
22+
"symfony/validator": "4.2.*",
23+
"symfony/web-server-bundle": "4.2.*",
24+
"symfony/yaml": "4.2.*"
25+
},
26+
"config": {
27+
"preferred-install": {
28+
"*": "dist"
29+
},
30+
"sort-packages": true
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"App\\": "src/"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"App\\Tests\\": "tests/"
40+
}
41+
},
42+
"replace": {
43+
"paragonie/random_compat": "2.*",
44+
"symfony/polyfill-ctype": "*",
45+
"symfony/polyfill-iconv": "*",
46+
"symfony/polyfill-php71": "*",
47+
"symfony/polyfill-php70": "*",
48+
"symfony/polyfill-php56": "*"
49+
},
50+
"scripts": {
51+
"auto-scripts": {
52+
"cache:clear": "symfony-cmd",
53+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
54+
},
55+
"post-install-cmd": [
56+
"@auto-scripts"
57+
],
58+
"post-update-cmd": [
59+
"@auto-scripts"
60+
]
61+
},
62+
"conflict": {
63+
"symfony/symfony": "*"
64+
},
65+
"extra": {
66+
"symfony": {
67+
"allow-contrib": false,
68+
"require": "4.2.*"
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)