]> git.mxchange.org Git - friendica.git/blob - src/Network/FKOAuth1.php
a323f5cd568080cdd9a3a5c17b85fbab2a6a749c
[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
14 require_once "library/OAuth1.php";
15 require_once "include/plugin.php";
16
17 /**
18  * @brief OAuth protocol
19  */
20 class FKOAuth1 extends OAuthServer
21 {
22         /**
23          * @brief Constructor
24          */
25         public function __construct()
26         {
27                 parent::__construct(new FKOAuthDataStore());
28                 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
29                 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
30         }
31
32         /**
33          * @param string $uid user id
34          * @return void
35          */
36         public static function loginUser($uid)
37         {
38                 logger("FKOAuth1::loginUser $uid");
39                 $a = get_app();
40                 $r = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
41
42                 if (DBM::is_result($r)) {
43                         $record = $r;
44                 } else {
45                         logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
46                         header('HTTP/1.0 401 Unauthorized');
47                         die('This api requires login');
48                 }
49                 $_SESSION['uid'] = $record['uid'];
50                 $_SESSION['theme'] = $record['theme'];
51                 $_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
52                 $_SESSION['authenticated'] = 1;
53                 $_SESSION['page_flags'] = $record['page-flags'];
54                 $_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
55                 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
56                 $_SESSION["allow_api"] = true;
57
58                 $a->user = $record;
59
60                 if (strlen($a->user['timezone'])) {
61                         date_default_timezone_set($a->user['timezone']);
62                         $a->timezone = $a->user['timezone'];
63                 }
64
65                 $r = dba::select('contact', array(), array('uid' => $_SESSION['uid'], 'self' => 1), array('limit' => 1));
66                 
67                 if (DBM::is_result($r)) {
68                         $a->contact = $r;
69                         $a->cid = $r['id'];
70                         $_SESSION['cid'] = $a->cid;
71                 }
72
73                 dba::update('user', ['login_date' => datetime_convert()], ['uid' => $_SESSION['uid']]);
74
75                 call_hooks('logged_in', $a->user);
76         }
77 }