public function loginAction()
 {
     $redirect = 'dashboard';
     if ($this->auth->hasIdentity()) {
         return $this->redirect()->toRoute($redirect);
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->authForm->setData($request->getPost());
         if ($this->authForm->isValid()) {
             $authAdapter = new AuthAdapter($this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'));
             $authAdapter->setTableName('admins')->setIdentityColumn('email')->setCredentialColumn('password')->setIdentity($request->getPost('email'))->setCredential($request->getPost('password'))->setCredentialTreatment('md5(?)');
             $Site_Id = 1;
             $authAdapter->getDbSelect()->where('site_id=' . $Site_Id);
             $result = $this->auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 if ($request->getPost('remember_me') == 1) {
                     $storage = $this->getServiceLocator()->get('Application\\Model\\MyAuthStorage');
                     $storage->setRememberMe(1);
                 }
                 $this->flashmessenger()->addMessage('You are looged in successfully');
                 return $this->redirect()->toRoute($redirect);
             } else {
                 $this->flashmessenger()->addErrorMessage('Invalid username or password, try again.');
                 return $this->redirect()->toRoute('home');
             }
         }
     }
     $viewModel = new ViewModel(array('form' => $this->authForm));
     $viewModel->setTerminal(true);
     return $viewModel;
 }
示例#2
0
 public function getAdapter()
 {
     $adapter = new AuthAdapter($this->db, 'credentials_password', 'credentials_password.email', 'credentials_password.password');
     $adapter->getDbSelect()->join('accounts', 'accounts.id = credentials_password.account');
     $adapter->setIdentity($this->email);
     $adapter->setCredential($this->getHashedPassword());
     return $adapter;
 }
示例#3
0
 /**
  * @group ZF-5957
  */
 public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfterAuth()
 {
     $select = $this->_adapter->getDbSelect();
     $select->where('1 = 1');
     $this->_adapter->setIdentity('my_username');
     $this->_adapter->setCredential('my_password');
     $this->_adapter->authenticate();
     $selectAfterAuth = $this->_adapter->getDbSelect();
     $whereParts = $selectAfterAuth->where->getPredicates();
     $this->assertEquals(1, count($whereParts));
     $lastWherePart = array_pop($whereParts);
     $expressionData = $lastWherePart[1]->getExpressionData();
     $this->assertEquals('1 = 1', $expressionData[0][0]);
 }
示例#4
0
 public function getAuthenticationAdapter()
 {
     if ($this->authenticationAdapter === NULL) {
         $authenticationAdapter = new DbTable($this->getAdapter(), $this->getTableName(), $this->getIdentityColumn(), $this->getCredentialColumn());
         $select = $authenticationAdapter->getDbSelect();
         if ($this->getOption('where') !== NULL) {
             $select->where($this->getOption('where'));
         }
         $this->setAuthenticationAdapter($authenticationAdapter);
     }
     return $this->authenticationAdapter;
 }
示例#5
0
 /**
  * Return service config array
  *
  * @return array
  */
 public function getServiceConfig()
 {
     return ['factories' => ['User\\AuthService' => function () {
         $adapter = $this->serviceLocator->get('Zend\\Db\\Adapter\\Adapter');
         $authAdapter = new DbTableAuthAdapter($adapter, 'user_list', 'nick_name', 'password', 'SHA1(CONCAT(MD5(?), "' . $this->serviceLocator->get('Config')['site_salt'] . '"))');
         $select = $authAdapter->getDbSelect();
         $select->where(['status' => UserBaseModel::STATUS_APPROVED]);
         $authService = new AuthenticationService();
         $authService->setAdapter($authAdapter);
         return $authService;
     }]];
 }