add a page for modifying password for user

This commit is contained in:
nobohan 2018-04-10 16:19:35 +02:00
parent 0287da70d7
commit f7502b4e9e
3 changed files with 116 additions and 4 deletions

View File

@ -0,0 +1,74 @@
<?php
namespace Chill\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\MainBundle\Form\UserPasswordType;
use Chill\MainBundle\Entity\User;
class PasswordController extends Controller
{
/**
*
* @param Request $request
* @return Response
*/
public function UserPasswordAction(Request $request)
{
// get authentified user
$user = $this->getUser();
// create a form for password_encoder
$form = $this->passwordForm($user);
// process the form
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$password = $form->getData()->getPassword();
// logging for prod
$this->get('logger')->info('update password for an user',
array('method' => __METHOD__, 'user' => $user->getUsername()));
$user->setPassword($this->get('security.password_encoder')
->encodePassword($user, $password));
$em = $this->getDoctrine()->getManager();
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));
}
// render into a template
return $this->render('ChillMainBundle:Password:password.html.twig', array(
'form' => $form->createView()
));
}
/**
*
*
* @param User $user
* @return \Symfony\Component\Form\Form
*/
private function passwordForm(User $user)
{
return $this->createForm(UserPasswordType::class, $user, array(
'method' => 'PUT',
))
->add('submit', SubmitType::class, array('label' => 'Change password'))
;
}
}

View File

@ -13,7 +13,7 @@ chill_main_admin_scope:
chill_main_admin:
resource: "@ChillMainBundle/Resources/config/routing/center.yml"
prefix: "{_locale}/admin/center"
chill_main_exports:
resource: "@ChillMainBundle/Resources/config/routing/exports.yml"
prefix: "{_locale}/exports"
@ -62,11 +62,11 @@ chill_main_admin_permissions:
chill_main_search:
path: /{_locale}/search
defaults: { _controller: ChillMainBundle:Search:search }
chill_main_advanced_search:
path: /{_locale}/search/advanced/{name}
defaults: { _controller: ChillMainBundle:Search:advancedSearch }
chill_main_advanced_search_list:
path: /{_locale}/search/advanced
defaults: { _controller: ChillMainBundle:Search:advancedSearchList }
@ -85,4 +85,8 @@ logout:
user:
order: 10
label: Logout
icon: power-off
icon: power-off
password:
path: /password
defaults: { _controller: ChillMainBundle:Password:userPassword }

View File

@ -0,0 +1,34 @@
{#
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
<info@champs-libres.coop> / <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "ChillMainBundle::layout.html.twig" %}
{% block title %}{{"Change my password"|trans}}{% endblock %}
{% block content %}
<h1>{{ 'Choose a new password'|trans }}</h1>
{{ form_start(form) }}
{{ form_row(form.password) }}
{{ form_widget(form.submit, { 'attr': { 'class': 'sc-button orange' } } ) }}
{{ form_end(form) }}
{% endblock %}