Пример #1
0
 public function create()
 {
     $data = array('id' => $_POST['app'], 'secret' => $_POST['secret']);
     if (empty($data['id']) || empty($data['secret'])) {
         throw new Exception('missing id or secret');
     }
     $app = new App();
     $appInfo = $app->get($data['id']);
     if ($appInfo->secret != $data['secret']) {
         throw new Exception('invalid autentication');
     }
     if ($appInfo->isBanned()) {
         throw new Exception("This app can't create tokens");
     }
     $token = new AuthToken(array('app' => $data['id']));
     return $token->save();
 }
Пример #2
0
 /**
  * updates an auth-token
  *
  * @author Matthias Pfefferle
  * @param int $pUserId
  * @param int $pOnlineIdentityId
  * @param string $pToken
  * @param string $pTokenSecret
  * @param boolean $pActive
  * @return AuthToken
  */
 public static function saveToken($pUserId, $pOnlineIdentityId, $pToken, $pTokenSecret, $pActive = false)
 {
     if ($lCheck = self::getByUserAndOnlineIdentity($pUserId, $pOnlineIdentityId)) {
         $lToken = $lCheck;
     } else {
         $lToken = new AuthToken();
     }
     if ($pActive && $pOnlineIdentityId) {
         $lIdentity = OnlineIdentityTable::getInstance()->retrieveByPK($pOnlineIdentityId);
         $lIdentity->save();
     }
     $lToken->setTokenKey($pToken);
     $lToken->setOnlineIdentityId($pOnlineIdentityId);
     // get online-identity
     $lOnlineIdentity = OnlineIdentityTable::getInstance()->find($pOnlineIdentityId);
     $lToken->setCommunityId($lOnlineIdentity->getCommunityId());
     $lToken->setTokenType(self::TOKEN_TYPE_OAUTH);
     $lToken->setTokenSecret($pTokenSecret);
     $lToken->setUserId($pUserId);
     $lToken->save();
     return $lToken;
 }