mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
require actual password for change + insert link in menu
This commit is contained in:
@@ -5,12 +5,42 @@ 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;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var UserPasswordEncoderInterface
|
||||
*/
|
||||
protected $passwordEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $chillLogger;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $chillLogger,
|
||||
UserPasswordEncoderInterface $passwordEncoder,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->chillLogger = $chillLogger;
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
@@ -18,7 +48,6 @@ class PasswordController extends Controller
|
||||
*/
|
||||
public function UserPasswordAction(Request $request)
|
||||
{
|
||||
|
||||
// get authentified user
|
||||
$user = $this->getUser();
|
||||
|
||||
@@ -29,21 +58,27 @@ class PasswordController extends Controller
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
|
||||
$password = $form->getData()->getPassword();
|
||||
$password = $form->get('new_password')->getData();
|
||||
|
||||
// logging for prod
|
||||
$this->get('logger')->info('update password for an user',
|
||||
array('method' => __METHOD__, 'user' => $user->getUsername()));
|
||||
$this
|
||||
->chillLogger
|
||||
->notice(
|
||||
'update password for an user',
|
||||
array(
|
||||
'method' => $request->getMethod(),
|
||||
'user' => $user->getUsername()
|
||||
)
|
||||
);
|
||||
|
||||
$user->setPassword($this->get('security.password_encoder')
|
||||
->encodePassword($user, $password));
|
||||
$user->setPassword($this->passwordEncoder->encodePassword($user, $password));
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));
|
||||
$this->addFlash('success', $this->translator->trans('Password successfully updated!'));
|
||||
|
||||
return $this->redirectToRoute('change_my_password');
|
||||
|
||||
}
|
||||
|
||||
@@ -62,11 +97,12 @@ class PasswordController extends Controller
|
||||
*/
|
||||
private function passwordForm(User $user)
|
||||
{
|
||||
return $this->createForm(UserPasswordType::class, $user, array(
|
||||
'method' => 'PUT',
|
||||
|
||||
))
|
||||
->add('submit', SubmitType::class, array('label' => 'Change password'))
|
||||
return $this->createForm(
|
||||
UserPasswordType::class,
|
||||
[],
|
||||
[ 'user' => $this->getUser() ]
|
||||
)
|
||||
->add('submit', SubmitType::class, array('label' => 'Change password'))
|
||||
;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user