public function write($contents)
 {
     parent::write($contents);
     //check if $contents is array
     if (is_array($contents) && !empty($contents)) {
         $this->getSessionManager()->getSaveHandler()->write($this->getSessionId(), \Zend\Json\Json::encode($contents));
     }
 }
Exemple #2
0
 public function testSetGetStorage()
 {
     $identity = mt_rand(1, 100);
     $sessionStorage = new Session();
     $sessionStorage->write($identity);
     $this->testedObject->setStorage($sessionStorage);
     $result = $this->testedObject->getStorage();
     $this->assertInstanceOf(Session::class, $result);
     $this->assertSame($identity, $result->read());
 }
Exemple #3
0
 public function authenticate()
 {
     $result = new Result(1, 1, array(1 => 'Witaj ' . $this->username));
     $ses = new SessionStorage();
     $ses->write($result);
     $auth = new AuthenticationService();
     // Use 'someNamespace' instead of 'Zend_Auth'
     $auth->setStorage(new SessionStorage('someNamespace'));
     var_dump($auth->getStorage()->read());
     return $result;
 }
Exemple #4
0
 public function loginAction()
 {
     if (!empty($this->postData)) {
         $adminName = $this->postData['adminName'];
         $password = $this->postData['password'];
         $where = array('username' => $adminName, 'passwd' => $this->adminModel->genPassword($password));
         $adminLoginInfo = $this->adminModel->select($where)->current();
         if (!empty($adminLoginInfo)) {
             $session = new Session(self::ADMIN_PLATFORM);
             $session->write($adminLoginInfo);
             return $this->redirect()->toUrl('/admin/index/index');
         } else {
             $this->view->setVariable('error', '用户名或密码错误');
         }
     }
     return $this->view;
 }
 protected function mockLogin()
 {
     $userSessionValues = new \stdClass();
     $userSessionValues->id = 2;
     $userSessionValues->username = '******';
     $userSessionValues->role = 'administrator';
     $userSessionModel = new Session();
     $userSessionModel->write($userSessionValues);
     $authService = $this->getMock('Zend\\Authentication\\AuthenticationService');
     //     	$authService->expects($this->any())
     // 			    	->method('getIdentity')
     // 			    	->will($this->returnValue($userSessionModel));
     $authService->expects($this->any())->method('hasIdentity')->will($this->returnValue(true));
     //     	$authService->getStorage()->write($userSessionModel);
     $authService->expects($this->any())->method('getStorage')->will($this->returnValue($userSessionModel));
     $this->getApplicationServiceLocator()->setAllowOverride(true);
     $this->getApplicationServiceLocator()->setService('Zend\\Authentication\\AuthenticationService', $authService);
 }
 /**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface
  *                                                                   If authentication cannot be performed
  */
 public function authenticate()
 {
     /* Anti Injection de login */
     $login1 = Security\AntiInjection::antiSqlInjection1($this->getIdentity());
     $login2 = Security\AntiInjection::antiSqlInjection2($login1);
     $identity = Security\AntiInjection::antiSqlInjection3($login2);
     /* Anti Injection de senha */
     $senha1 = Security\AntiInjection::antiSqlInjection1($this->getCredential());
     $senha2 = Security\AntiInjection::antiSqlInjection2($senha1);
     $senha3 = Security\AntiInjection::antiSqlInjection3($senha2);
     /* Criptografa a senha */
     $crypt = new Security\Crypt();
     $credential = $crypt->encrypt($senha3);
     //Define os dados para processar o login
     $this->setIdentity($identity)->setCredential($credential);
     //Faz inner join dos dados do perfil no SELECT do Auth_Adapter
     $select = $this->getDbSelect();
     $select->where("ind_status = 'A'");
     //Efetua o login
     $result = parent::authenticate();
     //Verifica se o login foi efetuado com sucesso
     if ($result->isValid()) {
         //Recupera o objeto do usuário, sem a senha
         $info = $this->getResultRowObject($this->returnColumns, $this->credentialColumn);
         $storage = new SessionStorage();
         $storage->write($info);
         if ($result->getCode()) {
             return new ResultValidation(ResultValidation::SUCCESS, (array) $info);
         } else {
             return new ResultValidation(ResultValidation::FAILURE, null);
         }
     } else {
         return new ResultValidation(ResultValidation::FAILURE, null);
     }
 }
 public function write($contents)
 {
     $id = $contents->getId();
     parent::write($id);
 }
 public function loginAdminAction()
 {
     $authAdmin = new AuthenticationService();
     $authAdmin->setStorage(new SessionStorage("SessaoAdmin"));
     $authAdmin->clearIdentity();
     $authAdminLanguage = new AuthenticationService();
     $authAdminLanguage->setStorage(new SessionStorage("LanguageUserAdmin"));
     $authAdminLanguage->clearIdentity();
     $authReseller = new AuthenticationService();
     $authReseller->setStorage(new SessionStorage("SessaoReseller"));
     $authReseller->clearIdentity();
     $authResellerLanguage = new AuthenticationService();
     $authResellerLanguage->setStorage(new SessionStorage("LanguageUserReseller"));
     $authResellerLanguage->clearIdentity();
     // Recuperar parâmetros passados pela url
     $param = $this->params()->fromRoute('id', 0);
     /** @var \Application\Entity\WcUser $user */
     $user = $this->getEm()->getRepository("Application\\Entity\\WcUser")->find($param);
     if ($user) {
         $arraySession = $this->getArraySession($user);
         /** @var \Application\Service\ApplicationUserService $userLogged */
         $userLogged = $this->getServiceLocator()->get("Application\\Service\\ApplicationUserService");
         $userLogged->setUserLogged($arraySession);
         $sessionStorageLanguageUser = new SessionStorage("LanguageUser");
         $sessionStorageLanguageUser->write($user->getLanguage()->getAbbreviation(), NULL);
         $this->getServiceLocator()->get('Application\\Service\\ApplicationAccessLog')->save(['type' => 1, 'description' => 'Login Access - ' . $user->getFirstname() . ' ' . $user->getLastname()]);
     }
     return $this->redirect()->toRoute('home');
 }
