diff --git a/config/packages/security.yaml b/config/packages/security.yaml index fb4c593e..e7bdf841 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,7 +1,15 @@ security: + encoders: + App\Entity\User: + algorithm: bcrypt + # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers providers: - in_memory: { memory: ~ } + # used to reload user from session & other features (e.g. switch_user) + app_user_provider: + entity: + class: App\Entity\User + property: name firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ @@ -9,16 +17,24 @@ security: main: anonymous: true - # activate different ways to authenticate + # activate different ways to authenticate - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate + #http_basic: true + # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - # form_login: true # https://symfony.com/doc/current/security/form_login_setup.html + form_login: + login_path: login + check_path: login + csrf_token_generator: security.csrf.token_manager + use_referer: true + + logout: + path: logout + target: homepage # 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 } + # - { path: ^/admin, roles: ROLE_ADMIN } + # - { path: ^/profile, roles: ROLE_USER } diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php new file mode 100644 index 00000000..1ae5d2f4 --- /dev/null +++ b/src/Controller/SecurityController.php @@ -0,0 +1,66 @@ +getLastAuthenticationError(); + + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', [ + 'last_username' => $lastUsername, + 'error' => $error, + ]); + } + + /** + * @Route("/logout", name="logout") + */ + public function logout() + { + throw new \Exception('Will be intercepted before getting here'); + } + +} \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php new file mode 100644 index 00000000..a18f373a --- /dev/null +++ b/src/Entity/User.php @@ -0,0 +1,314 @@ +name; + } + + /** + * @see UserInterface + */ + public function getRoles(): array + { + $roles = []; + //$roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + public function setRoles(array $roles): self + { + //$this->roles = $roles; + + return $this; + } + + /** + * @see UserInterface + */ + public function getPassword(): string + { + return (string) $this->password; + } + + public function setPassword(string $password): self + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function getSalt() + { + // not needed when using the "bcrypt" algorithm in security.yaml + } + + /** + * @see UserInterface + */ + public function eraseCredentials() + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } + + /** + * Returns the ID as an string, defined by the element class. + * This should have a form like P000014, for a part with ID 14. + * @return string The ID as a string; + */ + public function getIDString(): string + { + return "U" . $this->getID(); + } + + + /************************************************ + * Getters + ************************************************/ + + /** + * @return string + */ + public function getFirstName(): string + { + return $this->first_name; + } + + /** + * @param string $first_name + * @return User + */ + public function setFirstName(string $first_name): User + { + $this->first_name = $first_name; + return $this; + } + + /** + * @return string + */ + public function getLastName(): string + { + return $this->last_name; + } + + /** + * @param string $last_name + * @return User + */ + public function setLastName(string $last_name): User + { + $this->last_name = $last_name; + return $this; + } + + /** + * @return string + */ + public function getDepartment(): string + { + return $this->department; + } + + /** + * @param string $department + * @return User + */ + public function setDepartment(string $department): User + { + $this->department = $department; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $email + * @return User + */ + public function setEmail(string $email): User + { + $this->email = $email; + return $this; + } + + /** + * @return string + */ + public function getLanguage(): string + { + return $this->language; + } + + /** + * @param string $language + * @return User + */ + public function setLanguage(string $language): User + { + $this->language = $language; + return $this; + } + + /** + * @return string + */ + public function getTimezone(): string + { + return $this->timezone; + } + + /** + * @param string $timezone + * @return User + */ + public function setTimezone(string $timezone): User + { + $this->timezone = $timezone; + return $this; + } + + /** + * @return string + */ + public function getTheme(): string + { + return $this->theme; + } + + /** + * @param string $theme + * @return User + */ + public function setTheme(string $theme): User + { + $this->theme = $theme; + return $this; + } + +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php new file mode 100644 index 00000000..8e822023 --- /dev/null +++ b/src/Repository/UserRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('u') + ->andWhere('u.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('u.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?User + { + return $this->createQueryBuilder('u') + ->andWhere('u.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/templates/base.html.twig b/templates/base.html.twig index d9baa0b9..ee3cb7fb 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -81,16 +81,16 @@