- /**
- * Create and fetch an token for the application and user
- *
- * @param array $application
- * @param integer $uid
- * @param string $scope
- * @return array application record
- */
- public static function createTokenForUser(array $application, int $uid, string $scope)
- {
- $code = bin2hex(random_bytes(32));
- $access_token = bin2hex(random_bytes(32));
-
- $fields = ['application-id' => $application['id'], 'uid' => $uid, 'code' => $code, 'access_token' => $access_token, 'scopes' => $scope,
- 'read' => (stripos($scope, self::SCOPE_READ) !== false),
- 'write' => (stripos($scope, self::SCOPE_WRITE) !== false),
- 'follow' => (stripos($scope, self::SCOPE_FOLLOW) !== false),
- 'push' => (stripos($scope, self::SCOPE_PUSH) !== false),
- 'created_at' => DateTimeFormat::utcNow(DateTimeFormat::MYSQL)];
-
- foreach ([self::SCOPE_READ, self::SCOPE_WRITE, self::SCOPE_WRITE, self::SCOPE_PUSH] as $scope) {
- if ($fields[$scope] && !$application[$scope]) {
- Logger::warning('Requested token scope is not allowed for the application', ['token' => $fields, 'application' => $application]);
+ if ($posts_month > $throttle_month) {
+ Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
+ $error = DI::l10n()->t('Too Many Requests');
+ $error_description = DI::l10n()->t("Monthly posting limit of %d post reached. The post was rejected.", "Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month);
+ $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
+ System::jsonError(429, $errorobj->toArray());