Exemple #9
0
 /**
  * @param $newData
  */
 public function updateSessionData($newData)
 {
     $this->storage->write($newData);
 }
Exemple #10
0
 public function regAction()
 {
     if (empty($this->postData)) {
         return $this->view;
     }
     $mobile = $this->postData['mobile'];
     $password = $this->postData['password'];
     //$confirmPassword = $this->postData['confirmPassword'];
     $nickName = $this->postData['nickName'];
     if (empty($mobile) || empty($password) || empty($nickName)) {
         return $this->response(ApiError::PARAMETER_MISSING, ApiError::PARAMETER_MISSING_MSG);
     }
     if (!$this->validateMobile($mobile)) {
         return $this->response(ApiError::MOBILE_VALIDATE_FAILED, ApiError::MOBILE_VALIDATE_FAILED_MSG);
     }
     if (strlen($password) < 6) {
         return $this->response(ApiError::PASSWORD_LT_SIX_WORDS, ApiError::PASSWORD_LT_SIX_WORDS_MSG);
     }
     if (mb_strlen($nickName, 'UTF-8') > 5) {
         return $this->response(ApiError::COMMON_ERROR, '昵称字数超过限制');
     }
     /*if($password != $confirmPassword){
           return $this->response(ApiError::TWICE_PASSWORD_NOT_SIMILAR, ApiError::TWICE_PASSWORD_NOT_SIMILAR_MSG);
       }*/
     $verifyCode = $this->mobileVerifyCodeModel->getLastVerifyCode($mobile);
     if ($verifyCode != $this->postData['verifyCode']) {
         return $this->response(ApiError::VERIFY_CODE_INVALID, ApiError::VERIFY_CODE_INVALID_MSG);
     }
     $where = array('nickName' => $nickName);
     $existMember = $this->memberInfoModel->select($where)->current();
     if (!empty($existMember)) {
         return $this->response(ApiError::MEMBER_EXIST_NICK_NAME, ApiError::MEMBER_EXIST_NICK_NAME_MSG);
     }
     $where = array('mobile' => $mobile);
     $existMember = $this->memberInfoModel->select($where)->current();
     if (!empty($existMember)) {
         return $this->response(ApiError::MEMBER_EXIST_MOBILE, ApiError::MEMBER_EXIST_MOBILE_MSG);
     }
     $data = array('mobile' => $mobile, 'password' => $this->memberModel->genPassword($password));
     $this->memberModel->insert($data);
     $memberID = $this->memberModel->getLastInsertValue();
     $memberInfoData = array('memberID' => $memberID, 'nickName' => $nickName, 'mobile' => $mobile);
     $this->memberInfoModel->insert($memberInfoData);
     $token = array('memberID' => $memberID, 'token' => uniqid());
     $this->tokenModel->insert($token);
     $memberInfo = array('token' => $token['token'], 'memberID' => $memberID, 'nickName' => $nickName);
     $loginSession = new Session(self::FRONT_PLATFORM, null, null);
     $loginSession->write($memberInfo);
     return $this->response(ApiSuccess::COMMON_SUCCESS, ApiSuccess::COMMON_SUCCESS_MSG, $memberInfo);
 }
 /**
  * Escreve os dados recebidos por parametro na sessao
  * 
  * @param string $contents        	
  */
 public function escreveSessao($contents)
 {
     $this->sessionStorage->write($contents, null);
 }
 /**
  * @param  object $identity
  * @return void
  */
 public function write($identity)
 {
     $metadataInfo = $this->options->getClassMetadata();
     $identifierValues = $metadataInfo->getIdentifierValues($identity);
     parent::write($identifierValues);
 }