Merge branch 'master' into ssl-client-certs
This commit is contained in:
commit
fbfbd8d5ca
3 changed files with 87 additions and 22 deletions
|
@ -28,6 +28,14 @@ require_once 'SemanticScuttle/Model/User.php';
|
||||||
*/
|
*/
|
||||||
class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The ID of the currently logged on user.
|
||||||
|
* NULL when not logged in.
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
protected $currentuserId = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently logged on user from database
|
* Currently logged on user from database
|
||||||
*
|
*
|
||||||
|
@ -378,10 +386,17 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
*/
|
*/
|
||||||
public function getCurrentUserId()
|
public function getCurrentUserId()
|
||||||
{
|
{
|
||||||
if (isset($_SESSION[$this->getSessionKey()])) {
|
if ($this->currentuserId !== null) {
|
||||||
return (int)$_SESSION[$this->getSessionKey()];
|
return $this->currentuserId;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isset($_COOKIE[$this->getCookieKey()])) {
|
if (isset($_SESSION[$this->getSessionKey()])) {
|
||||||
|
$this->currentuserId = (int)$_SESSION[$this->getSessionKey()];
|
||||||
|
return $this->currentuserId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_COOKIE[$this->getCookieKey()])) {
|
||||||
$cook = explode(':', $_COOKIE[$this->getCookieKey()]);
|
$cook = explode(':', $_COOKIE[$this->getCookieKey()]);
|
||||||
//cookie looks like this: 'id:md5(username+password)'
|
//cookie looks like this: 'id:md5(username+password)'
|
||||||
$query = 'SELECT * FROM '. $this->getTableName() .
|
$query = 'SELECT * FROM '. $this->getTableName() .
|
||||||
|
@ -400,10 +415,10 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
|
|
||||||
if ($row = $this->db->sql_fetchrow($dbresult)) {
|
if ($row = $this->db->sql_fetchrow($dbresult)) {
|
||||||
$this->setCurrentUserId(
|
$this->setCurrentUserId(
|
||||||
(int)$row[$this->getFieldName('primary')]
|
(int)$row[$this->getFieldName('primary')], true
|
||||||
);
|
);
|
||||||
$this->db->sql_freeresult($dbresult);
|
$this->db->sql_freeresult($dbresult);
|
||||||
return (int)$_SESSION[$this->getSessionKey()];
|
return $this->currentuserId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,16 +441,23 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
* @internal
|
* @internal
|
||||||
* No ID verification is being done.
|
* No ID verification is being done.
|
||||||
*
|
*
|
||||||
* @param integer $user User ID or null to unset the user
|
* @param integer $user User ID or null to unset the user
|
||||||
|
* @param boolean $storeInSession Store the user ID in the session
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setCurrentUserId($user)
|
public function setCurrentUserId($user, $storeInSession = false)
|
||||||
{
|
{
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
unset($_SESSION[$this->getSessionKey()]);
|
$this->currentuserId = null;
|
||||||
|
if ($storeInSession) {
|
||||||
|
unset($_SESSION[$this->getSessionKey()]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$_SESSION[$this->getSessionKey()] = (int)$user;
|
$this->currentuserId = (int)$user;
|
||||||
|
if ($storeInSession) {
|
||||||
|
$_SESSION[$this->getSessionKey()] = $this->currentuserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//reload user object
|
//reload user object
|
||||||
$this->getCurrentUser(true);
|
$this->getCurrentUser(true);
|
||||||
|
@ -473,10 +495,9 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
$this->db->sql_freeresult($dbresult);
|
$this->db->sql_freeresult($dbresult);
|
||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$id = $_SESSION[$this->getSessionKey()]
|
$this->setCurrentUserId($row[$this->getFieldName('primary')], true);
|
||||||
= $row[$this->getFieldName('primary')];
|
|
||||||
if ($remember) {
|
if ($remember) {
|
||||||
$cookie = $id .':'. md5($username.$password);
|
$cookie = $this->currentuserId . ':' . md5($username.$password);
|
||||||
setcookie(
|
setcookie(
|
||||||
$this->cookiekey, $cookie,
|
$this->cookiekey, $cookie,
|
||||||
time() + $this->cookietime, '/'
|
time() + $this->cookietime, '/'
|
||||||
|
@ -488,7 +509,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
/**
|
||||||
|
* Logs the user off
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
@setcookie($this->getCookiekey(), '', time() - 1, '/');
|
@setcookie($this->getCookiekey(), '', time() - 1, '/');
|
||||||
unset($_COOKIE[$this->getCookiekey()]);
|
unset($_COOKIE[$this->getCookiekey()]);
|
||||||
session_unset();
|
session_unset();
|
||||||
|
@ -516,10 +543,18 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
return $arrWatch;
|
return $arrWatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWatchNames($uId, $watchedby = false) {
|
|
||||||
// Gets the list of user names being watched by the given user.
|
/**
|
||||||
// - If $watchedby is false get the list of users that $uId watches
|
* Gets the list of user names being watched by the given user.
|
||||||
// - If $watchedby is true get the list of users that watch $uId
|
*
|
||||||
|
* @param integer $uId User ID
|
||||||
|
* @param boolean $watchedby if false: get the list of users that $uId watches
|
||||||
|
* if true: get the list of users that watch $uId
|
||||||
|
*
|
||||||
|
* @return array Array of user names
|
||||||
|
*/
|
||||||
|
public function getWatchNames($uId, $watchedby = false)
|
||||||
|
{
|
||||||
if ($watchedby) {
|
if ($watchedby) {
|
||||||
$table1 = 'b';
|
$table1 = 'b';
|
||||||
$table2 = 'a';
|
$table2 = 'a';
|
||||||
|
@ -527,10 +562,22 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
$table1 = 'a';
|
$table1 = 'a';
|
||||||
$table2 = 'b';
|
$table2 = 'b';
|
||||||
}
|
}
|
||||||
$query = 'SELECT '. $table1 .'.'. $this->getFieldName('username') .' FROM '. $GLOBALS['tableprefix'] .'watched AS W, '. $this->getTableName() .' AS a, '. $this->getTableName() .' AS b WHERE W.watched = a.'. $this->getFieldName('primary') .' AND W.uId = b.'. $this->getFieldName('primary') .' AND '. $table2 .'.'. $this->getFieldName('primary') .' = '. intval($uId) .' ORDER BY '. $table1 .'.'. $this->getFieldName('username');
|
$primary = $this->getFieldName('primary');
|
||||||
|
$userfield = $this->getFieldName('username');
|
||||||
|
$query = 'SELECT '. $table1 .'.'. $userfield
|
||||||
|
. ' FROM '. $GLOBALS['tableprefix'] . 'watched AS W,'
|
||||||
|
. ' ' . $this->getTableName() .' AS a,'
|
||||||
|
. ' ' . $this->getTableName() .' AS b'
|
||||||
|
. ' WHERE W.watched = a.' . $primary
|
||||||
|
. ' AND W.uId = b.' . $primary
|
||||||
|
. ' AND ' . $table2 . '.' . $primary . ' = '. intval($uId)
|
||||||
|
. ' ORDER BY '. $table1 . '.' . $userfield;
|
||||||
|
|
||||||
if (!($dbresult =& $this->db->sql_query($query))) {
|
if (!($dbresult = $this->db->sql_query($query))) {
|
||||||
message_die(GENERAL_ERROR, 'Could not get watchlist', '', __LINE__, __FILE__, $query, $this->db);
|
message_die(
|
||||||
|
GENERAL_ERROR, 'Could not get watchlist',
|
||||||
|
'', __LINE__, __FILE__, $query, $this->db
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,13 +586,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
|
||||||
$this->db->sql_freeresult($dbresult);
|
$this->db->sql_freeresult($dbresult);
|
||||||
return $arrWatch;
|
return $arrWatch;
|
||||||
}
|
}
|
||||||
while ($row =& $this->db->sql_fetchrow($dbresult)) {
|
while ($row = $this->db->sql_fetchrow($dbresult)) {
|
||||||
$arrWatch[] = $row[$this->getFieldName('username')];
|
$arrWatch[] = $row[$this->getFieldName('username')];
|
||||||
}
|
}
|
||||||
$this->db->sql_freeresult($dbresult);
|
$this->db->sql_freeresult($dbresult);
|
||||||
return $arrWatch;
|
return $arrWatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getWatchStatus($watcheduser, $currentuser) {
|
function getWatchStatus($watcheduser, $currentuser) {
|
||||||
// Returns true if the current user is watching the given user, and false otherwise.
|
// Returns true if the current user is watching the given user, and false otherwise.
|
||||||
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched AS W INNER JOIN '. $this->getTableName() .' AS U ON U.'. $this->getFieldName('primary') .' = W.watched WHERE U.'. $this->getFieldName('primary') .' = '. intval($watcheduser) .' AND W.uId = '. intval($currentuser);
|
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched AS W INNER JOIN '. $this->getTableName() .' AS U ON U.'. $this->getFieldName('primary') .' = W.watched WHERE U.'. $this->getFieldName('primary') .' = '. intval($watcheduser) .' AND W.uId = '. intval($currentuser);
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Api_OpenSearchTest extends TestBaseApi
|
||||||
1, count($arElements),
|
1, count($arElements),
|
||||||
'OpenSearch link in HTML is missing'
|
'OpenSearch link in HTML is missing'
|
||||||
);
|
);
|
||||||
$searchDescUrl = (string)$arElements[0]['href'];
|
$searchDescUrl = $this->completeUrl((string)$arElements[0]['href']);
|
||||||
$this->assertNotNull($searchDescUrl, 'Search description URL is empty');
|
$this->assertNotNull($searchDescUrl, 'Search description URL is empty');
|
||||||
|
|
||||||
$req = new HTTP_Request2($searchDescUrl);
|
$req = new HTTP_Request2($searchDescUrl);
|
||||||
|
|
|
@ -92,6 +92,23 @@ class TestBaseApi extends TestBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completes an URL that's missing the protocol.
|
||||||
|
* Useful when re-using URLs extracted from HTML
|
||||||
|
*
|
||||||
|
* @param string $url Potentially partial URL
|
||||||
|
*
|
||||||
|
* @return string Full URL
|
||||||
|
*/
|
||||||
|
protected function completeUrl($url)
|
||||||
|
{
|
||||||
|
if (substr($url, 0, 2) == '//') {
|
||||||
|
$url = 'http:' . $url;
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a user and a HTTP request object and prepares
|
* Creates a user and a HTTP request object and prepares
|
||||||
|
|
Loading…
Reference in a new issue