Skip to content
Snippets Groups Projects
Commit e5957829 authored by PEREZ-RAMIREZ Julian's avatar PEREZ-RAMIREZ Julian
Browse files

editing fixtures files to created sample records

parent a84b8792
Branches remove-reset
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ php bin/console doctrine:migrations:migrate prev ...@@ -32,6 +32,7 @@ php bin/console doctrine:migrations:migrate prev
To add sample data per dafault to the database (after finished editing DataFixtures/ files) To add sample data per dafault to the database (after finished editing DataFixtures/ files)
Note: Add the `--append` flag if you don't want to erase the records already created. Note: Add the `--append` flag if you don't want to erase the records already created.
Also add `--group` to apply and specific file.
``` ```
php bin/console doctrine:fixtures:load php bin/console doctrine:fixtures:load
``` ```
\ No newline at end of file
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"symfony/flex": "^2", "symfony/flex": "^2",
"symfony/framework-bundle": "7.2.*", "symfony/framework-bundle": "7.2.*",
"symfony/runtime": "7.2.*", "symfony/runtime": "7.2.*",
"symfony/security-bundle": "7.2.*",
"symfony/security-core": "7.2.*",
"symfony/yaml": "7.2.*" "symfony/yaml": "7.2.*"
}, },
"config": { "config": {
......
...@@ -6,4 +6,5 @@ return [ ...@@ -6,4 +6,5 @@ return [
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
]; ];
security:
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
users_in_memory: { memory: null }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: users_in_memory
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
# 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 }
when@test:
security:
password_hashers:
# By default, password hashers are resource intensive and take time. This is
# important to generate secure password hashes. In tests however, secure hashes
# are not important, waste resources and increase test times. The following
# reduces the work factor to the lowest possible values.
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
algorithm: auto
cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon
_security_logout:
resource: security.route_loader.logout
type: service
...@@ -5,9 +5,11 @@ namespace App\Entity; ...@@ -5,9 +5,11 @@ namespace App\Entity;
use App\Enum\UserRole; use App\Enum\UserRole;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)] #[ORM\Entity(repositoryClass: UserRepository::class)]
class User class User implements UserInterface, PasswordAuthenticatedUserInterface
{ {
#[ORM\Id] #[ORM\Id]
#[ORM\GeneratedValue] #[ORM\GeneratedValue]
...@@ -138,4 +140,20 @@ class User ...@@ -138,4 +140,20 @@ class User
return $this; return $this;
} }
//Methods neeeded to be implemented here because of the extension of UserInterface, PasswordAuthenticatedUserInterface
public function getRoles(): array
{
return [$this->role->value]; // Assuming UserRole is an enum with string values
}
public function getUserIdentifier(): string
{
return $this->email; // Or another unique identifier like username
}
public function eraseCredentials(): void
{
// If storing temporary sensitive data, clear it here
}
} }
...@@ -103,5 +103,18 @@ ...@@ -103,5 +103,18 @@
"config/packages/routing.yaml", "config/packages/routing.yaml",
"config/routes.yaml" "config/routes.yaml"
] ]
},
"symfony/security-bundle": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.4",
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
},
"files": [
"config/packages/security.yaml",
"config/routes/security.yaml"
]
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment