コード例 #1
0
 public function authenticateAction()
 {
     $oLoginForm = new LoginForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $oLoginForm->setData($request->getPost());
         $oLoginFilter = new LoginFilter();
         $oLoginForm->setInputFilter($oLoginFilter->getInputFilter());
         if ($oLoginForm->isValid()) {
             $this->getAuthService()->getAdapter()->setIdentity($request->getPost('login'))->setCredential(md5($request->getPost('password')));
             $result = $this->getAuthService()->authenticate();
             foreach ($result->getMessages() as $message) {
                 //save message temporary into flashmessenger
                 $this->flashmessenger()->addMessage($message);
             }
             if ($result->isValid()) {
                 $aUser = $this->getAuthService()->getAdapter()->getResultRowObject();
                 $this->getAuthService()->getStorage()->write($aUser);
                 return $this->redirect()->toRoute('success');
             }
         } else {
             $this->flashmessenger()->addMessage($oLoginForm->getMessages());
         }
     }
     return $this->redirect()->toRoute('auth');
 }
コード例 #2
0
 public function loginAction()
 {
     $request = $this->getRequest();
     $view = new ViewModel();
     $loginForm = new LoginForm('loginForm');
     $loginForm->setInputFilter(new LoginFilter());
     if ($request->isPost()) {
         $data = $request->getPost();
         $loginForm->setData($data);
         if ($loginForm->isValid()) {
             $data = $loginForm->getData();
             $userPassword = new UserPassword();
             $encyptPass = $userPassword->create($data['password']);
             $this->getAuthService()->getAdapter()->setIdentity($data['email'])->setCredential($encyptPass);
             $result = $this->getAuthService()->authenticate();
             if ($result->isValid()) {
                 $session = new Container('User');
                 $session->offsetSet('email', $data['email']);
                 $this->flashMessenger()->addMessage(array('success' => 'Login Success.'));
                 // Redirect to page after successful login
             } else {
                 $this->flashMessenger()->addMessage(array('error' => 'invalid credentials.'));
                 // Redirect to page after login failure
             }
             return $this->redirect()->tourl('/article_to_read/public/device');
             // Logic for login authentication
         } else {
             $errors = $loginForm->getMessages();
             //prx($errors);
         }
     }
     $view->setVariable('loginForm', $loginForm);
     return $view;
 }
コード例 #3
0
 public function authenticateAction()
 {
     $form = new LoginForm();
     $form->setInputFilter(new LoginFilter());
     $redirect = '/auth/login';
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getAuthService()->getAdapter()->setIdentity($request->getPost('email'))->setCredential($request->getPost('password'));
             $result = $this->getAuthService()->authenticate();
             $user = $this->getAuthService()->getAdapter()->getResultRowObject();
             // TODO refactor this
             foreach ($result->getMessages() as $message) {
                 if ($message == 'A record with the supplied identity could not be found.' || $message == 'Supplied credential is invalid.') {
                     $this->flashmessenger()->addMessage('Логин или пароль введен неправильно.');
                 }
             }
             if ($result->isValid()) {
                 $redirect = '/admin/index';
                 $userDataArray = array('id' => $user->id, 'email' => $user->email);
                 $this->getAuthService()->getStorage()->write($userDataArray);
             }
         } else {
             $model = new ViewModel(array('error' => true, 'form' => $form));
             $model->setTemplate('auth/auth/login');
             return $model;
         }
     }
     return $this->redirect()->toUrl($redirect);
 }
コード例 #4
0
ファイル: LoginController.php プロジェクト: omusico/cursoZf2
 public function loginAction()
 {
     $form = new LoginForm();
     $form->get('submit')->setValue('Login');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('form' => $form);
 }
コード例 #5
0
ファイル: AuthController.php プロジェクト: jalvarez14/hva
 public function loginAction()
 {
     //Verficamos si existe ya una session activa
     if (!SessionManager::sessionExist()) {
         $this->layout('layout/layout_auth');
         //Almacenamos la ruta redirect
         //$reditect_url = $this->params()->fromRoute('redirect_url') && $this->params()->fromRoute('redirect_url')!='/login   ' ? $this->params()->fromRoute('redirect_url') : '/';
         $message = null;
         //Instanciamos nuestro loginForm
         $loginForm = new LoginForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             //Instanciamos nuestro filtro
             $loginFilter = new LoginFilter();
             $loginForm->setInputFilter($loginFilter->getInputFilter());
             $loginForm->setData($request->getPost());
             if ($loginForm->isValid()) {
                 $empleadoQuery = new EmpleadoQuery();
                 //Si los datos del formulario son correctos ahora hacemos la busqueda a la db
                 $credentialIsValid = $empleadoQuery->filterByEmpleadoNombreusuario($loginForm->get('empleado_nombreusuario')->getValue())->filterByEmpleadoPassword(md5($loginForm->get('empleado_password')->getValue()))->exists();
                 if ($credentialIsValid) {
                     //Creamos la sesion
                     //Obtenemos el objeto empleado
                     $empleado = $empleadoQuery->findOneByEmpleadoNombreusuario($loginForm->get('empleado_nombreusuario')->getValue());
                     //El rol
                     $empleado_rol = $empleado->getRol()->getRolNombre();
                     //El Acl
                     $empleado_aclCollection = \RolmoduloQuery::create()->filterByIdrol($empleado->getIdRol())->find();
                     $empleado_acl = array();
                     foreach ($empleado_aclCollection as $modulo) {
                         $moduloNombre = \ModuloQuery::create()->findOneByIdmodulo($modulo->getIdModulo())->getModuloNombre();
                         array_push($empleado_acl, $moduloNombre);
                     }
                     $empleadoArray = $empleado->toArray(\BasePeer::TYPE_FIELDNAME);
                     //Removemos idrol y password ya que son datos que no necesitamos en la session
                     unset($empleadoArray['idrol']);
                     unset($empleadoArray['empleado_password']);
                     $empleado_session = array('empleado_info' => $empleadoArray, 'empleado_rol' => $empleado_rol, 'empleado_acl' => $empleado_acl);
                     SessionManager::init($empleado_session);
                     return $this->redirect()->toUrl('/');
                 } else {
                     $message = "Nombre de usuario y/o contraseña incorrecta";
                 }
             }
         }
         return new ViewModel(array('form' => $loginForm, 'message' => $message));
     } else {
         return $this->redirect()->toUrl('/');
     }
 }
