]> git.mxchange.org Git - friendica.git/blob - src/Network/FKOAuth1.php
31960a91dac54b8fe3e4ba2614a2620c9c6bec44
[friendica.git] / src / Network / FKOAuth1.php
1 <?php
2 /**
3  * @file src/Protocol/OAuth1.php
4  */
5 namespace Friendica\Network;
6
7 use Friendica\App;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Network\FKOAuthDataStore;
12 use dba;
13 use OAuthServer;
14
15 require_once "library/OAuth1.php";
16 require_once "include/plugin.php";
17
18 /**
19  * @brief OAuth protocol
20  */
21 class FKOAuth1 extends OAuthServer
22 {
23         /**
24          * @brief Constructor
25          */
26         public function __construct()
27         {
28                 parent::__construct(new FKOAuthDataStore());
29                 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
30                 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
31         }
32
33         /**
34          * @param string $uid user id
35          * @return void
36          */
37         public static function loginUser($uid)
38         {
39                 logger("FKOAuth1::loginUser $uid");
40                 $a = get_app();
41                 $record = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
42
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');
47                 }
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;
56
57                 $a->user = $record;
58
59                 if (strlen($a->user['timezone'])) {
60                         date_default_timezone_set($a->user['timezone']);
61                         $a->timezone = $a->user['timezone'];
62                 }
63
64                 $r = dba::select('contact', array(), array('uid' => $_SESSION['uid'], 'self' => 1), array('limit' => 1));
65                 
66                 if (DBM::is_result($r)) {
67                         $a->contact = $r;
68                         $a->cid = $r['id'];
69                         $_SESSION['cid'] = $a->cid;
70                 }
71
72                 dba::update('user', ['login_date' => datetime_convert()], ['uid' => $_SESSION['uid']]);
73
74                 call_hooks('logged_in', $a->user);
75         }
76 }