symfony - overriding template of password change fos user bundle -
hi im working on project using fosuserbundle manage users inside application, want - same thing - move/copy template of password change inside page contains profile of current user, works fine, displays me changepasswordformtype, when submit changes controller gives me error :
catchable fatal error: argument 1 passed user\userbundle\entity\acces::checkallfields() must instance of symfony\component\validator\executioncontext, instance of symfony\component\validator\context\executioncontext given
thats controller :
$request = $this->get('request'); $em = $this->getdoctrine()->getmanager(); $roles = $em->getrepository('adminadminbundle:role')->findall(); $usermanager = $this->get('fos_user.user_manager'); $user = new \user\userbundle\entity\acces(); $user = $this->container->get('security.context')->gettoken()->getuser(); /** @var $dispatcher \symfony\component\eventdispatcher\eventdispatcherinterface */ $dispatcher = $this->container->get('event_dispatcher'); $event = new getresponseuserevent($user, $request); $dispatcher->dispatch(fosuserevents::change_password_initialize, $event); if (null !== $event->getresponse()) { return $event->getresponse(); } /** @var $formfactory \fos\userbundle\form\factory\factoryinterface */ $formfactory = $this->container->get('fos_user.change_password.form.factory'); $form = $formfactory->createform(); $form->setdata($user); $currentuser = $user; $personnel = $em->getrepository('adminadminbundle:personnel')->findby(array('acces' => $user)); $user = $this->container->get('security.context')->gettoken()->getuser(); if (!is_object($user) || !$user instanceof userinterface) { throw new accessdeniedexception('cet utilisateur n\'a pas d\'acces à ce contenu.'); } if ($request->ismethod('post')) { /** @var $formfactory \fos\userbundle\form\factory\factoryinterface */ $formfactory = $this->get('fos_user.change_password.form.factory'); $form = $formfactory->createform(); $form->setdata($user); $form->handlerequest($request); if ($form->isvalid()) { /** @var $usermanager \fos\userbundle\model\usermanagerinterface */ $usermanager = $this->container->get('fos_user.user_manager'); $event = new formevent($form, $request); $dispatcher->dispatch(fosuserevents::change_password_success, $event); $usermanager->updateuser($user); if (null === $response = $event->getresponse()) { $url = $this->container->get('router')->generate('personnel_profile'); $response = new redirectresponse($url); } $dispatcher->dispatch(fosuserevents::change_password_completed, new filteruserresponseevent($user, $request, $response)); return $response; } }
the view code :
<form role="form" name="passchange" method="post" {{ form_enctype(password_form) }} action="{{ path('personnel_update_personnal') }}" id="form_sample_2"> <input type="hidden" name="passchange" value="0" /> <div class="form-group"> <label class="control-label">mot de passe actuel</label> {{ form_widget(password_form.current_password,{ 'attr': {'required': 'required', 'class':'form-control'} }) }} <span class="help-block"> {{ form_errors(password_form.current_password) }} </span> </div> <div class="form-group"> <label class="control-label">nouveau mot de passe</label> {{ form_widget(password_form.plainpassword.first,{ 'attr': {'required': 'required', 'class':'form-control'} }) }} <span class="help-block"> {{ form_errors(password_form.plainpassword.first) }} </span> </div> <div class="form-group"> <label class="control-label">confirmation mot de passe</label> {{ form_widget(password_form.plainpassword.second,{ 'attr': {'required': 'required', 'class':'form-control'} }) }} <span class="help-block"> {{ form_errors(password_form.plainpassword.second) }} </span> </div> <div class="margin-top-10"> <button type="submit" class="btn green-haze">valider le changement</button> <button type="reset" class="btn default reset">annuler le changement</button> </div> </form>
a simple note: entity user (of userbundle) in case named acces
the error given above generated on line : $form->handlerequest($request);
plz if has encountered error, info helpful lot.
edit : use entity :
namespace user\userbundle\entity; use doctrine\orm\mapping orm; use fos\userbundle\model\user baseuser; use symfony\component\validator\executioncontext; use symfony\component\validator\constraints assert; /** * @orm\entity * @orm\table(name="fos_user") * @assert\callback(methods={"checkallfields"}) * @orm\attributeoverrides({ * @orm\attributeoverride(name="username", column=@orm\column(nullable=true)), * @orm\attributeoverride(name="email", column=@orm\column(nullable=true)), * @orm\attributeoverride(name="password", column=@orm\column(nullable=true)), * }) */ class acces extends baseuser { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @orm\manytoone(targetentity="\admin\adminbundle\entity\role" ) * @orm\joincolumn(name="role_id", referencedcolumnname="id") * @assert\null(groups={"registration"}) */ private $role; public function __construct() { parent::__construct(); // own logic } /** * id * * @return integer */ public function getid() { return $this->id; } /** * set role * * @param \admin\adminbundle\entity\role $role * @return acces */ public function setrole(\admin\adminbundle\entity\role $role = null) { $this->role = $role; return $this; } /** * role * * @return \admin\adminbundle\entity\role */ public function getrole() { return $this->role; } public function checkallfields(executioncontext $context) { if (!(($this->username == null && $this->password == null && $this->email == null && $this->role == null ) || ($this->username != null && $this->password != null && $this->email != null && $this->role != null ) )) { $context->validate($this->getrole(), 'acces', array("registration")); } } public function __tostring() { return parent::__tostring(); } }
Comments
Post a Comment