Commit f5c7a619 authored by martin's avatar martin
Browse files

profile modification

parent 09e908de
......@@ -45,7 +45,7 @@ class AdminController extends AbstractController
UserPasswordEncoderInterface $encoder, \Swift_Mailer $mailer){
$planner = new User();
$form = $this->createForm(PlannerType::class, $planner);
$form = $this->createForm(PlannerType::class, $planner, ['password' => false]);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
......
......@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\Course;
use App\Modele\CreateTrack;
use App\Entity\Track;
use App\Modele\CreateMissingCheckpoint;
use App\Entity\MissingCheckpoint;
class DataController extends AbstractController
{
......
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Form\PlannerType;
use App\Entity\User;
use App\Modele\CreateUser;
class ProfileController extends AbstractController
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @Route("/profile", name="profile")
*/
public function index()
{
$user = $this->security->getUser();
return $this->render('profile/index.html.twig', [
'user' => $user,
]);
}
/**
* @Route("/profile/modify", name="modify_info")
*/
public function modify(Request $request, TranslatorInterface $translator,
UserPasswordEncoderInterface $encoder){
$planner = $this->security->getUser();
$form = $this->createForm(PlannerType::class, $planner, ['password' => true]);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$user = $form->getData();
$creator = new CreateUser($user, $translator);
$valid = $creator->addUser($encoder, $this->getDoctrine()->getManager());
if($valid === true){
return $this->redirectToRoute('profile');
}else{
return $this->render('profile/modify.html.twig', [
'form' => $form->createView(),
'error' => $valid,
]);
}
}
return $this->render('profile/modify.html.twig', [
'form' => $form->createView(),
]);
}
}
......@@ -6,6 +6,7 @@ use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
......@@ -13,8 +14,12 @@ class PlannerType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username', TextType::class, ['label' => "name"]);
if($options["password"])
$builder->add('password', PasswordType::class, ['label' => 'new.password']);
$builder
->add('username', TextType::class, ['label' => "name"])
->add('email', TextType::class, ['label' => 'email'])
->add('phone', TextType::class, ['label' => 'phone', 'required' => false])
->add('submit', SubmitType::class)
......@@ -25,6 +30,7 @@ class PlannerType extends AbstractType
{
$resolver->setDefaults([
'data_class' => User::class,
'password' => bool::class,
]);
}
}
{% extends 'base.html.twig' %}
{% block title %}{%trans%}your.info{%endtrans%}{% endblock %}
{% block body %}
<div class="example-wrapper" style="padding-top: 100pt">
<h1>{{"hello"|trans({'%name%' : user.username})}}</h1>
<p>{{"your.email"|trans({'%email%' : user.email})}}</p>
{% if user.phone is defined %}
<p>{{"your.phone"|trans({'%phone%' : user.phone})}}</p>
{% else %}
<p>{%trans%}no.phone.given {%endtrans%}</p>
{%endif%}
</div>
{% endblock %}
{% extends 'base.html.twig' %}
{% block title %}{% trans %}add.user{% endtrans %}{% endblock %}
{% block body %}
<div class="container" style="padding-top: 100pt">
<h1>{% trans %}add.user{% endtrans %}</h1>
{% if error is defined %}
<p class="alert alert-danger">{{error}}</p>
{% endif %}
{{form(form)}}
</div>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment