Exemplo n.º 1
0
 public function loginAction()
 {
     $form = new LoginForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         $inputFilter = new LoginFilter();
         $form->setInputFilter($inputFilter);
         $form->setData($post);
         if (!$form->isValid()) {
             $viewModel = new ViewModel(array('error' => true, 'form' => $form));
             $viewModel->setTemplate('home/login/login');
             return $viewModel;
         }
         $authService = $this->_get_auth_service();
         $adapter = $authService->getAdapter();
         $adapter->setIdentityValue($post['member_name']);
         $adapter->setCredentialValue(md5($post['member_pwd']));
         $authResult = $authService->authenticate();
         if ($authResult->isValid()) {
             // 写入session
             $identity = $authResult->getIdentity();
             $authService->getStorage()->write($identity);
             $time = 1209600;
             // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
             if ($post['rememberme']) {
                 $sessionManager = new \Zend\Session\SessionManager();
                 $sessionManager->rememberMe($time);
             }
             return $this->redirect()->toRoute('home');
         }
         //return $this->redirect()->toRoute('register_confirm');
     }
     return array('form' => $form);
 }
 public function signUp($email, $password, $fullName, $oAuth2Client = null)
 {
     $user = $this->createUser($email, $password, $fullName);
     $adapter = $this->authenticationService->getAdapter();
     $adapter->setIdentityValue($user->getEmail());
     $adapter->setCredentialValue($password);
     $authenticationResult = $this->authenticationService->authenticate();
     if ($authenticationResult->isValid()) {
         $identity = $authenticationResult->getIdentity();
         $this->authenticationService->getStorage()->write($identity);
         // if ($this->params()->fromPost('rememberMe')) {
         $time = 1209600;
         // 14 days (1209600/3600 = 336 hours => 336/24 = 14 days)
         $sessionManager = new \Zend\Session\SessionManager();
         $sessionManager->rememberMe($time);
         // }
         return true;
         // redirect using cookie
         // if(isset($cookie->requestedUri)) {
         //     $requestedUri = $cookie->requestedUri;
         //     $redirectUri = $this->getRequest()->getUri()->getScheme() . '://' . $this->getRequest()->getUri()->getHost() . $requestedUri;
         //     return $this->redirect()->toUrl($redirectUri);
         // }
         // $this->getLogger()->log(\Zend\Log\Logger::INFO, 'Signed up', ['user' => $this->identity()]);
         // $this->flashMessenger()->addInfoMessage('We just sent you an email asking you to confirm your registration. Please search for fryday@fryady.net in your inbox and click on the "Confirm my registration" button');
         // $redirectRoute = $this->options->getSignUpRedirectRoute();
         // return $this->redirect()->toRoute($redirectRoute);
     }
     return false;
 }
Exemplo n.º 3
0
 public function loginAction()
 {
     $form = new LoginForm();
     $form->get('submit')->setValue('Login');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new LoginInputFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
             $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;
                 if ($data['rememberme']) {
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                 }
             }
             foreach ($authResult->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
             return $this->redirect()->toRoute('home');
         }
     }
     return new ViewModel(array('error' => 'Your authentication credentials are not valid', 'form' => $form, 'messages' => $this->flashMessenger()->getMessages()));
 }
Exemplo n.º 4
0
 public function indexAction()
 {
     $viewModel = new ViewModel();
     $request = $this->getRequest();
     if (!$request->isPost()) {
         $this->layout('layout/login');
         return $viewModel;
     }
     $user = $this->identity();
     $messages = null;
     $auth = new AuthenticationService();
     if ($auth->hasIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $sm = $this->getServiceLocator();
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $authAdapter = new AuthAdapter($dbAdapter, 'users', 'username', 'password', 'MD5(?) AND block = 1');
         $authAdapter->setIdentity($request->getPost('username'))->setCredential($request->getPost('password'));
         if (trim($request->getPost('username')) == "" || trim($request->getPost('password')) == "") {
             return $this->redirect()->toRoute('auth');
         }
         // or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module.
         // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
         // $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called.
         $result = $auth->authenticate($authAdapter);
         switch ($result->getCode()) {
             case Result::FAILURE_IDENTITY_NOT_FOUND:
                 // do stuff for nonexistent identity
                 break;
             case Result::FAILURE_CREDENTIAL_INVALID:
                 // do stuff for invalid credential
                 break;
             case Result::SUCCESS:
                 $storage = $auth->getStorage();
                 $storage->write($authAdapter->getResultRowObject(null, 'password'));
                 $time = 28800;
                 // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                 //						if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
                 if ($request->getPost('username')) {
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                 }
                 return $this->redirect()->toRoute('home');
                 break;
             default:
                 // do stuff for other failure
                 break;
         }
         foreach ($result->getMessages() as $message) {
             $messages .= "{$message}\n";
         }
     }
     $this->layout('layout/login');
     return $viewModel;
 }
Exemplo n.º 5
0
 public function loginAction()
 {
     $form = new LoginForm();
     $form->get('submit')->setValue('Login');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         //- $authFormFilters = new User(); // we use the Entity for the filters
         // TODO fix the filters
         //- $form->setInputFilter($authFormFilters->getInputFilter());
         // Filters have been fixed
         $form->setInputFilter(new LoginFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         // echo "<h1>I am here1</h1>";
         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']);
             //$data['usr_name']
             $adapter->setCredentialValue($data['password']);
             // $data['usr_password']
             $authResult = $authService->authenticate();
             // echo "<h1>I am here</h1>";
             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']) $authService->getStorage()->session->getManager()->rememberMe($time); // no way to get the session
                 if ($data['rememberme']) {
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                 }
                 //- return $this->redirect()->toRoute('home');
             }
             foreach ($authResult->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
             /*
                     $identity = $authenticationResult->getIdentity();
                     $authService->getStorage()->write($identity);
             
                     $authenticationService = $this->serviceLocator()->get('Zend\Authentication\AuthenticationService');
                     $loggedUser = $authenticationService->getIdentity();
             */
         }
     }
     return new ViewModel(array('error' => 'Your authentication credentials are not valid', 'form' => $form, 'messages' => $messages));
 }
Exemplo n.º 6
0
 public function loginAction()
 {
     $user = $this->identity();
     $form = new AuthForm();
     $form->get('submit')->setValue('Login');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $authFormFilters = new Auth();
         $form->setInputFilter($authFormFilters->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $sm = $this->getServiceLocator();
             $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
             $config = $this->getServiceLocator()->get('Config');
             $staticSalt = $config['static_salt'];
             $authAdapter = new AuthAdapter($dbAdapter, 'users', 'usr_name', 'usr_password', "MD5(CONCAT('{$staticSalt}', ?, usr_password_salt)) AND usr_active = 1");
             $authAdapter->setIdentity($data['usr_name'])->setCredential($data['usr_password']);
             $auth = new AuthenticationService();
             // or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module.
             // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
             // $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called.
             $result = $auth->authenticate($authAdapter);
             switch ($result->getCode()) {
                 case Result::FAILURE_IDENTITY_NOT_FOUND:
                     // do stuff for nonexistent identity
                     break;
                 case Result::FAILURE_CREDENTIAL_INVALID:
                     // do stuff for invalid credential
                     break;
                 case Result::SUCCESS:
                     $storage = $auth->getStorage();
                     $storage->write($authAdapter->getResultRowObject(null, 'usr_password'));
                     $time = 1209600;
                     // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                     //						if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
                     if ($data['rememberme']) {
                         $sessionManager = new \Zend\Session\SessionManager();
                         $sessionManager->rememberMe($time);
                     }
                     break;
                 default:
                     // do stuff for other failure
                     break;
             }
             foreach ($result->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
         }
     }
     return new ViewModel(array('form' => $form, 'messages' => $messages));
 }
