public function user_newAction(Request $request) { $user = new User(); $addr = new Address(); $karma = new Karma(); $user->setCreateTime(new \Datetime()); $addr->setLastUpdate(new \Datetime()); $user->setAddress($addr); $form = $this->get('form.factory')->create(new UserType(), $user); if ($form->handleRequest($request)->isValid()) { // $user = $form->getData(); $em = $this->getDoctrine()->getManager(); $em->persist($user->getAddress()); $em->flush(); $user->setId_address($user->getAddress()->getId()); $user->setActive(1); $toks = explode("@", $user->getEmail()); $user->setUsername($toks[0]); $user->setRoles(array('ROLE_USER')); $em->persist($user); $em->flush(); $karma->setidUser($user->getId()); $karma->setValue(0); $em->persist($karma); $em->flush(); // Initialisation des listes $this->initLists($em, $user); $this->get('session')->getFlashBag()->add('success', 'Inscription effectuée.'); return $this->redirect($this->generateUrl('ur_user_login')); } return $this->render('URUserBundle:Default:inscription.html.twig', array('form' => $form->createView())); }
public function logUser(\upReal\UserBundle\Entity\User $user, \upReal\CoreBundle\Entity\UserOauth $userOauth) { // Here, "main" is the name of the firewall in your security.yml $token = new UsernamePasswordToken($user, null, 'oauth', $user->getRoles()); $this->get('security.context')->setToken($token); $this->get('session')->set('oauthDatas', $userOauth); // Fire the login event $this->get('event_dispatcher')->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($token)); }