openid stuff

This commit is contained in:
friendica 2015-03-11 21:49:29 -07:00
parent 64ae17aa6a
commit 76fedfe1f8
2 changed files with 50 additions and 36 deletions

View File

@ -51,9 +51,10 @@ function getUserData($handle=null)
get_app()->page['content'] = login(); get_app()->page['content'] = login();
} }
logger('handle: ' . $handle);
if($handle) { if($handle) {
$r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1",
dbesc($handle) dbesc($handle)
); );
} }
@ -63,7 +64,7 @@ function getUserData($handle=null)
); );
} }
return $r; return $r[0];
/* /*
if(isset($_POST['login'],$_POST['password'])) { if(isset($_POST['login'],$_POST['password'])) {
@ -108,6 +109,12 @@ class MysqlProvider extends LightOpenIDProvider
function setup($identity, $realm, $assoc_handle, $attributes) function setup($identity, $realm, $assoc_handle, $attributes)
{ {
logger('identity: ' . $identity);
logger('realm: ' . $realm);
logger('assoc_handle: ' . $assoc_handle);
logger('attributes: ' . print_r($attributes,true));
$data = getUserData($assoc_handle); $data = getUserData($assoc_handle);
$o .= '<form action="" method="post">' $o .= '<form action="" method="post">'
. '<input type="hidden" name="openid.assoc_handle" value="' . $assoc_handle . '">' . '<input type="hidden" name="openid.assoc_handle" value="' . $assoc_handle . '">'
@ -141,34 +148,42 @@ class MysqlProvider extends LightOpenIDProvider
. '<button name="cancel">cancel</button> ' . '<button name="cancel">cancel</button> '
. '</form>'; . '</form>';
get_app()->page['content'] = $o; get_app()->page['content'] .= $o;
} }
function checkid($realm, &$attributes) function checkid($realm, &$attributes)
{ {
logger('checkid: ' . $realm);
logger('checkid attrs: ' . print_r($attributes,true));
if(isset($_POST['cancel'])) { if(isset($_POST['cancel'])) {
$this->cancel(); $this->cancel();
} }
$data = getUserData(); $data = getUserData();
if(!$data) { if(! $data) {
return false; return false;
} }
$realm = mysql_real_escape_string($realm);
$q = mysql_query("SELECT attributes FROM AllowedSites WHERE user = '{$data['id']}' AND realm = '$realm'"); logger('checkid: checkpoint1');
$attrs = array();
if($attrs = mysql_fetch_row($q)) { $q = get_pconfig(local_channel(),'openid',$realm);
$attrs = explode(',', $attributes[0]);
$attrs = array();
if($q) {
$attrs = $q;
} elseif(isset($_POST['attributes'])) { } elseif(isset($_POST['attributes'])) {
$attrs = array_keys($_POST['attributes']); $attrs = array_keys($_POST['attributes']);
} elseif(!isset($_POST['once']) && !isset($_POST['always'])) { } elseif(!isset($_POST['once']) && !isset($_POST['always'])) {
return false; return false;
} }
$attributes = array(); $attributes = array();
foreach($attrs as $attr) { foreach($attrs as $attr) {
if(isset($this->attrFieldMap[$attr])) { if(isset($this->attrFieldMap[$attr])) {
@ -177,46 +192,45 @@ class MysqlProvider extends LightOpenIDProvider
} }
if(isset($_POST['always'])) { if(isset($_POST['always'])) {
$attrs = mysql_real_escape_string(implode(',', array_keys($attributes))); set_pconfig(local_channel(),'openid',$realm,array_keys($attributes));
mysql_query("REPLACE INTO AllowedSites VALUES('{$data['id']}', '$realm', '$attrs')");
} }
return $this->serverLocation . '?' . $data['login']; return z_root() . '/id/' . $data['channel_address'];
} }
function assoc_handle() function assoc_handle()
{ {
# We generate an integer assoc handle, because it's just faster to look up an integer later.
$q = mysql_query("SELECT MAX(id) FROM Associations"); $channel = get_app()->get_channel();
$result = mysql_fetch_row($q); return z_root() . '/id/' . $channel['channel_address'];
return $q[0]+1;
} }
function setAssoc($handle, $data) function setAssoc($handle, $data)
{ {
$data = mysql_real_escape_string(serialize($data)); logger('setAssoc');
mysql_query("REPLACE INTO Associations VALUES('$handle', '$data')"); $channel = channelx_by_nick(basename($handle));
if($channel)
set_pconfig($channel['channel_id'],'openid','associate',$data);
} }
function getAssoc($handle) function getAssoc($handle)
{ {
if(!is_numeric($handle)) { logger('getAssoc: ' . $handle);
return false;
} $channel = channelx_by_nick(basename($handle));
$q = mysql_query("SELECT data FROM Associations WHERE id = '$handle'"); if($channel)
$data = mysql_fetch_row($q); return get_pconfig($channel['channel_id'],'openid','associate');
if(!$data) { return false;
return false;
}
return unserialize($data[0]);
} }
function delAssoc($handle) function delAssoc($handle)
{ {
if(!is_numeric($handle)) { logger('delAssoc');
return false; $channel = channelx_by_nick(basename($handle));
} if($channel)
mysql_query("DELETE FROM Associations WHERE id = '$handle'"); return del_pconfig($channel['channel_id'],'openid','associate');
} }
} }

View File

@ -85,7 +85,7 @@ function openid_content(&$a) {
$url = trim($_REQUEST['openid_identity'],'/'); $url = trim($_REQUEST['openid_identity'],'/');
if(strpos($url,'http') === false) if(strpos($url,'http') === false)
$url = 'https://' . $url; $url = 'https://' . $url;
$pphoto = get_default_profile_photo(); $pphoto = z_root() . '/' . get_default_profile_photo();
$parsed = @parse_url($url); $parsed = @parse_url($url);
if($parsed) { if($parsed) {
$host = $parsed['host']; $host = $parsed['host'];