Ejemplo n.º 1
0
 /**
  * 执行Zfirm用户平台的数据验证,获取Token。
  * 
  * @param AuthEvent $e
  * @return mixed
  */
 public function onToken(AuthEvent $e)
 {
     $user = $e->getResult();
     $e->setParam('account', "_qihu_m_{$user['id']}");
     $e->setParam('ip', (new RemoteAddress())->getIpAddress());
     $e->setParam('nickname', iconv('utf-8', 'gbk', $user['name']));
     $user = $this->getUserService();
     if (false === ($zfirm = $user->setToken($e->getParam('account'), $e->getParam('ip'), $e->getParam('nickname')))) {
         return new Failure('获取Zfirm用户平台登陆Token失败。');
     }
     $e->setZfirm($zfirm);
     return $e->getZfirm();
 }
 /**
  * 记录验证用户信息失败的日志
  * 
  * @param AuthEvent $e
  * @return void
  */
 public function onFailure(AuthEvent $e)
 {
     $failure = $e->getFailure();
     $this->logger->warn($failure->getReason(), $failure->getResult());
 }
 /**
  * 测试AuthLoggerListener::onFailure()
  */
 public function testOnFailure()
 {
     $e = new Event();
     $e->setFailure(new Failure('Test', array('result' => '123456')));
     $this->events->trigger(Event::EVENT_FAILURE, $e);
     $this->assertStringMatchesFormat('%s WARN (4): Test {"result":"123456"}%w', file_get_contents($this->destfile));
 }
Ejemplo n.º 4
0
 /**
  * 测试Zfirm用户平台的数据验证——成功
  */
 public function testOnTokenSuccess()
 {
     $token = rand();
     $this->user->expects($this->once())->method('setToken')->with($this->equalTo('_qihu_m_valid_id'), $this->equalTo((new RemoteAddress())->getIpAddress()), $this->equalTo('valid_name'))->will($this->returnValue(array('token' => $token)));
     $e = new Event();
     $e->setResult(array('id' => 'valid_id', 'name' => 'valid_name'));
     $result = $this->http->onToken($e);
     $this->assertArrayHasKey('token', $result);
     $this->assertEquals($token, $result['token']);
 }