Skip to content
Snippets Groups Projects
Commit 10dc1cee authored by Camille Simiand's avatar Camille Simiand
Browse files

Add edit profile form

parent ebaf284c
Branches
Tags
1 merge request!36tuleap-90-access-my-account-preferences
......@@ -122,11 +122,11 @@ button[type=submit]{
padding: 10px;
}
.row-title {
text-decoration: none;
text-transform: uppercase;
font-size: 18px;
}
//.row-title {
// text-decoration: none;
// text-transform: uppercase;
// font-size: 18px;
//}
.row-title:hover {
color: rgba(255,255,255,.75);
......
......@@ -3,10 +3,13 @@
namespace App\Controller;
use App\Entity\User;
use App\Form\EditUserProfileFormType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserController extends AbstractController
{
......@@ -26,26 +29,41 @@ class UserController extends AbstractController
]);
}
// /**
// * @Route("/edit_profile", name="edit_profile")
// */
// public function editProfile(Request $request): Response
// {
// $form = $this->createForm(EditUserProfileFormType::class);
// $form->handleRequest($request);
// $current_user = $this->getUser();
//
// if (! $current_user instanceof User) {
// return $this->redirectToRoute('app_logout');
// }
//
// if ($form->isSubmitted() && $form->isValid()) {
// }
//
// return $this->render('user/edit_profile.html.twig', [
// 'editUserProfileForm' => $form->createView()
// ]);
// }
/**
* @Route("/edit_profile", name="edit_profile")
*/
public function editProfile(
Request $request,
EntityManagerInterface $entity_manager,
TranslatorInterface $translator
): Response {
$current_user = $this->getUser();
if (! $current_user instanceof User) {
return $this->redirectToRoute('app_logout');
}
$form = $this->createForm(EditUserProfileFormType::class, $current_user);
$form->setData($current_user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entity_manager->persist($current_user);
$entity_manager->flush();
$this->addFlash(
'profile_updated_success',
$translator->trans('user.profile.updated_success')
);
return $this->redirectToRoute('show_profile');
}
return $this->render('user/edit_profile.html.twig', [
'editUserProfileForm' => $form->createView()
]);
}
// /**
// * @Route("/edit_password", name="edit_password")
......
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
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\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\NotBlank;
class EditUserProfileFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add(
'firstName',
TextType::class,
[
'constraints' => [new NotBlank(['message' => 'firstName.not_blank'])],
'label' => 'user.firstname',
'empty_data' => ''
]
)
->add(
'lastName',
TextType::class,
[
'constraints' => [new NotBlank(['message' => 'lastName.not_blank'])],
'label' => 'user.lastname',
'empty_data' => ''
]
)
->add(
'email',
EmailType::class,
[
'constraints' => [new NotBlank(['message' => 'email.not_blank'])],
'label' => 'general.email',
'empty_data' => ''
]
)
->add(
'current_password',
PasswordType::class,
[
'mapped' => false,
'required' => true,
'constraints' => [
new NotBlank(['message' => 'password.not_blank']),
new UserPassword(['message' => "password.invalid"])
],
'label' => 'user.password.current'
]
)
->add(
'update',
SubmitType::class,
['label' => 'user.profile.update']
)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}
{% extends 'layout.html.twig' %}
{% block title %}
{{ 'user.profile.title'|trans }}
{% endblock %}
{% block body %}
<div class="row gx-0">
<div class="row-title-box">
<h3 class="row-title">
{{ 'user.edit_profile'|trans }}
</h3>
</div>
</div>
<div>
{{ form_start(editUserProfileForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }}
{{ form_row(editUserProfileForm.firstName, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }}
{{ form_row(editUserProfileForm.lastName, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }}
{{ form_row(editUserProfileForm.email, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }}
{{ form_row(editUserProfileForm.current_password, {'row_attr': {'class' : ' m-auto mb-4 col-6'}}) }}
{{ form_row(editUserProfileForm.update, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-2'}}) }}
{{ form_end(editUserProfileForm) }}
</div>
{% endblock %}
\ No newline at end of file
......@@ -13,6 +13,12 @@
</div>
</div>
{% for flashSuccess in app.flashes('profile_updated_success') %}
<div class="text-center alert alert-success col-5 mx-auto my-5" role="alert">
{{ flashSuccess }}
</div>
{% endfor %}
<div class="d-flex flex-column flex-md-row justify-content-center align-items-center">
<div class="profile-block d-flex flex-row ps-3 ps-md-5 pe-3 pe-md-5 pt-4 pb-3 fw-normal me-0 me-md-5">
<div class="pe-3 pe-md-4 text-nowrap">
......
......@@ -64,5 +64,9 @@ user:
profile:
title: My profile
edit: Edit profile
update: Update
updated_success: The profile has been updated
password:
edit: Edit password
current: Current password
edit_profile: Edit my profile
\ No newline at end of file
......@@ -63,5 +63,9 @@ user:
profile:
title: Mon profil
edit: Modifier mon profil
update: Mettre à jour
updated_success: Votre profil a bien été mis à jour
password:
edit: Modifier mon mot de passe
current: Mot de passe actuel
edit_profile: Edit my profile
\ No newline at end of file
......@@ -12,6 +12,7 @@ password:
not_blank: Please enter your password
min_characters: Your password should be at least {{ limit }} characters
match: The password fields must match.
invalid: Invalid password
agreeTerms: You must agree with our terms
......
......@@ -12,5 +12,6 @@ password:
not_blank: Veuillez renseigner le mot de passe
min_characters: Le mot de passe doit contenir au minimum {{ limit }} caractères
match: Les champs mots de passe doivent être identiques
invalid: Invalid password
agreeTerms: Veuillez accepter les termes et conditions
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment