2017-12-04 19:09:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Protocol/OAuth1.php
|
|
|
|
*/
|
|
|
|
namespace Friendica\Protocol;
|
|
|
|
|
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\Core\PConfig;
|
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Database\DBM;
|
|
|
|
use Friendica\Protocol\FKOAuthDataStore;
|
|
|
|
use dba;
|
|
|
|
|
|
|
|
require_once "library/OAuth1.php";
|
|
|
|
require_once "include/plugin.php";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief OAuth protocol
|
|
|
|
*/
|
|
|
|
class FKOAuth1 extends OAuthServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(new FKOAuthDataStore());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:52:04 +00:00
|
|
|
/**
|
|
|
|
* @param string $uid user id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function loginUser($uid)
|
2017-12-04 19:09:23 +00:00
|
|
|
{
|
|
|
|
logger("FKOAuth1::loginUser $uid");
|
|
|
|
$a = get_app();
|
2017-12-04 19:52:04 +00:00
|
|
|
$r = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
|
|
|
|
|
|
|
|
if (DBM::is_result($r)) {
|
|
|
|
$record = $r;
|
2017-12-04 19:09:23 +00:00
|
|
|
} else {
|
2017-12-04 19:52:04 +00:00
|
|
|
logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
|
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
die('This api requires login');
|
2017-12-04 19:09:23 +00:00
|
|
|
}
|
|
|
|
$_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'];
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:52:04 +00:00
|
|
|
$r = dba::select('contact', array(), array('uid' => $_SESSION['uid'], 'self' => 1), array('limit' => 1));
|
|
|
|
|
2017-12-04 19:09:23 +00:00
|
|
|
if (DBM::is_result($r)) {
|
2017-12-04 19:52:04 +00:00
|
|
|
$a->contact = $r;
|
|
|
|
$a->cid = $r['id'];
|
2017-12-04 19:09:23 +00:00
|
|
|
$_SESSION['cid'] = $a->cid;
|
|
|
|
}
|
2017-12-04 19:52:04 +00:00
|
|
|
|
|
|
|
dba::q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
|
2017-12-04 19:09:23 +00:00
|
|
|
dbesc(datetime_convert()),
|
|
|
|
intval($_SESSION['uid'])
|
|
|
|
);
|
|
|
|
|
|
|
|
call_hooks('logged_in', $a->user);
|
|
|
|
}
|
|
|
|
}
|