Exemplo n.º 7
0
 public function loginAction()
 {
     $user = $this->identity();
     $form = new AuthForm();
     $form->get('submit')->setValue('Войти');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $authFormFilters = new Auth();
         $form->setInputFilter($authFormFilters->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $sm = $this->getServiceLocator();
             $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
             $config = $this->getServiceLocator()->get('Config');
             $staticSalt = $config['static_salt'];
             $authAdapter = new AuthAdapter($dbAdapter, 'users', 'usr_email', 'usr_password', "MD5(CONCAT('{$staticSalt}', ?, usr_password_salt)) AND usr_active = 1");
             $authAdapter->setIdentity($data['usr_email'])->setCredential($data['usr_password']);
             $auth = new AuthenticationService();
             $result = $auth->authenticate($authAdapter);
             switch ($result->getCode()) {
                 case Result::FAILURE_IDENTITY_NOT_FOUND:
                     break;
                 case Result::FAILURE_CREDENTIAL_INVALID:
                     break;
                 case Result::SUCCESS:
                     $storage = $auth->getStorage();
                     $storage->write($authAdapter->getResultRowObject(null, 'usr_password'));
                     $time = 1209600;
                     // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                     if ($data['rememberme']) {
                         $sessionManager = new \Zend\Session\SessionManager();
                         $sessionManager->rememberMe($time);
                     }
                     break;
                 default:
                     break;
             }
             foreach ($result->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
         }
     }
     return new ViewModel(array('form' => $form, 'messages' => $messages));
 }
 public function loginAction()
 {
     if ($user = $this->identity()) {
         return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
     }
     $form = new LoginForm();
     $form->get('submit')->setValue('Entrar');
     $messages = null;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new LoginFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
             $adapter = $authService->getAdapter();
             $login = $request->getPost('login');
             $usernameOrEmail = $data['usernameOrEmail'];
             if ($user = $this->getEntityManager()->getRepository('CsnUser\\Entity\\User')->findOneBy(array('email' => $usernameOrEmail))) {
                 $data['usernameOrEmail'] = $user->getUsername();
                 // Set username to the input array in place of the email
             }
             $adapter->setIdentityValue($data['usernameOrEmail']);
             $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
                 if ($data['rememberme']) {
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                 }
                 return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
             }
             foreach ($authResult->getMessages() as $message) {
                 $messages .= "{$message}\n";
             }
         }
     }
     return new ViewModel(array('error' => 'Suas credenciais de autenticação não são válidos', 'form' => $form, 'messages' => $messages, 'navMenu' => $this->getOptions()->getNavMenu()));
 }
Exemplo n.º 9
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));
 }
Exemplo n.º 10
0
 public function loginAction()
 {
     $userLogin = new AuthenticationService();
     if ($userLogin->hasIdentity()) {
         $identity = $userLogin->getIdentity();
         return $this->forward()->dispatch('Application\\Controller\\Index', array('action' => 'listar'));
     } else {
         $form = new Login();
         $form->get('submit')->setValue('Login');
         $messages = null;
         $request = $this->getRequest();
         if ($request->isPost()) {
             $loginFilters = new LoginValidator();
             $form->setInputFilter($loginFilters->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $data = $form->getData();
                 $sm = $this->getServiceLocator();
                 $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
                 $config = $this->getServiceLocator()->get('Config');
                 $indexAdapter = new IndexAdapter($dbAdapter, 'zml_admin', 'usr_name', 'usr_password');
                 $indexAdapter->setIdentity($data['usr_name'])->setCredential($data['usr_password']);
                 $auth = new AuthenticationService();
                 // or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module.
                 //$auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
                 // $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called.
                 $result = $auth->authenticate($indexAdapter);
                 switch ($result->getCode()) {
                     case Result::FAILURE_IDENTITY_NOT_FOUND:
                         echo "prueba";
                         die;
                         break;
                     case Result::FAILURE_CREDENTIAL_INVALID:
                         echo "prueba";
                         die;
                         break;
                     case Result::SUCCESS:
                         $storage = $auth->getStorage();
                         $storage->write($indexAdapter->getResultRowObject(null, 'usr_password'));
                         $time = 1209600;
                         // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                         //						if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
                         if ($data['rememberme']) {
                             $sessionManager = new \Zend\Session\SessionManager();
                             $sessionManager->rememberMe($time);
                         }
                         return $this->forward()->dispatch('Application\\Controller\\Index', array('action' => 'listar'));
                         break;
                     default:
                         echo "prueba";
                         die;
                         break;
                 }
                 foreach ($result->getMessages() as $message) {
                     $messages .= "{$message}\n";
                 }
             }
         }
         $viewModel = new ViewModel(array('form' => $form, 'messages' => $messages));
         $viewModel->setTerminal(true);
         return $viewModel;
     }
 }
