本文整理汇总了PHP中Claroline\CoreBundle\Entity\User::getPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getPassword方法的具体用法?PHP User::getPassword怎么用?PHP User::getPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Entity\User
的用法示例。
在下文中一共展示了User::getPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editPasswordAction
/**
* @EXT\Route(
* "/password/edit/{user}",
* name="claro_user_password_edit"
* )
* @EXT\ParamConverter("loggedUser", options={"authenticatedUser" = true})
* @EXT\Template()
*/
public function editPasswordAction(User $user, User $loggedUser)
{
$isAdmin = $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN');
$isGrantedUserAdmin = $this->get('security.authorization_checker')->isGranted('OPEN', $this->toolManager->getAdminToolByName('user_management'));
$selfEdit = $user->getId() === $loggedUser->getId() ? true : false;
if (!$selfEdit && !$isAdmin && !$isGrantedUserAdmin) {
throw new AccessDeniedException();
}
$form = $this->createForm(new ResetPasswordType($selfEdit));
$oldPassword = $user->getPassword();
$form->handleRequest($this->request);
if ($form->isValid()) {
/** @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $sessionFlashBag */
$sessionFlashBag = $this->get('session')->getFlashBag();
/** @var \Symfony\Component\Translation\TranslatorInterface $translator */
$translator = $this->get('translator');
$continue = !$selfEdit;
if ($selfEdit) {
$user->setPlainPassword($form['password']->getData());
}
if ($selfEdit && $this->encodePassword($user) === $oldPassword) {
$continue = true;
}
if ($continue) {
$user->setPlainPassword($form['plainPassword']->getData());
$user->setPassword($this->encodePassword($user));
$entityManager = $this->get('doctrine.orm.entity_manager');
$entityManager->persist($user);
$entityManager->flush();
$sessionFlashBag->add('success', $translator->trans('edit_password_success', array(), 'platform'));
} else {
$sessionFlashBag->add('error', $translator->trans('edit_password_error_current', array(), 'platform'));
}
if ($selfEdit) {
return $this->redirect($this->generateUrl('claro_profile_view'));
} else {
return $this->redirect($this->generateUrl('claro_admin_users_index'));
}
}
return array('form' => $form->createView(), 'user' => $user);
}