【发布时间】:2014-03-07 22:17:23
【问题描述】:
我有一个门户网站,公司可以在其中为其员工创建子帐户,并且他们可以更改员工密码。问题是当我尝试更改它时,我必须写入用户的当前密码,但它不接受它的密码,只有我的 - 当前登录的用户,而不是我正在编辑的用户。
我的控制器:
public function changePasswordAction(Request $request, $company_id, $id)
{
$company = $this->getCompany($company_id);
$subaccount = $this->getDoctrine()
->getRepository('MyBundle:User')
->find($id);
if (!$subaccount or !$company->hasUser($subaccount))
{
throw new AccessDeniedException();
}
$form = $this->createForm('fos_user_change_password', $subaccount);
$form->add('save', 'submit');
$form->handleRequest($request);
if ($form->isValid())
{
$userManager = $this->container->get('fos_user.user_manager');
$userManager->updateUser($subaccount);
$em = $this->getDoctrine()->getManager();
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'subaccount.flash.password_changed');
return $this->redirect($this->generateUrl('subaccount_list', array('company_id' => $company->getId())));
}
return $this->render('MyBundle:Subaccount:edit.html.twig', array(
'form' => $form->createView(),
'company' => $company
));
}
是的,子帐户和门户用户是使用一个实体创建的。
【问题讨论】:
标签: php forms symfony fosuserbundle