Exemplo n.º 11
0
 public function fauth($username, $pass, $table)
 {
     $sm = $this->getServiceLocator();
     $container = new Container('username');
     $dba = $sm->get($container->adapter);
     $sql = "Select Teacher_id from teacher where username='******'";
     $statement = $dba->query($sql, array(5));
     $resultSet = new ResultSet();
     $resultSet->initialize($statement);
     $tid = 0;
     foreach ($resultSet as $row) {
         $tid = $row['Teacher_id'];
     }
     $config = $this->getServiceLocator()->get('Config');
     $staticSalt = $config['static_salt'];
     if ($table == "teacher") {
         $authAdapter = new AuthAdapter($dba, $table, 'username', 'Teacher_pass', "MD5(CONCAT('{$staticSalt}', Teacher_salt))");
     } else {
         if ($table == "admin") {
             $authAdapter = new AuthAdapter($dba, $table, 'Admin_id', 'Admin_pass', "MD5(CONCAT('{$staticSalt}', Admin_salt))");
         }
     }
     $authAdapter->setIdentity($username)->setCredential($pass);
     $auth = new AuthenticationService();
     // or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module.
     // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
     // $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called.
     $result = $auth->authenticate($authAdapter);
     switch ($result->getCode()) {
         case Result::FAILURE_IDENTITY_NOT_FOUND:
             // do stuff for other failure
             break;
         case Result::FAILURE_CREDENTIAL_INVALID:
             // do stuff for other failure
             break;
         case Result::SUCCESS:
             if ($table == "teacher") {
                 $container->id = $tid;
                 $container->type = 1;
                 $storage = $auth->getStorage();
                 $storage->write($authAdapter->getResultRowObject(null, 'Teacher_pass'));
                 $time = 1209600;
                 // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                 //						if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
                 $sessionManager = new \Zend\Session\SessionManager();
                 $sessionManager->rememberMe($time);
                 return $this->redirect()->toRoute('teacher', array('controller' => 'index', 'action' => 'index'));
             } else {
                 if ($table == "admin") {
                     $container->id = $username;
                     $container->type = 0;
                     $container->sub = "";
                     $storage = $auth->getStorage();
                     $storage->write($authAdapter->getResultRowObject(null, 'Admin_pass'));
                     $time = 1209600;
                     // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days
                     //						if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session
                     $sessionManager = new \Zend\Session\SessionManager();
                     $sessionManager->rememberMe($time);
                     return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action' => 'index'));
                 }
             }
         default:
             // do stuff for other failure
             break;
     }
 }
Exemplo n.º 12
0
 public function signinAction()
 {
     $user = $this->identity();
     $auth = new AuthenticationService();
     if (!$auth->hasIdentity()) {
         $messages = null;
         $form = new SigninForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $signinFormFilter = new SigninUserModel();
             $form->setInputFilter($signinFormFilter->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $data = $form->getData();
                 $sm = $this->getServiceLocator();
                 $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
                 $config = $this->getServiceLocator()->get('Config');
                 $authAdapter = new AuthAdapter($dbAdapter, 'user', 'email', 'password');
                 $authAdapter->setIdentity($data['email']);
                 $authAdapter->setCredential(md5($data['password']));
                 $result = $auth->authenticate($authAdapter);
                 switch ($result->getCode()) {
                     case Result::FAILURE_IDENTITY_NOT_FOUND:
                         break;
                     case Result::FAILURE_CREDENTIAL_INVALID:
                         break;
                     case Result::SUCCESS:
                         $storage = $auth->getStorage();
                         $storage->write($authAdapter->getResultRowObject(null, 'password'));
                         $time = 604800;
                         //7 days
                         if ($data['rememberme']) {
                             $sessionManager = new \Zend\Session\SessionManager();
                             $sessionManager->rememberMe($time);
                         }
                         return $this->redirect()->toRoute('user', array('action' => 'index'));
                     default:
                         break;
                 }
                 foreach ($result->getMessages() as $message) {
                     $messages .= "{$message}\n";
                 }
             }
         }
         return new ViewModel(array('form' => $form, 'messages' => $messages));
     } else {
         return $this->redirect()->toRoute('user', array('action' => 'index'));
     }
     //        $user_session = new \Zend\Session\Container('user');
     //        if ($user_session->email!=null) {
     //            return $this->redirect()->toRoute('user',array('action'=>'index'));
     //        }
     //        $form = new SigninForm();
     //        $item = new SigninUserModel();
     //        $request = $this->getRequest();
     //        if ($request->isPost()) {
     //            $form->setInputFilter($item->getInputFilter());
     //            $form->setData($request->getPost());
     //            if ($form->isValid()) {
     //                $item->email = $form->get('email')->getValue();
     //                $item->password = $form->get('password')->getValue();
     //                $success = $this->getTable()->signin($item);
     //                if ($success) {
     //                    $user_session = new \Zend\Session\Container('user');
     //                    $user_session->email=$success->email;
     //                    $user_session->role=$success->role;
     //                    return $this->redirect()->toRoute('user');
     //                } else {
     //                    $error='Wrong email or password';
     //                }
     //            }
     //        }
     //
     //        return array(
     //            'form'=>$form,
     //            'error'=>$error
     //        );
 }
Exemplo n.º 13
0
 public function authenticate(AuthEvent $e)
 {
     if ($this->isSatisfied()) {
         $storage = $this->getStorage()->read();
         $e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
         return;
     }
     $identity = $e->getRequest()->getPost()->get('identity');
     $credential = $e->getRequest()->getPost()->get('credential');
     $remember = $e->getRequest()->getPost()->get('remember');
     $credential = $this->preProcessCredential($credential);
     $userObject = NULL;
     // Cycle through the configured identity sources and test each
     $fields = $this->getOptions()->getAuthIdentityFields();
     while (!is_object($userObject) && count($fields) > 0) {
         $mode = array_shift($fields);
         switch ($mode) {
             case 'username':
                 $userObject = $this->getMapper()->findByUsername($identity);
                 var_dump($userObject);
                 break;
             case 'email':
                 $userObject = $this->getMapper()->findByEmail($identity);
                 var_dump($userObject);
                 break;
         }
     }
     if (!$userObject) {
         $e->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.'));
         $this->setSatisfied(false);
         return false;
     }
     if ($this->getOptions()->getEnableUserState()) {
         // Don't allow user to login if state is not in allowed list
         if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) {
             $e->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.'));
             $this->setSatisfied(false);
             return false;
         }
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->getOptions()->getPasswordCost());
     var_dump($credential, $userObject->getPassword());
     exit;
     if (!$bcrypt->verify($credential, $userObject->getPassword())) {
         // Password does not match
         $e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.'));
         $this->setSatisfied(false);
         return false;
     }
     // Success!
     $e->setIdentity($userObject->getId());
     // Update user's password hash if the cost parameter has changed
     $this->updateUserPasswordHash($userObject, $credential, $bcrypt);
     $this->setSatisfied(true);
     // One Yeah session 31536000 seconds
     if ($remember == 1) {
         $this->getServiceManager()->get('user_remember')->setRememberMe(1);
     }
     $this->setStorage($this->getServiceManager()->get('user_remember'));
     $storage = $this->getStorage()->read();
     $storage['identity'] = $e->getIdentity();
     $this->getStorage()->write($storage);
     $time = 1209600;
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->rememberMe($time);
     $e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
 }