本文整理匯總了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);
}