コード例 #6
0
ファイル: AuthController.php プロジェクト: lslim/bareos-webui
 public function loginAction()
 {
     if (isset($_SESSION['bareos']['authenticated']) && $_SESSION['bareos']['authenticated']) {
         return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
     }
     $this->layout('layout/login');
     $config = $this->getServiceLocator()->get('Config');
     $form = new LoginForm($config['directors']);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $auth = new Auth();
         $form->setInputFilter($auth->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $director = $form->getInputFilter()->getValue('director');
             $username = $form->getInputFilter()->getValue('consolename');
             $password = $form->getInputFilter()->getValue('password');
             $config = $this->getServiceLocator()->get('Config');
             $this->director = $this->getServiceLocator()->get('director');
             $this->director->set_config($config['directors'][$director]);
             $this->director->set_user_credentials($username, $password);
             if ($this->director->auth($username, $password)) {
                 $_SESSION['bareos']['director'] = $director;
                 $_SESSION['bareos']['username'] = $username;
                 $_SESSION['bareos']['password'] = $password;
                 $_SESSION['bareos']['authenticated'] = true;
                 $_SESSION['bareos']['idletime'] = time();
                 return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
             } else {
                 session_destroy();
                 $err_msg = "Sorry, can not authenticate. Wrong username and/or password.";
                 return new ViewModel(array('form' => $form, 'err_msg' => $err_msg));
             }
         } else {
             // given credentials in login form could not be validated in this case
             $err_msg = "Please provide a director, username and password.";
             session_destroy();
             return new ViewModel(array('form' => $form, 'err_msg' => $err_msg));
         }
     }
     return new ViewModel(array('form' => $form));
 }
コード例 #7
0
ファイル: SessionController.php プロジェクト: lpj0017/easypay
 public function indexAction()
 {
     $headTitle = $this->getServiceLocator()->get('viewHelperManager')->get('headTitle');
     $translator = $this->getServiceLocator()->get('translator');
     $headTitle->append($translator->translate('System Login'));
     $form = new LoginForm();
     $vars = array();
     $auth = new AuthenticationService();
     if (!$auth->hasIdentity()) {
         $vars['form'] = $form;
         $request = $this->getRequest();
         if ($request->isPost()) {
             $post_data = $request->getPost();
             $form->setData($post_data);
             // Validate the form
             if ($form->isValid()) {
                 // Authentication ...
                 $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
                 // Configure the instance with constructor parameters...
                 $authAdapter = new AuthAdapter($dbAdapter, 'account', 'username', 'password', 'MD5(?)');
                 // Set the input credential values (e.g., from a login form)
                 $data = $form->getData();
                 $authAdapter->setIdentity($data['username'])->setCredential($data['password']);
                 $auth = new AuthenticationService();
                 $result = $auth->authenticate($authAdapter);
                 $vars['result'] = $result;
                 if (!$result->isValid()) {
                     // Authentication failed;
                 } else {
                     // Authentication succeeded; the identity ($username) is stored
                     // in the session
                     // $result->getIdentity() === $auth->getIdentity()
                     // $result->getIdentity() === $username
                     return $this->redirect()->toRoute('auth');
                 }
             }
         }
     }
     $view_page = new ViewModel($vars);
     return $view_page;
 }
コード例 #8
0
 public function loginAction()
 {
     $form = new LoginForm();
     $form->get('submit')->setValue('Login');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new LoginFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             // $data = $this->getRequest()->getPost();
             // If you used another name for the authentication service, change it here
             // it simply returns the Doctrine Auth. This is all it does. lets first create the connection to the DB and the Entity
             $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
             // Do the same you did for the ordinar Zend AuthService
             $adapter = $authService->getAdapter();
             $adapter->setIdentityValue($data['username']);
             $adapter->setCredentialValue($data['password']);
             $authResult = $authService->authenticate();
             if ($authResult->isValid()) {
                 $identity = $authResult->getIdentity();
                 $authService->getStorage()->write($identity);
                 $time = 1209600;
                 // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                 if ($data['rememberme']) {
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                 }
                 return $this->redirect()->toRoute('cms/default', array('controller' => 'user', 'action' => 'index'));
             }
             foreach ($authResult->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
         }
     }
     return new ViewModel(array('error' => 'Your authentication credentials are not valid', 'form' => $form, 'messages' => $messages));
 }