Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 38 additions & 21 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
security:
# https://symfony.com/doc/current/security/experimental_authenticators.html
enable_authenticator_manager: true
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
users_in_memory: { memory: null }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: users_in_memory
# https://symfony.com/doc/current/security/experimental_authenticators.html
enable_authenticator_manager: true
password_hashers:
App\Entity\User:
algorithm: auto

# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: app_user_provider
custom_authenticator: App\Security\AppUserAuthenticator
remember_me:
secret: "%kernel.secret%"
lifetime: 604800 # 1 week in seconds
path: /
logout:
path: app_logout
# where to redirect after logout
target: home

# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
97 changes: 97 additions & 0 deletions migrations/Version20210816115519.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210816115519 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE billing_address (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, civic VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, state VARCHAR(50) NOT NULL, country VARCHAR(50) NOT NULL, postal_code VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_6660E456A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE category (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, excerpt VARCHAR(255) NOT NULL, icon VARCHAR(100) NOT NULL, parent_id INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE discount (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, rate DOUBLE PRECISION NOT NULL, start DATETIME NOT NULL, end DATETIME NOT NULL, UNIQUE INDEX UNIQ_E1E0B40E4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE fund (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, type VARCHAR(50) NOT NULL, account VARCHAR(50) NOT NULL, name VARCHAR(100) NOT NULL, expiration DATETIME NOT NULL, code VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_DC923E10A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE `order` (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, status VARCHAR(50) NOT NULL, edited_at DATETIME NOT NULL, INDEX IDX_F5299398A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE ordered_product (id INT AUTO_INCREMENT NOT NULL, order_id INT NOT NULL, product_id INT NOT NULL, quantity INT NOT NULL, INDEX IDX_E6F097B68D9F6D38 (order_id), INDEX IDX_E6F097B64584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE payment (id INT AUTO_INCREMENT NOT NULL, order_id INT NOT NULL, type VARCHAR(50) NOT NULL, amount DOUBLE PRECISION NOT NULL, status VARCHAR(50) NOT NULL, date DATETIME NOT NULL, UNIQUE INDEX UNIQ_6D28840D8D9F6D38 (order_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE photo (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, title VARCHAR(50) NOT NULL, caption VARCHAR(50) NOT NULL, url VARCHAR(255) NOT NULL, INDEX IDX_14B784184584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, category_id INT NOT NULL, user_id INT NOT NULL, name VARCHAR(50) NOT NULL, excerpt LONGTEXT NOT NULL, description LONGTEXT NOT NULL, quantity INT NOT NULL, price DOUBLE PRECISION NOT NULL, edited_at DATETIME NOT NULL, INDEX IDX_D34A04AD12469DE2 (category_id), INDEX IDX_D34A04ADA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE profile (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, photo VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_nane VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, phone_number VARCHAR(45) NOT NULL, UNIQUE INDEX UNIQ_8157AA0FA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE role (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE shipment (id INT AUTO_INCREMENT NOT NULL, order_id INT NOT NULL, service VARCHAR(50) NOT NULL, recipient VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, status VARCHAR(50) NOT NULL, delivery_time DATETIME NOT NULL, UNIQUE INDEX UNIQ_2CB20DC8D9F6D38 (order_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE shipping (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, service VARCHAR(50) NOT NULL, region VARCHAR(50) NOT NULL, cost DOUBLE PRECISION NOT NULL, delivery_date DATETIME NOT NULL, INDEX IDX_2D1C17244584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE specification (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, name VARCHAR(50) NOT NULL, value VARCHAR(50) NOT NULL, INDEX IDX_E3F1A9A4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE tax (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, name VARCHAR(50) NOT NULL, rate DOUBLE PRECISION NOT NULL, INDEX IDX_8E81BA764584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_role (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, role_id INT NOT NULL, INDEX IDX_2DE8C6A3A76ED395 (user_id), INDEX IDX_2DE8C6A3D60322AC (role_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE billing_address ADD CONSTRAINT FK_6660E456A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE discount ADD CONSTRAINT FK_E1E0B40E4584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE fund ADD CONSTRAINT FK_DC923E10A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE `order` ADD CONSTRAINT FK_F5299398A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE ordered_product ADD CONSTRAINT FK_E6F097B68D9F6D38 FOREIGN KEY (order_id) REFERENCES `order` (id)');
$this->addSql('ALTER TABLE ordered_product ADD CONSTRAINT FK_E6F097B64584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE payment ADD CONSTRAINT FK_6D28840D8D9F6D38 FOREIGN KEY (order_id) REFERENCES `order` (id)');
$this->addSql('ALTER TABLE photo ADD CONSTRAINT FK_14B784184584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD12469DE2 FOREIGN KEY (category_id) REFERENCES category (id)');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04ADA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE profile ADD CONSTRAINT FK_8157AA0FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipment ADD CONSTRAINT FK_2CB20DC8D9F6D38 FOREIGN KEY (order_id) REFERENCES `order` (id)');
$this->addSql('ALTER TABLE shipping ADD CONSTRAINT FK_2D1C17244584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE specification ADD CONSTRAINT FK_E3F1A9A4584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE tax ADD CONSTRAINT FK_8E81BA764584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3D60322AC FOREIGN KEY (role_id) REFERENCES role (id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04AD12469DE2');
$this->addSql('ALTER TABLE ordered_product DROP FOREIGN KEY FK_E6F097B68D9F6D38');
$this->addSql('ALTER TABLE payment DROP FOREIGN KEY FK_6D28840D8D9F6D38');
$this->addSql('ALTER TABLE shipment DROP FOREIGN KEY FK_2CB20DC8D9F6D38');
$this->addSql('ALTER TABLE discount DROP FOREIGN KEY FK_E1E0B40E4584665A');
$this->addSql('ALTER TABLE ordered_product DROP FOREIGN KEY FK_E6F097B64584665A');
$this->addSql('ALTER TABLE photo DROP FOREIGN KEY FK_14B784184584665A');
$this->addSql('ALTER TABLE shipping DROP FOREIGN KEY FK_2D1C17244584665A');
$this->addSql('ALTER TABLE specification DROP FOREIGN KEY FK_E3F1A9A4584665A');
$this->addSql('ALTER TABLE tax DROP FOREIGN KEY FK_8E81BA764584665A');
$this->addSql('ALTER TABLE user_role DROP FOREIGN KEY FK_2DE8C6A3D60322AC');
$this->addSql('ALTER TABLE billing_address DROP FOREIGN KEY FK_6660E456A76ED395');
$this->addSql('ALTER TABLE fund DROP FOREIGN KEY FK_DC923E10A76ED395');
$this->addSql('ALTER TABLE `order` DROP FOREIGN KEY FK_F5299398A76ED395');
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04ADA76ED395');
$this->addSql('ALTER TABLE profile DROP FOREIGN KEY FK_8157AA0FA76ED395');
$this->addSql('ALTER TABLE user_role DROP FOREIGN KEY FK_2DE8C6A3A76ED395');
$this->addSql('DROP TABLE billing_address');
$this->addSql('DROP TABLE category');
$this->addSql('DROP TABLE discount');
$this->addSql('DROP TABLE fund');
$this->addSql('DROP TABLE `order`');
$this->addSql('DROP TABLE ordered_product');
$this->addSql('DROP TABLE payment');
$this->addSql('DROP TABLE photo');
$this->addSql('DROP TABLE product');
$this->addSql('DROP TABLE profile');
$this->addSql('DROP TABLE role');
$this->addSql('DROP TABLE shipment');
$this->addSql('DROP TABLE shipping');
$this->addSql('DROP TABLE specification');
$this->addSql('DROP TABLE tax');
$this->addSql('DROP TABLE user');
$this->addSql('DROP TABLE user_role');
}
}
75 changes: 75 additions & 0 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Controller;

use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class AccountController extends AbstractController
{
/**
* @Route("/account", name="account")
*/

public function index(): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('home');
}

return $this->render('account/index.html.twig');
}
/**
* @Route("/login", name="user_login")
*/

public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('home');
}

// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();

return $this->render('account/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/register", name="user_register")
*/
public function register(Request $request, UserPasswordHasherInterface $hasher): Response
{
if ($request->request->get('password') !== $request->request->get('confirm')) {
echo ('Confirmation Password does not match with Password...');
} else {
if ($request->request->get('email') != null && $request->request->get('password') != null) {
$em = $this->getDoctrine()->getManager();
$user = new User();
// $user->firstname = $request->request->get('first_name');
// $user->lastname = $request->request->get('last_name');
$user->setEmail($request->request->get('email'));
$user->setPassword($hasher->hashPassword($user, $request->request->get('password')));
$em->persist($user);
$em->flush();
return $this->redirect("/");
}
}
return $this->render('account/register.html.twig');
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
9 changes: 0 additions & 9 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,4 @@ public function cart(): Response
// 'controller_name' => 'HomeController',
// ]);
}
/**
* @Route("/account", name="account")
*/
public function account(): Response
{
return $this->render('account/login-register.html.twig', [
'controller_name' => 'HomeController',
]);
}
}
Loading