Пример #1
0
 static function create($values)
 {
     self::$unique_key = self::$unique_key + 1;
     $values = array_merge(array('uid' => 1, 'api_key' => md5(self::$unique_key), 'api_secret' => 'api_secret', 'enabled' => true), $values);
     $dao = new ApiKeys_ApiKeyDao(Database::obtain());
     $struct = new ApiKeys_ApiKeyStruct($values);
     return $dao->create($struct);
 }
 private function validKeys()
 {
     $this->api_record = ApiKeys_ApiKeyDao::findByKey($this->api_key);
     return $this->api_record && $this->api_record->validSecret($this->api_secret);
 }
Пример #3
0
{
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
$options = getopt('h', array('email:'));
if (array_key_exists('h', $options)) {
    usage();
}
if (empty($options)) {
    usage();
}
if (!array_key_exists('email', $options)) {
    usage();
}
$dao = new Users_UserDao(Database::obtain());
$result = $dao->read(new Users_UserStruct(array('email' => $options['email'])));
$user = $result[0];
$dao = new ApiKeys_ApiKeyDao(Database::obtain());
$values = array('uid' => $user->uid, 'api_key' => generateRandomString(), 'api_secret' => generateRandomString(), 'enabled' => true);
$insert = $dao->create(new ApiKeys_ApiKeyStruct($values));
echo "News keys added to {$user->email}:\n";
echo "\n";
echo "API KEY:       {$insert->api_key} \n";
echo "API SECRET:    {$insert->api_secret} \n";
echo "ENABLED:       {$insert->enabled} \n";
echo "\n";
Пример #4
0
 private function validateAuthHeader()
 {
     if ($_SERVER['HTTP_X_MATECAT_KEY'] == null) {
         return true;
     }
     $key = ApiKeys_ApiKeyDao::findByKey($_SERVER['HTTP_X_MATECAT_KEY']);
     if ($key && $key->validSecret($_SERVER['HTTP_X_MATECAT_SECRET'])) {
         Log::doLog($key);
         $this->current_user = $key->getUser();
         return true;
     } else {
         return false;
     }
 }