use Friendica\Model\Notification;
use Friendica\Model\Photo;
use Friendica\Model\Post;
+use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Model\Verb;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Security\FKOAuth1;
+use Friendica\Security\OAuth;
use Friendica\Security\OAuth1\OAuthRequest;
use Friendica\Security\OAuth1\OAuthUtil;
use Friendica\Util\DateTimeFormat;
*/
function api_user()
{
+ $user = OAuth::getCurrentUserID();
+ if (!empty($user)) {
+ return $user;
+ }
+
if (!empty($_SESSION['allow_api'])) {
return local_user();
}
* Simple Auth allow username in form of <pre>user@server</pre>, ignoring server part
*
* @param App $a App
- * @param bool $do_login try to log in when not logged in, otherwise quit silently
* @throws ForbiddenException
* @throws InternalServerErrorException
* @throws UnauthorizedException
* 'authenticated' => return status,
* 'user_record' => return authenticated user record
*/
-function api_login(App $a, bool $do_login = true)
+function api_login(App $a)
{
$_SESSION["allow_api"] = false;
Logger::warning(API_LOG_PREFIX . 'OAuth error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]);
}
- if (!$do_login) {
- return;
- }
-
Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]);
header('WWW-Authenticate: Basic realm="Friendica"');
throw new UnauthorizedException("This API requires login");
}
if (!DBA::isResult($record)) {
- if (!$do_login) {
- return;
- }
Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]);
header('WWW-Authenticate: Basic realm="Friendica"');
//header('HTTP/1.0 401 Unauthorized');
api_login($a);
return false;
} else {
- $user = $_SESSION['uid'];
+ $user = api_user();
$extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` ";
}
}
Contact::updateSelfFromUserID(api_user(), true);
// Update global directory in background
- $url = DI::baseUrl() . '/profile/' . DI::app()->user['nickname'];
- if ($url && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $url);
- }
-
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user());
+ Profile::publishUpdate(api_user());
// output for client
if ($data) {
DBA::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]);
}
- Worker::add(PRIORITY_LOW, 'ProfileUpdate', $local_user);
- // Update global directory in background
- if ($api_user['url'] && strlen(DI::config()->get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $api_user['url']);
- }
+ Profile::publishUpdate($local_user);
return api_account_verify_credentials($type);
}