symfony2 : user password set to empty after running this method

前端 未结 3 1616
闹比i
闹比i 2020-12-21 22:09

this methodi use it to add a new job but when i add a job the password of the that current user get its password set to empty cus the user object that i retrieve has no pass

3条回答
  •  遥遥无期
    2020-12-21 22:52

    It does seem strange, but you could always retrieve User object prior to binding it to a newly created job:

    $token = $this->get('security.context')->getToken();
    $user_repo = $this->getDoctrine()->getRepository('**NAMESPACE**:User');
    $user = $user_repo->find($token->getUser()->getId());
    
    $job->setAnnouncer($user);
    $em = $this->getDoctrine()->getEntityManager();
    $em->persist($job) ;
    $em->flush();
    

    Also, I'm not really sure but I read somewhere that token isn't supposed to carry password due to it's security nature.... maybe that is your problem...

提交回复
热议问题