示例#1
0
 /**
  * Returns whether the given identity needs an password or not
  *
  * @httpMethod GET
  * @path /
  * @nickname needPassword
  * @parameter query identity string
  * @responseClass PSX_Data_Message
  */
 public function needPassword()
 {
     $identity = $this->get->identity('string');
     $handles = array_map('trim', explode(',', $this->registry['login.provider']));
     $result = array();
     foreach ($handles as $key) {
         $handler = HandlerFactory::factory($key, $this->container);
         if ($handler instanceof HandlerAbstract && $handler->isValid($identity)) {
             $result = array('handler' => $key, 'icon' => $this->config['psx_url'] . '/img/icons/login/' . $key . '.png', 'needPassword' => $handler->hasPassword());
             break;
         }
     }
     echo Json::encode($result);
 }
示例#2
0
文件: Callback.php 项目: visapi/amun
 protected function handleCallback()
 {
     $handler = $this->getUriFragments('loginHandler');
     $handler = HandlerFactory::factory($handler, $this->container);
     if ($handler instanceof CallbackInterface) {
         try {
             $handler->setPageUrl($this->page->getUrl());
             $handler->callback();
         } catch (\Exception $e) {
             $this->template->assign('error', $e->getMessage());
         }
     } else {
         $this->template->assign('error', 'Invalid callback handler');
     }
 }
示例#3
0
文件: Index.php 项目: visapi/amun
 public function onPost()
 {
     if ($this->post->register('string', array(), null, null, false)) {
         header('Location: ' . $this->page->getUrl() . '/register');
         exit;
     }
     $redirect = $this->getRedirect($this->post);
     $identity = $this->post->identity('string', array(new Account\Filter\Identity()));
     $pw = $this->post->pw('string', array(new Account\Filter\Pw(new Security($this->registry))));
     $captcha = $this->post->captcha('integer');
     try {
         if (empty($identity)) {
             throw new Exception('Invalid identity');
         }
         // check captcha if needed
         if ($this->level == Attempt::TRYING) {
             if (!Captcha::factory($this->config['amun_captcha'])->verify($captcha)) {
                 throw new Exception('Invalid captcha');
             }
         }
         // load handles
         $handles = array_map('trim', explode(',', $this->registry['login.provider']));
         foreach ($handles as $handler) {
             $handler = HandlerFactory::factory($handler, $this->container);
             if ($handler instanceof HandlerAbstract && $handler->isValid($identity)) {
                 $handler->setPageUrl($this->page->getUrl());
                 if ($handler->hasPassword() && empty($pw)) {
                     throw new Exception('Invalid password');
                 }
                 try {
                     if ($handler->handle($identity, $pw) === true) {
                         // clear attempts
                         if ($this->level != Attempt::NONE) {
                             $this->attempt->clear();
                         }
                         // redirect
                         $url = $redirect === false ? $this->config['psx_url'] : $redirect;
                         header('Location: ' . $url);
                         exit;
                         break;
                     }
                 } catch (InvalidPasswordException $e) {
                     // increase login attempt
                     $this->attempt->increase();
                     // if none assign captcha
                     if ($this->level == Attempt::NONE) {
                         $captcha = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/core/captcha';
                         $this->template->assign('captcha', $captcha);
                     }
                 }
             }
         }
         throw new Exception('Authentication failed');
     } catch (\Exception $e) {
         $this->template->assign('error', $e->getMessage());
     }
 }