public function indexAction(Request $request) { $session = $this->getRequest()->getSession(); $em = $this->getDoctrine()->getEntityManager(); $repository = $em->getRepository('LoginLoginBundle:Users'); 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 == 'rememberme') { $login = new Login(); $login->setUsername($username); $login->setPassword($password); $session->set('login', $login); } return $this->render('LoginLoginBundle:Default:welcome.html.twig', array('name' => $user->getFirstName())); } else { return $this->render('LoginLoginBundle:Default: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('LoginLoginBundle:Default:welcome.html.twig', array('name' => $user->getFirstName())); } } return $this->render('LoginLoginBundle:Default:login.html.twig'); } }
public function indexAction(Request $request) { $session = new Session(); $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('LoginLoginBundle:Users'); if ($request->getMethod() == "POST") { $session->clear(); $email = $request->get('email'); $password = $request->get('password'); $remember = $request->get('remember'); $user = $repository->findOneBy(array('email' => $email, 'password' => $password)); if ($user) { if ($remember == 'remember-me') { $login = new Login(); $login->setEmail($email); $login->setPassword($password); $session->set('login', $login); } return $this->redirectToRoute('admin_admin_homepage'); } return $this->render('LoginLoginBundle:Pages:login.html.twig'); } else { if ($session->has('login')) { $login = $session->get('login'); $email = $login->getEmail(); $password = $login->getPassword(); $user = $repository->findOneBy(array('email' => $email, 'password' => $password)); if ($user) { //return $this->render('LoginLoginBundle:Pages:login.html.twig', array('name' => $user->getName())); return $this->redirectToRoute('admin_admin_homepage'); } } return $this->render('LoginLoginBundle:Pages:login.html.twig'); } }
public function indexAction(Request $request) { if ($request->getMethod() == 'POST') { $username = $request->get('username'); $password = sha1($request->get('password')); $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository("LoginLoginBundle:Users"); $user = $repository->findOneBy(array('username' => $username, 'password' => $password)); if ($user) { if ($user->getStatus() == 'Active') { $fullname = $user->getFirstname() . " " . $user->getLastname(); $session = $this->getRequest()->getSession(); $session->clear(); $login = new Login(); $login->setUsername($user->getUsername()); $login->setPassword($password); $login->setRole($user->getRole()); $login->setFullname($fullname); $session->set('token', $login); return $this->redirectToRoute('web_dashboard'); // return $this->render('webBundle:Default:dashboard.html.twig', array('name' => $user->getUsername(), 'role' => $user->getRole(), 'fullname' => $fullname, 'manageview' => $user->getUserView())); } else { return $this->render('LoginLoginBundle:Default:signinV2.html.twig', array('errormsg' => 'Oh snap! You are not an active user')); } } else { return $this->render('LoginLoginBundle:Default:signinV2.html.twig', array('errormsg' => 'Oh snap! Login Failed Try Again')); } } else { return $this->render('LoginLoginBundle:Default:signinV2.html.twig'); } }