Kaynağa Gözat

Ajout de gestion de son profil

François 6 yıl önce
ebeveyn
işleme
85f7a06976

+ 18 - 0
app/Resources/views/base.html.twig

@@ -30,6 +30,24 @@
 					</li>
 					{%  endif %}
 				</ul>
+				{%  if not is_granted('IS_AUTHENTICATED_REMEMBERED') %}
+					<ul class="navbar-nav">
+						<li class="nav-item"><a class="nav-link" href="{{ path('login') }}">Se connecter</a></li>
+					</ul>
+				{% else %}
+					<ul class="navbar-nav">
+						<li class="nav-item dropdown">
+							<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+								{{ app.user.username }}
+							</a>
+							<div class="dropdown-menu" aria-labelledby="navbarDropdown">
+								<a class="dropdown-item" href="{{ path('user_profil') }}">Profil</a>
+								<div class="dropdown-divider"></div>
+								<a class="dropdown-item" href="{{ path('logout') }}">Se déconnecter</a>
+							</div>
+						</li>
+					</ul>
+				{% endif %}
 				<form class="form-inline my-2 my-lg-0">
 					<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
 					<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>

+ 36 - 0
src/AppBundle/Controller/ProfilController.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace AppBundle\Controller;
+
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Routing\Annotation\Route;
+
+class ProfilController extends Controller
+{
+    /**
+     * @Route("/profil/", name="user_profil")
+     */
+    public function monProfilAction(Request $request)
+    {
+        $user = $this->getUser();
+        $form = $this->createForm('AppBundle\Form\UserEditProfilType', $user);
+        $form->handleRequest($request);
+        if ($form->isSubmitted() && $form->isValid())
+        {
+            $em = $this->getDoctrine()->getManager();
+            $user = $form->getData();
+            $em->flush();
+            $this->addFlash('success', "Votre profil a été modifié");
+        }
+
+
+        return $this->render('@App/profil/monprofil.html.twig', array (
+            'form'  =>  $form->createView()
+        ));
+    }
+
+
+
+}

+ 71 - 2
src/AppBundle/Entity/User.php

@@ -22,12 +22,81 @@ class User implements UserInterface
      */
     private $id;
 
+    /**
+ * @var string
+ *
+ * @ORM\Column(name="username", type="string", length=255, unique=true)
+ */
+    private $username;
+
     /**
      * @var string
      *
-     * @ORM\Column(name="username", type="string", length=255, unique=true)
+     * @ORM\Column(name="prenom", type="string", length=255)
      */
-    private $username;
+    private $prenom;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="nom", type="string", length=255)
+     */
+    private $nom;
+
+    /**
+     * @return string
+     */
+    public function getPrenom()
+    {
+        return $this->prenom;
+    }
+
+    /**
+     * @param string $prenom
+     */
+    public function setPrenom($prenom)
+    {
+        $this->prenom = $prenom;
+    }
+
+    /**
+     * @return string
+     */
+    public function getNom()
+    {
+        return $this->nom;
+    }
+
+    /**
+     * @param string $nom
+     */
+    public function setNom($nom)
+    {
+        $this->nom = $nom;
+    }
+
+    /**
+     * @return string
+     */
+    public function getMail()
+    {
+        return $this->mail;
+    }
+
+    /**
+     * @param string $mail
+     */
+    public function setMail($mail)
+    {
+        $this->mail = $mail;
+    }
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="mail", type="string", length=255)
+     */
+    private $mail;
 
     /**
      * @var string

+ 25 - 0
src/AppBundle/Form/UserEditProfilType.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace AppBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
+
+class UserEditProfilType extends AbstractType
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function buildForm(FormBuilderInterface $builder, array $options)
+    {
+        $builder
+            ->remove('password')
+            ->remove('roles');
+    }
+
+    public function getParent()
+    {
+        return UserType::class;
+    }
+}

+ 6 - 2
src/AppBundle/Form/UserType.php

@@ -3,6 +3,8 @@
 namespace AppBundle\Form;
 
 use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\Extension\Core\Type\EmailType;
 use Symfony\Component\Form\Extension\Core\Type\PasswordType;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\FormBuilderInterface;
@@ -17,8 +19,10 @@ class UserType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder
-            ->add('username')
-            ->add('password')
+            ->add('username', TextType::class)
+            ->add('password', PasswordType::class)
+            ->add('prenom', TextType::class)
+            ->add('mail', EmailType::class)
             ->add('roles', ChoiceType::class, array(
                 'choices'   => array (
                     'Administrateur'    =>  'ROLE_ADMIN',

+ 9 - 0
src/AppBundle/Resources/views/profil/monprofil.html.twig

@@ -0,0 +1,9 @@
+{% extends "base.html.twig" %}
+
+{% block title %}Mon profil{%  endblock %}
+{% block titre %}Modifier mon profil{%  endblock %}
+
+{% block body %}
+    {{ form(form) }}
+    <a href="{{ path('videotheque_liste') }}" class="btn btn-link" role="button">Retour à l'accueil</a>
+{% endblock %}