public function loginAction(Request $request) { $session = $this->getRequest()->getSession(); $em = $this->getDoctrine()->getEntityManager(); $repository = $em->getRepository('ApplicationBundle:User'); if ($request->getMethod() == 'POST') { $session->clear(); $username = $request->get('username'); $password = sha1($request->get('password')); $remember = $request->get('remember'); $user = $repository->findOneBy(array('userName' => $username, 'password' => $password)); if ($user) { if ($remember == 'remember-me') { } $login = new Login(); $login->setUsername($username); $login->setPassword($password); $login->setEmpNo($user->getEmpNo()); $session->set('login', $login); return $this->render('user/welcome.html.twig', array('name' => $user->getEmpNo())); } else { return $this->render('user/login.html.twig', array('name' => 'Login Error')); } } else { if ($session->has('login')) { $login = $session->get('login'); $username = $login->getUsername(); $password = $login->getPassword(); $user = $repository->findOneBy(array('userName' => $username, 'password' => $password)); if ($user) { return $this->render('user/welcome.html.twig', array('name' => $user->getEmpNo())); } } } return $this->render('user/login.html.twig'); }
public function loginAction(Request $request) { $session = $this->getRequest()->getSession(); // $em = $this->getDoctrine()->getEntityManager(); //$repository = $em->getRepository('ApplicationBundle:User'); if ($request->getMethod() == 'POST') { $session->clear(); $username = $request->get('username'); $password = sha1($request->get('password')); $remember = $request->get('remember'); $user = $this->user_connection->getUserById($username, $password); $emp_no = $user['emp_no']; $roleId = $user['role_id']; $id = $user['id']; //$user = $repository->findOneBy(array('userName' => $username, 'password' => $password));$user->getEmpNo() if ($user) { if ($remember == 'remember-me') { } $login = new Login(); $login->setUsername($username); $login->setPassword($password); $login->setEmpNo($emp_no); $login->setRoleId($roleId); $login->setId($id); $session->set('login', $login); $previleges = $this->role_connection->get_preveliges_by_role_id($roleId); return $this->render('user/welcome.html.twig', array('name' => $emp_no, 'previleges' => $previleges)); } else { return $this->render('user/login.html.twig', array('name' => 'Login Error')); } } else { if ($session->has('login')) { $login = $session->get('login'); $username = $login->getUsername(); $password = $login->getPassword(); $user = $this->user_connection->getUserById($username, $password); $roleId = $user['role_id']; //$user = $repository->findOneBy(array('userName' => $username, 'password' => $password)); $previleges = $this->role_connection->get_preveliges_by_role_id($roleId); if ($user) { return $this->render('user/welcome.html.twig', array('name' => $login->getEmpNo(), 'previleges' => $previleges)); } } } return $this->render('user/login.html.twig'); }