adding new openids in user profile works now
This commit is contained in:
parent
3afbf11087
commit
e1655f0e22
48
data/templates/default/editprofile-openid.tpl.php
Normal file
48
data/templates/default/editprofile-openid.tpl.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* User's own profile page: OpenID management
|
||||
*
|
||||
* @param array $openIds Array of OpenID association objects
|
||||
* @param string $formaction URL where to send the forms to
|
||||
* @param SemanticScuttle_Model_User_OpenId
|
||||
* $currentOpenId Current OpenID object (may be null)
|
||||
*/
|
||||
?>
|
||||
<h3><?php echo T_('OpenIDs'); ?></h3>
|
||||
<?php if (count($openIds)) { ?>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Options</th>
|
||||
<th><?php echo T_('OpenID URL'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($openIds as $openId) { ?>
|
||||
<tr <?php if ($openId->isCurrent()) { echo 'class="openid-current"'; } ?>>
|
||||
<td>
|
||||
<form method="post" action="<?php echo $formaction; ?>">
|
||||
<input type="hidden" name="openIdUrl" value="<?php echo htmlspecialchars($openId->url); ?>"/>
|
||||
<button type="submit" name="action" value="deleteOpenId">
|
||||
<?php echo T_('delete'); ?>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($openId->url); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php } else { ?>
|
||||
<p><?php echo T_('No OpenIDs registered'); ?></p>
|
||||
<?php } ?>
|
||||
|
||||
<p>
|
||||
<form method="post" action="<?php echo $formaction; ?>">
|
||||
<label for="openid"><?php echo T_('New OpenID'); ?></label>
|
||||
<input type="text" id="openid" name="openid_identifier" size="20" />
|
||||
<button type="submit" name="action" value="registerOpenId">
|
||||
<?php echo T_('Register'); ?>
|
||||
</button>
|
||||
</form>
|
||||
</p>
|
@ -59,6 +59,7 @@ $this->includeTemplate($GLOBALS['top_include']);
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php include 'editprofile-openid.tpl.php'; ?>
|
||||
<?php include 'editprofile-sslclientcerts.tpl.php'; ?>
|
||||
<h3><?php echo T_('Actions'); ?></h3>
|
||||
<table class="profile">
|
||||
|
60
src/SemanticScuttle/Model/OpenId.php
Normal file
60
src/SemanticScuttle/Model/OpenId.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* SemanticScuttle - your social bookmark manager.
|
||||
*
|
||||
* PHP version 5.
|
||||
*
|
||||
* @category Bookmarking
|
||||
* @package SemanticScuttle
|
||||
* @author Christian Weiske <cweiske@cweiske.de>
|
||||
* @license AGPL http://www.gnu.org/licenses/agpl.html
|
||||
* @link http://sourceforge.net/projects/semanticscuttle
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenID model. Represents one single OpenID association to a user.
|
||||
*
|
||||
* @category Bookmarking
|
||||
* @package SemanticScuttle
|
||||
* @author Christian Weiske <cweiske@cweiske.de>
|
||||
* @license AGPL http://www.gnu.org/licenses/agpl.html
|
||||
* @link http://sourceforge.net/projects/semanticscuttle
|
||||
*/
|
||||
class SemanticScuttle_Model_OpenId
|
||||
{
|
||||
public $id;
|
||||
public $uId;
|
||||
public $url;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates and returns a new object and fills it with
|
||||
* the passed values from the database.
|
||||
*
|
||||
* @param array $arOpenIdRow Database row array
|
||||
*
|
||||
* @return SemanticScuttle_Model_OpenId
|
||||
*/
|
||||
public static function fromDb($arOpenIdRow)
|
||||
{
|
||||
$openId = new self();
|
||||
foreach (get_object_vars($openId) as $variable => $dummy) {
|
||||
if (isset($arOpenIdRow[$variable])) {
|
||||
$openId->$variable = $arOpenIdRow[$variable];
|
||||
}
|
||||
}
|
||||
return $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this OpenID is the one the user is logged in with currently.
|
||||
*
|
||||
* @return boolean True if the User logged in with this OpenID
|
||||
*/
|
||||
public function isCurrent()
|
||||
{
|
||||
//FIXME
|
||||
return false;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
require_once 'SemanticScuttle/Exception/User.php';
|
||||
require_once 'SemanticScuttle/Model/OpenId.php';
|
||||
require_once 'OpenID.php';
|
||||
require_once 'OpenID/RelyingParty.php';
|
||||
require_once 'OpenID/Extension/SREG11.php';
|
||||
@ -25,7 +26,7 @@ require_once 'OpenID/Extension/SREG11.php';
|
||||
* @license AGPL http://www.gnu.org/licenses/agpl.html
|
||||
* @link http://sourceforge.net/projects/semanticscuttle
|
||||
*/
|
||||
class SemanticScuttle_Service_OpenID extends SemanticScuttle_DbService
|
||||
class SemanticScuttle_Service_OpenId extends SemanticScuttle_DbService
|
||||
{
|
||||
/**
|
||||
* Creates a new instance, sets database variable and table name.
|
||||
@ -43,7 +44,7 @@ class SemanticScuttle_Service_OpenID extends SemanticScuttle_DbService
|
||||
*
|
||||
* @param sql_db $db Database object
|
||||
*
|
||||
* @return SemanticScuttle_Service_OpenID
|
||||
* @return SemanticScuttle_Service_OpenId
|
||||
*/
|
||||
public static function getInstance($db)
|
||||
{
|
||||
@ -208,5 +209,119 @@ class SemanticScuttle_Service_OpenID extends SemanticScuttle_DbService
|
||||
}
|
||||
return $row['uId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an OpenID to a given user
|
||||
*
|
||||
* @param integer $uId User ID to attach the OpenID to
|
||||
* @param string $identifier OpenID identifier (URL)
|
||||
* @param string $email OpenID-delivered e-mail address of the user
|
||||
*
|
||||
* @return boolean True if it worked, false if not
|
||||
*/
|
||||
public function register($uId, $identifier, $email = null)
|
||||
{
|
||||
//FIXME: use email when google-openid
|
||||
$query = 'INSERT INTO ' . $this->getTableName()
|
||||
. ' ' . $this->db->sql_build_array(
|
||||
'INSERT', array(
|
||||
'uId' => $uId,
|
||||
'url' => $identifier,
|
||||
)
|
||||
);
|
||||
if (!($dbresult = $this->db->sql_query($query))) {
|
||||
message_die(
|
||||
GENERAL_ERROR, 'Could not register OpenID',
|
||||
'', __LINE__, __FILE__, $query, $this->db
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the OpenID with the given numeric database ID
|
||||
*
|
||||
* @param integer $id Numeric ID from database
|
||||
*
|
||||
* @return boolean True if it worked, false if not
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if ($id instanceof SemanticScuttle_Model_OpenId) {
|
||||
$id = $id->id;
|
||||
}
|
||||
$id = (int)$id;
|
||||
|
||||
$query = 'DELETE FROM ' . $this->getTableName()
|
||||
.' WHERE id = ' . $id;
|
||||
|
||||
if (!($dbresult = $this->db->sql_query($query))) {
|
||||
message_die(
|
||||
GENERAL_ERROR, 'Could not delete OpenID',
|
||||
'', __LINE__, __FILE__, $query, $this->db
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an OpenID object from the given identifiert
|
||||
*
|
||||
* @param string $identifier OpenID identifier (URL)
|
||||
*
|
||||
* @return SemanticScuttle_Model_OpenId OpenID object or NULL if not found
|
||||
*/
|
||||
public function getId($identifier)
|
||||
{
|
||||
$query = 'SELECT * FROM ' . $this->getTableName()
|
||||
. ' WHERE url = "' . $this->db->sql_escape($identifier) . '"';
|
||||
if (!($dbresult = $this->db->sql_query($query))) {
|
||||
message_die(
|
||||
GENERAL_ERROR, 'Could not load OpenID',
|
||||
'', __LINE__, __FILE__, $query, $this->db
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($row = $this->db->sql_fetchrow($dbresult)) {
|
||||
$cert = SemanticScuttle_Model_OpenId::fromDb($row);
|
||||
} else {
|
||||
$cert = null;
|
||||
}
|
||||
$this->db->sql_freeresult($dbresult);
|
||||
return $cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all OpenIDs the given user has attached
|
||||
*
|
||||
* @param integer $uId User ID to fetch registered OpenIDs for
|
||||
*
|
||||
* @return array Array of SemanticScuttle_Model_OpenId objects
|
||||
*/
|
||||
public function getIds($uId)
|
||||
{
|
||||
$query = 'SELECT * FROM ' . $this->getTableName()
|
||||
. ' WHERE uId = ' . (int)$uId
|
||||
. ' ORDER BY url ASC';
|
||||
if (!($dbresult = $this->db->sql_query($query))) {
|
||||
message_die(
|
||||
GENERAL_ERROR, 'Could not load OpenIDs',
|
||||
'', __LINE__, __FILE__, $query, $this->db
|
||||
);
|
||||
return array();
|
||||
}
|
||||
|
||||
$certs = array();
|
||||
while ($row = $this->db->sql_fetchrow($dbresult)) {
|
||||
$certs[] = SemanticScuttle_Model_OpenId::fromDb($row);
|
||||
}
|
||||
$this->db->sql_freeresult($dbresult);
|
||||
return $certs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -42,7 +42,8 @@ isset($_SESSION['token']) ? define('SESSION_TOKEN', $_SESSION['token']): define(
|
||||
isset($_SESSION['token_stamp']) ? define('SESSION_TOKENSTAMP', $_SESSION['token_stamp']): define('SESSION_TOKENSTAMP', '');
|
||||
|
||||
|
||||
@list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
|
||||
@list($url, $user, $method) = isset($_SERVER['PATH_INFO'])
|
||||
? explode('/', $_SERVER['PATH_INFO']) : NULL;
|
||||
|
||||
if (!$user) {
|
||||
$tplVars['error'] = T_('Username was not specified');
|
||||
@ -169,6 +170,53 @@ if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) {
|
||||
}
|
||||
}
|
||||
|
||||
$oids = SemanticScuttle_Service_Factory::get('OpenId');
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'deleteOpenId'
|
||||
&& isset($_POST['openIdUrl'])
|
||||
) {
|
||||
$identifier = $_POST['openIdUrl'];
|
||||
$openId = $oids->getId($identifier);
|
||||
if ($openId === null || $openId->uId != $currentUser->getId()
|
||||
) {
|
||||
$tplVars['error'] = T_('OpenID not found.');
|
||||
} else if (false === $oids->delete($openId->id)) {
|
||||
$tplVars['error'] = T_('Failed to delete OpenID.');
|
||||
} else {
|
||||
$tplVars['msg'] = T_('OpenID deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
$openIdAction = false;
|
||||
$openIdReturn = false;
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'registerOpenId'
|
||||
&& isset($_POST['openid_identifier'])
|
||||
) {
|
||||
$openIdAction = true;
|
||||
} else if (isset($method) && $method == 'openidreturn') {
|
||||
$openIdAction = true;
|
||||
$openIdReturn = true;
|
||||
}
|
||||
if ($openIdAction) {
|
||||
$returnUrl = addProtocolToUrl(createURL('profile', $user . '/openidreturn'));
|
||||
|
||||
try {
|
||||
if (!$openIdReturn) {
|
||||
//part 1 of OpenID registration
|
||||
$oids->sendIdRequest($_POST['openid_identifier'], $returnUrl);
|
||||
} else {
|
||||
//part 2
|
||||
$ret = $oids->handleIdResponse($returnUrl);
|
||||
$oids->register(
|
||||
$currentUser->getId(), $ret['identifier'], $ret['email']
|
||||
);
|
||||
$tplVars['msg'] = T_('OpenID registered.');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$tplVars['error'] = SemanticScuttle_Exception::getErrorMessage($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Token Init
|
||||
$_SESSION['token'] = md5(uniqid(rand(), true));
|
||||
$_SESSION['token_stamp'] = time();
|
||||
@ -179,6 +227,7 @@ if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) {
|
||||
$tplVars['token'] = $_SESSION['token'];
|
||||
|
||||
$tplVars['sslClientCerts'] = $scert->getUserCerts($currentUser->getId());
|
||||
$tplVars['openIds'] = $oids->getIds($currentUser->getId());
|
||||
$tplVars['currentCert'] = null;
|
||||
if ($scert->hasValidCert()) {
|
||||
$tplVars['currentCert'] = SemanticScuttle_Model_User_SslClientCert::fromCurrentCert();
|
||||
|
Loading…
Reference in New Issue
Block a user