add active class for nav

This commit is contained in:
Tykayn 2024-07-16 11:44:30 +02:00 committed by tykayn
parent 9a6405e418
commit 6857cad565
12 changed files with 127 additions and 30 deletions

View File

@ -1,6 +1,11 @@
#account_main{ #account_main{
menu{ display: flex;
width: 10rem; #account_nav{
width: 20rem;
padding: 1rem; padding: 1rem;
}
#account_main_content{
width: 30rem;
} }
} }

View File

@ -3,10 +3,17 @@
} }
a{ a{
@extend .clickable; @extend .clickable;
padding: 0.5rem 1rem;
display: inline-block;
color: $primary_color; color: $primary_color;
text-decoration: none;
&:hover{ &:hover{
color: $primary_color_darker; color: $primary_color_darker;
} }
&.active{
background: $bg_active_link;
color: $active_link_text;
}
} }
button{ button{
@extend .clickable; @extend .clickable;

View File

@ -2,3 +2,5 @@ $bg_color:lightgray;
$bg_main_color: white; $bg_main_color: white;
$primary_color: #98c87e; $primary_color: #98c87e;
$primary_color_darker: #537b3d; $primary_color_darker: #537b3d;
$bg_active_link: $primary_color_darker;
$active_link_text: white;

View File

@ -1,4 +1,7 @@
security: security:
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers: password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
@ -18,7 +21,13 @@ security:
provider: app_user_provider provider: app_user_provider
# by default, the feature allows 5 login attempts per minute # by default, the feature allows 5 login attempts per minute
# login_throttling: null # login_throttling: null
remember_me:
secret: '%kernel.secret%' # required
lifetime: 604800 # 1 week in seconds
# by default, the feature is enabled by checking a
# checkbox in the login form (see below), uncomment the
# following line to always enable it.
#always_remember_me: true
# configure the maximum login attempts # configure the maximum login attempts
login_throttling: login_throttling:
max_attempts: 3 # per minute ... max_attempts: 3 # per minute ...
@ -45,6 +54,7 @@ security:
access_control: access_control:
- { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/profile, roles: ROLE_USER } - { path: ^/profile, roles: ROLE_USER }
- { path: ^/account, roles: ROLE_USER }
when@test: when@test:
security: security:

View File

@ -0,0 +1,31 @@
<?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 Version20240716092119 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('ALTER TABLE user ADD last_login DATE DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `user` DROP last_login');
}
}

View File

@ -15,6 +15,9 @@ class AccountController extends AbstractController
'controller_name' => 'AccountController', 'controller_name' => 'AccountController',
]); ]);
} }
/***
page d'exemple
**/
#[Route('/account/history', name: 'app_account_history')] #[Route('/account/history', name: 'app_account_history')]
public function history(): Response public function history(): Response
{ {

View File

@ -3,6 +3,7 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
@ -21,8 +22,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 180, unique: true)] #[ORM\Column(length: 180, unique: true)]
private ?string $email = null; private ?string $email = null;
#[ORM\Column(length: 500, nullable: true)]
private ?string $description = null;
#[ORM\Column] #[ORM\Column]
private array $roles = []; private array $roles = [];
@ -36,6 +35,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(type: 'boolean')] #[ORM\Column(type: 'boolean')]
private $isVerified = false; private $isVerified = false;
#[ORM\Column(length: 500, nullable: true)]
private ?string $description = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $last_login = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -117,4 +122,28 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this; return $this;
} }
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->last_login;
}
public function setLastLogin(?\DateTimeInterface $last_login): static
{
$this->last_login = $last_login;
return $this;
}
} }

View File

@ -7,9 +7,9 @@
<div id="account_home"> <div id="account_home">
<h1> <h1>
Mon compte Tableau de bord
</h1> </h1>
<a href="{{ app_account }}">modifier mes informations</a> <a href="{{ path('app_account') }}">modifier mes informations (todo)</a>
<p> <p>
Coucou {{ app.user.email }}! Coucou {{ app.user.email }}!
</p> </p>

View File

@ -1,16 +1,21 @@
{% set currentRoute = app.request.attributes.get('_route') %}
<div id="nav_menu"> <div id="nav_menu">
<nav> <nav>
<div class="mb-3"> <div class="mb-3">
<a href="{{ path('app_index') }}">Accueil</a> <a href="{{ path('app_index') }}"
class="{% if currentRoute == 'app_index' %}active{% endif %}"
>{{ 'common.homepage'|trans }}</a>
{% if app.user %} {% if app.user %}
<a
You are logged in as class="account-link {% if currentRoute == 'app_account' %}active{% endif %}"
<a class="account-link" href="{{ path('app_account') }}">{{ app.user.userIdentifier }}</a> href="{{ path('app_account') }}">{{ app.user.userIdentifier }}</a>
, <a href="{{ path('app_logout') }}">Logout</a> , <a href="{{ path('app_logout') }}">{{ 'user.logout'|trans }}</a>
{% else %} {% else %}
<a href="{{ path('app_login') }}">{{ 'user.login'|trans }}</a> <a class="account-link {% if currentRoute == 'app_login' %}active{% endif %}"
<a href="{{ path('app_register') }}">Register</a> href="{{ path('app_login') }}">{{ 'user.login'|trans }}</a>
<a class="account-link {% if currentRoute == 'app_register' %}active{% endif %}"
href="{{ path('app_register') }}">{{ 'user.register'|trans }}</a>
{% endif %} {% endif %}
</div> </div>
{# <a href="{{path('admin')}}">Admin</a> #} {# <a href="{{path('admin')}}">Admin</a> #}

View File

@ -3,18 +3,10 @@
{% block title %}Hello IndexController!{% endblock %} {% block title %}Hello IndexController!{% endblock %}
{% block body %} {% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper"> <div class="example-wrapper">
<h1>Hello ! ✅</h1> <h1>{{ 'pages.app_index.title'|trans }}</h1>
<p>
This friendly message is coming from: {{ 'pages.app_index.subtitle'|trans }}
<ul> </p>
<li>Your controller at <code><a href="{{ '/home/poule/encrypted/stockage-syncable/www/development/html/sf-with-users/userlands/src/Controller/IndexController.php'|file_link(0) }}">src/Controller/IndexController.php</a></code></li>
<li>Your template at <code><a href="{{ '/home/poule/encrypted/stockage-syncable/www/development/html/sf-with-users/userlands/templates/index/index.html.twig'|file_link(0) }}">templates/index/index.html.twig</a></code></li>
</ul>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -38,7 +38,10 @@
If you want to control the URL the user is redirected to on success If you want to control the URL the user is redirected to on success
#} #}
<input type="hidden" name="_target_path" value="/account"> <input type="hidden" name="_target_path" value="/account">
<label>
<input type="checkbox" name="_remember_me" checked>
Keep me logged in
</label>
<button class="btn btn-lg btn-primary" type="submit"> <button class="btn btn-lg btn-primary" type="submit">
Sign in Sign in
</button> </button>

View File

@ -1 +1,11 @@
common:
homepage: Accueil
pages:
app_index:
title: Salutations noble barbare!
subtitle: Bienvenue dans cette application Symfony capable de gérer un espace utilisateur.
user:
# id is user.login
login: Login
logout: Se déconnecter
register: Créer un compte