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\DBM;
11 use Friendica\Network\FKOAuthDataStore;
12 use Friendica\Util\DateTimeFormat;
15 use OAuthSignatureMethod_HMAC_SHA1;
16 use OAuthSignatureMethod_PLAINTEXT;
19 * @brief OAuth protocol
21 class FKOAuth1 extends OAuthServer
26 public function __construct()
28 parent::__construct(new FKOAuthDataStore());
29 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
30 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
34 * @param string $uid user id
37 public function loginUser($uid)
39 logger("FKOAuth1::loginUser $uid");
41 $record = dba::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
43 if (!DBM::is_result($record)) {
44 logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
45 header('HTTP/1.0 401 Unauthorized');
46 die('This api requires login');
48 $_SESSION['uid'] = $record['uid'];
49 $_SESSION['theme'] = $record['theme'];
50 $_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
51 $_SESSION['authenticated'] = 1;
52 $_SESSION['page_flags'] = $record['page-flags'];
53 $_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
54 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
55 $_SESSION["allow_api"] = true;
59 if (strlen($a->user['timezone'])) {
60 date_default_timezone_set($a->user['timezone']);
61 $a->timezone = $a->user['timezone'];
64 $contact = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
65 if (DBM::is_result($contact)) {
66 $a->contact = $contact;
67 $a->cid = $contact['id'];
68 $_SESSION['cid'] = $a->cid;
71 dba::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
73 Addon::callHooks('logged_in', $a->user);