Unified request for uid

This commit is contained in:
Michael 2021-06-08 08:28:14 +00:00
parent 85217941e3
commit 11c8dfe73a
6 changed files with 11 additions and 21 deletions

View File

@ -38,6 +38,8 @@ class Accounts extends BaseApi
*/
public static function rawContent(array $parameters = [])
{
$uid = self::getCurrentUserID();
if (empty($parameters['id']) && empty($parameters['name'])) {
DI::mstdnError()->UnprocessableEntity();
}
@ -56,7 +58,7 @@ class Accounts extends BaseApi
}
}
$account = DI::mstdnAccount()->createFromContactId($id, self::getCurrentUserID());
$account = DI::mstdnAccount()->createFromContactId($id, $uid);
System::jsonExit($account);
}
}

View File

@ -40,7 +40,7 @@ class Follow extends BaseApi
DI::mstdnError()->UnprocessableEntity();
}
$cid = Contact::follow($parameters['id'], self::getCurrentUserID());
$cid = Contact::follow($parameters['id'], $uid);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($cid, $uid)->toArray());
}

View File

@ -42,6 +42,8 @@ class Statuses extends BaseApi
*/
public static function rawContent(array $parameters = [])
{
$uid = self::getCurrentUserID();
if (empty($parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
}
@ -66,8 +68,6 @@ class Statuses extends BaseApi
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
$uid = self::getCurrentUserID();
if (!$uid) {
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
'uid' => 0, 'network' => Protocol::FEDERATED];

View File

@ -34,7 +34,6 @@ class Lists extends BaseApi
public static function delete(array $parameters = [])
{
self::login(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($parameters['id'])) {
@ -55,8 +54,7 @@ class Lists extends BaseApi
public static function post(array $parameters = [])
{
self::login(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$uid = self::getCurrentUserID();
$request = self::getRequest([
'title' => '',

View File

@ -219,10 +219,12 @@ class Statuses extends BaseApi
*/
public static function rawContent(array $parameters = [])
{
$uid = self::getCurrentUserID();
if (empty($parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
}
System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], self::getCurrentUserID()));
System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], $uid));
}
}

View File

@ -173,21 +173,9 @@ class BaseApi extends BaseModule
}
/**
* Log in user via OAuth or Simple HTTP Auth.
*
* Simple Auth allow username in form of <pre>user@server</pre>, ignoring server part
* Log in user via OAuth or Basic HTTP Auth.
*
* @param string $scope the requested scope (read, write, follow)
*
* @throws HTTPException\ForbiddenException
* @throws HTTPException\UnauthorizedException
* @throws HTTPException\InternalServerErrorException
* @hook 'authenticate'
* array $addon_auth
* 'username' => username from login form
* 'password' => password from login form
* 'authenticated' => return status,
* 'user_record' => return authenticated user record
*/
protected static function login(string $scope)
{