Tutorial 3 : Login Application using Symfony2 part 2 symfony symfony, Hi In this tutorial about Login Application using Symfony2 part2 The controller getRequest()->getSession(); $em=$this->getDoctrine()->getManager(); $repository =$em->getRepository('DWMUserBundle:User'); if ($session->has('login')) { $login = $session->get('login'); $email = $login->getEmail(); $password = $login->getPassword(); $user = $repository->findOneBy(array('email' => $email, 'password' => $password)); return $this->render('DWMUserBundle:Default:home.html.twig',array('user' => $user)); } else return $this->render('DWMUserBundle:Default:index.html.twig'); } public function SigninAction(Request $request) { $session = $this->getRequest()->getSession(); $em=$this->getDoctrine()->getManager(); $repository =$em->getRepository('DWMUserBundle:User'); if($request->getMethod()=='POST') { $session->clear(); $email=$request->get('email'); $password=$request->get('password'); $user=$repository->findOneBy(array('email'=>$email,'password'=>$password)); if ($user) //if user has values { $login = new User(); $login->setEmail($email); $login->setPassword($password); $session->set('login', $login); return $this->render('DWMUserBundle:Default:home.html.twig', array('user' => $user)); } else//if login is incorrect return $this->render('DWMUserBundle:Default:signin.html.twig'); } else //if $request->getMethod()!='POST' { if ($session->has('login')) { $login = $session->get('login'); $email = $login->getEmail(); $password = $login->getPassword(); $user = $repository->findOneBy(array('email' => $email, 'password' => $password)); return $this->render('DWMUserBundle:Default:home.html.twig',array('user' => $user)); } return $this->render('DWMUserBundle:Default:signin.html.twig'); } } public function logoutAction(Request $request) { $session=$this->getRequest()->getSession(); $session->clear(); return $this->redirect('../web/'); } } the routing.yml dwm_user_homepage: path: / defaults: { _controller: DWMUserBundle:Default:index } dwm_user_signin: path: /signin defaults: { _controller: DWMUserBundle:Default:Signin } dwm_user_logout: path: /logout defaults: { _controller: DWMUserBundle:Default:logout } NextArticle plus récent PreviousArticle plus ancien Hssan Riahi Hssan Riahi is a Web Developer, designer and a programmer.He loves experimenting with technology and codes. symfony
Post A Comment:
0 comments: