Ejemplo n.º 1
0
 /**
  * Authenticate user
  *
  * @param string $login    Login
  * @param string $password Password
  *
  * @return boolean
  */
 public function authenticate($login, $password)
 {
     $authAdapter = new Adapter\DbTable\CredentialTreatmentAdapter($this->getAdapter());
     $authAdapter->setTableName($this->name);
     $authAdapter->setIdentityColumn('login');
     $authAdapter->setCredentialColumn('password');
     $authAdapter->setCredentialTreatment('? AND active = TRUE');
     $authAdapter->setIdentity($login);
     $authAdapter->setCredential(sha1($password));
     $auth = new AuthenticationService(new Storage\Session(self::BACKEND_AUTH_NAMESPACE));
     $result = $auth->authenticate($authAdapter);
     $this->events()->trigger(__CLASS__, 'before.auth', $this);
     if ($result->isValid()) {
         $data = $authAdapter->getResultRowObject(null, 'password');
         $this->setData((array) $data);
         $this->setOrigData();
         $auth->getStorage()->write($this);
         $this->events()->trigger(__CLASS__, 'after.auth', $this);
         return true;
     }
     $this->events()->trigger(__CLASS__, 'after.auth.failed', $this, array('login' => $login));
     return false;
 }
Ejemplo n.º 2
0
 public function loginAction()
 {
     if ($this->userModuleOptions->getDisabledLogin()) {
         echo "禁止登陆";
         exit("indexuser");
         //$b=$aaa['user'];
     }
     $options = $this->getRequest()->getPost();
     $adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $authAdapter = new CredentialTreatmentAdapter($adapter, 'user', 'email', 'password');
     $authAdapter->setIdentity($options->get('email'));
     $authAdapter->setCredential($options->get('password'));
     $authService = new AuthenticationService(new Session('email'), $authAdapter);
     /*$authService = $this->getServiceLocator()->get('my_auth_service');
       $authService->setStorage(new Session('username'));
       $authService->setAdapter($authAdapter);*/
     $result = $authService->authenticate();
     if ($result->isValid()) {
         //                $storage=new ArrayStorage(iterator_to_array($options));
         //                $manager=new SessionManager();
         //                $manager->setStorage($storage);
         $userData = $this->getServiceLocator()->get('User\\Table\\UserTable')->getUser($options->get('email'));
         $sessionContainer = new Container();
         $sessionContainer->offsetSet("user", ["username" => $userData->username, "email" => $options->get('email')]);
         $this->layout()->setVariable("username", $userData->username);
         //how to asign?
         if ($user = $authService->getIdentity()) {
             $this->redirect()->toRoute('forum', ['controller' => 'index', 'action' => 'index']);
         } else {
             echo 'Not logged in';
         }
         // exit("suceess");
     } else {
         exit("die");
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $username
  * @param string $password
  * @return boolean
  */
 public function authenticate($username, $password)
 {
     /* @var $sl \Zend\ServiceManager\ServiceManager */
     $sl = $this->getServiceLocator();
     $authAdapter = new CredentialTreatmentAdapter($sl->get('dbAdapter'), 'users', 'username', 'password', 'MD5(CONCAT(salt,?))');
     $authAdapter->setIdentity($username);
     $authAdapter->setCredential($password);
     /* @var $result \Zend\Authentication\Result */
     $result = $this->getAuthService()->authenticate($authAdapter);
     if ($result->getCode() == \Zend\Authentication\Result::SUCCESS) {
         /* @var $userMapper \User\Model\UserMapper */
         $userMapper = $sl->get('User\\Model\\UserMapper');
         /* @var $user \User\Model\User */
         $user = $userMapper->get(null, $username);
         $this->getAuthService()->getStorage()->write($user->getId());
         return true;
     }
     return false;
 }