]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/FKOAuth1.php
Centralized gsid generation
[friendica.git] / src / Network / FKOAuth1.php
index 07e15ad51ee72a2fd0f8659a7a27b8beea092f74..642fab111a1912c205a0318f0e98b8168aa919bd 100644 (file)
@@ -1,29 +1,40 @@
 <?php
 /**
- * @file src/Protocol/OAuth1.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Network;
 
-use Friendica\App;
-use Friendica\Core\PConfig;
-use Friendica\Core\System;
-use Friendica\Database\DBM;
-use Friendica\Network\FKOAuthDataStore;
-use dba;
+use Friendica\Core\Logger;
+use Friendica\Database\DBA;
+use Friendica\DI;
 use OAuthServer;
-use OAuthSignatureMethod_PLAINTEXT;
 use OAuthSignatureMethod_HMAC_SHA1;
-
-require_once "library/OAuth1.php";
-require_once "include/plugin.php";
+use OAuthSignatureMethod_PLAINTEXT;
 
 /**
- * @brief OAuth protocol
+ * OAuth protocol
  */
 class FKOAuth1 extends OAuthServer
 {
        /**
-        * @brief Constructor
+        * Constructor
         */
        public function __construct()
        {
@@ -35,44 +46,21 @@ class FKOAuth1 extends OAuthServer
        /**
         * @param string $uid user id
         * @return void
+        * @throws HTTPException\ForbiddenException
+        * @throws HTTPException\InternalServerErrorException
         */
        public function loginUser($uid)
        {
-               logger("FKOAuth1::loginUser $uid");
-               $a = get_app();
-               $record = dba::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
+               Logger::log("FKOAuth1::loginUser $uid");
+               $a = DI::app();
+               $record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
 
-               if (!DBM::is_result($record)) {
-                       logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
+               if (!DBA::isResult($record)) {
+                       Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
                        header('HTTP/1.0 401 Unauthorized');
                        die('This api requires login');
                }
-               $_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'];
-               }
-
-               $r = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
-               
-               if (DBM::is_result($r)) {
-                       $a->contact = $r;
-                       $a->cid = $r['id'];
-                       $_SESSION['cid'] = $a->cid;
-               }
-
-               dba::update('user', ['login_date' => datetime_convert()], ['uid' => $_SESSION['uid']]);
 
-               call_hooks('logged_in', $a->user);
+               DI::auth()->setForUser($a, $record, true);
        }
 }