3 * @file src/Network/FKOAuth1.php
5 namespace Friendica\Network;
7 use Friendica\Core\Addon;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Util\DateTimeFormat;
13 use OAuthSignatureMethod_HMAC_SHA1;
14 use OAuthSignatureMethod_PLAINTEXT;
17 * @brief OAuth protocol
19 class FKOAuth1 extends OAuthServer
24 public function __construct()
26 parent::__construct(new FKOAuthDataStore());
27 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
28 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
32 * @param string $uid user id
35 public function loginUser($uid)
37 logger("FKOAuth1::loginUser $uid");
39 $record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
41 if (!DBA::is_result($record)) {
42 logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
43 header('HTTP/1.0 401 Unauthorized');
44 die('This api requires login');
46 $_SESSION['uid'] = $record['uid'];
47 $_SESSION['theme'] = $record['theme'];
48 $_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
49 $_SESSION['authenticated'] = 1;
50 $_SESSION['page_flags'] = $record['page-flags'];
51 $_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
52 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
53 $_SESSION["allow_api"] = true;
57 if (strlen($a->user['timezone'])) {
58 date_default_timezone_set($a->user['timezone']);
59 $a->timezone = $a->user['timezone'];
62 $contact = DBA::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
63 if (DBA::is_result($contact)) {
64 $a->contact = $contact;
65 $a->cid = $contact['id'];
66 $_SESSION['cid'] = $a->cid;
69 DBA::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
71 Addon::callHooks('logged_in', $a->user);