2017-12-04 20:09:23 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2018-01-31 05:29:05 +01:00
|
|
|
* @file src/Network/FKOAuth1.php
|
2017-12-04 20:09:23 +01:00
|
|
|
*/
|
2017-12-04 21:59:21 +01:00
|
|
|
namespace Friendica\Network;
|
2017-12-04 20:09:23 +01:00
|
|
|
|
2018-12-26 07:06:24 +01:00
|
|
|
use Friendica\Core\Hook;
|
2018-10-29 22:20:46 +01:00
|
|
|
use Friendica\Core\Logger;
|
2017-12-04 20:09:23 +01:00
|
|
|
use Friendica\Core\PConfig;
|
|
|
|
use Friendica\Core\System;
|
2018-07-20 14:19:26 +02:00
|
|
|
use Friendica\Database\DBA;
|
2018-01-27 03:38:34 +01:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2017-12-05 02:30:10 +01:00
|
|
|
use OAuthServer;
|
2017-12-05 03:18:48 +01:00
|
|
|
use OAuthSignatureMethod_HMAC_SHA1;
|
2018-01-31 05:29:05 +01:00
|
|
|
use OAuthSignatureMethod_PLAINTEXT;
|
2017-12-04 20:09:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief OAuth protocol
|
|
|
|
*/
|
|
|
|
class FKOAuth1 extends OAuthServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(new FKOAuthDataStore());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
|
|
|
|
}
|
|
|
|
|
2017-12-04 20:52:04 +01:00
|
|
|
/**
|
|
|
|
* @param string $uid user id
|
|
|
|
* @return void
|
2019-01-06 22:06:53 +01:00
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2017-12-04 20:52:04 +01:00
|
|
|
*/
|
2017-12-05 03:03:39 +01:00
|
|
|
public function loginUser($uid)
|
2017-12-04 20:09:23 +01:00
|
|
|
{
|
2018-10-29 22:20:46 +01:00
|
|
|
Logger::log("FKOAuth1::loginUser $uid");
|
2018-12-28 01:22:35 +01:00
|
|
|
$a = \get_app();
|
2018-07-20 14:19:26 +02:00
|
|
|
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
|
2017-12-04 20:52:04 +01:00
|
|
|
|
2018-07-21 14:46:04 +02:00
|
|
|
if (!DBA::isResult($record)) {
|
2018-10-30 14:58:45 +01:00
|
|
|
Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
|
2017-12-04 20:52:04 +01:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
die('This api requires login');
|
2017-12-04 20:09:23 +01:00
|
|
|
}
|
|
|
|
$_SESSION['uid'] = $record['uid'];
|
|
|
|
$_SESSION['theme'] = $record['theme'];
|
|
|
|
$_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
|
|
|
|
$_SESSION['authenticated'] = 1;
|
|
|
|
$_SESSION['page_flags'] = $record['page-flags'];
|
|
|
|
$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
|
|
|
|
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
|
|
|
|
$_SESSION["allow_api"] = true;
|
|
|
|
|
|
|
|
$a->user = $record;
|
|
|
|
|
|
|
|
if (strlen($a->user['timezone'])) {
|
|
|
|
date_default_timezone_set($a->user['timezone']);
|
|
|
|
$a->timezone = $a->user['timezone'];
|
|
|
|
}
|
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
$contact = DBA::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
|
2018-07-21 14:46:04 +02:00
|
|
|
if (DBA::isResult($contact)) {
|
2018-01-11 09:26:30 +01:00
|
|
|
$a->contact = $contact;
|
|
|
|
$a->cid = $contact['id'];
|
2017-12-04 20:09:23 +01:00
|
|
|
$_SESSION['cid'] = $a->cid;
|
|
|
|
}
|
2017-12-04 20:52:04 +01:00
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
DBA::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
|
2017-12-04 20:09:23 +01:00
|
|
|
|
2018-12-26 07:06:24 +01:00
|
|
|
Hook::callAll('logged_in', $a->user);
|
2017-12-04 20:09:23 +01:00
|
|
|
}
|
|
|
|
}
|