openid cleanup

This commit is contained in:
friendica 2015-03-16 17:08:50 -07:00
parent ccf4734f7b
commit 178b768e3c
3 changed files with 73 additions and 105 deletions

View File

@ -736,7 +736,7 @@ function contact_block() {
if((! is_array($a->profile)) || ($a->profile['hide_friends'])) if((! is_array($a->profile)) || ($a->profile['hide_friends']))
return $o; return $o;
$r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and not ( abook_flags & %d )>0 and not (xchan_flags & %d)>0", $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0",
intval($a->profile['uid']), intval($a->profile['uid']),
intval($abook_flags), intval($abook_flags),
intval($xchan_flags) intval($xchan_flags)
@ -748,12 +748,10 @@ function contact_block() {
$contacts = t('No connections'); $contacts = t('No connections');
$micropro = null; $micropro = null;
} else { } else {
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$randfunc = 'RANDOM()'; $randfunc = db_getfunc('RAND');
} else {
$randfunc = 'RAND()'; $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0 ORDER BY $randfunc LIMIT %d",
}
$r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND not ( abook_flags & %d)>0 and not (xchan_flags & %d )>0 ORDER BY $randfunc LIMIT %d",
intval($a->profile['uid']), intval($a->profile['uid']),
intval($abook_flags|ABOOK_FLAG_ARCHIVED), intval($abook_flags|ABOOK_FLAG_ARCHIVED),
intval($xchan_flags), intval($xchan_flags),

View File

@ -39,7 +39,7 @@ function channel_init(&$a) {
// Not yet ready for prime time // Not yet ready for prime time
// $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->get_baseurl() . '/id/' . $which .'?f=" />' . "\r\n" ; // $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->get_baseurl() . '/id/' . $which .'?f=" />' . "\r\n" ;
// $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $a->get_baseurl() . '/id/' . $which .'" />' . "\r\n" ; // $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $a->get_baseurl() . '/channel/' . $which .'" />' . "\r\n" ;
// Run profile_load() here to make sure the theme is set before // Run profile_load() here to make sure the theme is set before
// we start loading content // we start loading content

View File

@ -1,5 +1,37 @@
<?php <?php
require 'library/openid/provider/provider.php';
$attrMap = array(
'namePerson/first' => t('First Name'),
'namePerson/last' => t('Last Name'),
'namePerson/friendly' => t('Nickname'),
'namePerson' => t('Full Name'),
'contact/internet/email' => t('Email'),
'contact/email' => t('Email'),
'media/image/aspect11' => t('Profile Photo'),
'media/image' => t('Profile Photo'),
'media/image/default' => t('Profile Photo'),
'media/image/16x16' => t('Profile Photo 16px'),
'media/image/32x32' => t('Profile Photo 32px'),
'media/image/48x48' => t('Profile Photo 48px'),
'media/image/64x64' => t('Profile Photo 64px'),
'media/image/80x80' => t('Profile Photo 80px'),
'media/image/128x128' => t('Profile Photo 128px'),
'timezone' => t('Timezone'),
'contact/web/default' => t('Homepage URL'),
'language/pref' => t('Language'),
'birthDate/birthYear' => t('Birth Year'),
'birthDate/birthMonth' => t('Birth Month'),
'birthDate/birthday' => t('Birth Day'),
'birthDate' => t('Birthdate'),
'gender' => t('Gender'),
);
function id_init(&$a) { function id_init(&$a) {
logger('id: ' . print_r($_REQUEST,true)); logger('id: ' . print_r($_REQUEST,true));
@ -17,11 +49,14 @@ function id_init(&$a) {
profile_load($a,$which,$profile); profile_load($a,$which,$profile);
require 'library/openid/provider/provider.php';
$op = new MysqlProvider;
$op->server();
}
function getUserData($handle=null) function getUserData($handle=null) {
{
if(! local_channel()) { if(! local_channel()) {
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
get_app()->page['content'] = login(); get_app()->page['content'] = login();
@ -54,9 +89,6 @@ function getUserData($handle=null)
intval($r[0]['channel_account_id']) intval($r[0]['channel_account_id'])
); );
$gender = ''; $gender = '';
if($p[0]['gender'] == t('Male')) if($p[0]['gender'] == t('Male'))
$gender = 'M'; $gender = 'M';
@ -85,100 +117,43 @@ function getUserData($handle=null)
return $r[0]; return $r[0];
/* /*
if(isset($_POST['login'],$_POST['password'])) { * if(isset($_POST['login'],$_POST['password'])) {
$login = mysql_real_escape_string($_POST['login']); * $login = mysql_real_escape_string($_POST['login']);
$password = sha1($_POST['password']); * $password = sha1($_POST['password']);
$q = mysql_query("SELECT * FROM Users WHERE login = '$login' AND password = '$password'"); * $q = mysql_query("SELECT * FROM Users WHERE login = '$login' AND password = '$password'");
if($data = mysql_fetch_assoc($q)) { * if($data = mysql_fetch_assoc($q)) {
return $data; * return $data;
} * }
if($handle) { * if($handle) {
echo 'Wrong login/password.'; * echo 'Wrong login/password.';
} * }
} * }
if($handle) { * if($handle) {
?> * ?>
<form action="" method="post"> * <form action="" method="post">
<input type="hidden" name="openid.assoc_handle" value="<?php echo $handle?>"> * <input type="hidden" name="openid.assoc_handle" value="<?php echo $handle?>">
Login: <input type="text" name="login"><br> * Login: <input type="text" name="login"><br>
Password: <input type="password" name="password"><br> * Password: <input type="password" name="password"><br>
<button>Submit</button> * <button>Submit</button>
</form> * </form>
<?php * <?php
die(); * die();
} * }
*/ */
} }
function translate_regs() {
// This exists to get around scoping rules
$attrMap = array(
'namePerson/first' => t('First Name'),
'namePerson/last' => t('Last Name'),
'namePerson/friendly' => t('Nickname'),
'namePerson' => t('Full Name'),
'contact/internet/email' => t('Email'),
'contact/email' => t('Email'),
'media/image/aspect11' => t('Profile Photo'),
'media/image' => t('Profile Photo'),
'media/image/default' => t('Profile Photo'),
'media/image/16x16' => t('Profile Photo 16px'),
'media/image/32x32' => t('Profile Photo 32px'),
'media/image/48x48' => t('Profile Photo 48px'),
'media/image/64x64' => t('Profile Photo 64px'),
'media/image/80x80' => t('Profile Photo 80px'),
'media/image/128x128' => t('Profile Photo 128px'),
'timezone' => t('Timezone'),
'contact/web/default' => t('Homepage URL'),
'language/pref' => t('Language'),
'birthDate/birthYear' => t('Birth Year'),
'birthDate/birthMonth' => t('Birth Month'),
'birthDate/birthday' => t('Birth Day'),
'birthDate' => t('Birthdate'),
'gender' => t('Gender'),
);
return $attrMap;
}
class MysqlProvider extends LightOpenIDProvider class MysqlProvider extends LightOpenIDProvider
{ {
// See http://openid.net/specs/openid-attribute-properties-list-1_0-01.html // See http://openid.net/specs/openid-attribute-properties-list-1_0-01.html
// This list contains a few variations of these attributes to maintain // This list contains a few variations of these attributes to maintain
// compatibility with legacy clients // compatibility with legacy clients
private $attrMap = array(
'namePerson/first' => 'First Name',
'namePerson/last' => 'Last Name',
'namePerson/friendly' => 'Nickname',
'namePerson' => 'Full Name',
'contact/internet/email' => 'Email',
'contact/email' => 'Email',
'media/image/aspect11' => 'Profile Photo',
'media/image' => 'Profile Photo',
'media/image/default' => 'Profile Photo',
'media/image/16x16' => 'Profile Photo 16px',
'media/image/32x32' => 'Profile Photo 32px',
'media/image/48x48' => 'Profile Photo 48px',
'media/image/64x64' => 'Profile Photo 64px',
'media/image/80x80' => 'Profile Photo 80px',
'media/image/128x128' => 'Profile Photo 128px',
'timezone' => 'Timezone',
'contact/web/default' => 'Homepage URL',
'language/pref' => 'Language',
'birthDate/birthYear' => 'Birth Year',
'birthDate/birthMonth' => 'Birth Month',
'birthDate/birthday' => 'Birth Day',
'birthDate' => 'Birthdate',
'gender' => 'Gender',
);
private $attrFieldMap = array( private $attrFieldMap = array(
'namePerson/first' => 'firstName', 'namePerson/first' => 'firstName',
'namePerson/last' => 'lastName', 'namePerson/last' => 'lastName',
@ -208,6 +183,7 @@ class MysqlProvider extends LightOpenIDProvider
function setup($identity, $realm, $assoc_handle, $attributes) function setup($identity, $realm, $assoc_handle, $attributes)
{ {
global $attrMap;
// logger('identity: ' . $identity); // logger('identity: ' . $identity);
// logger('realm: ' . $realm); // logger('realm: ' . $realm);
@ -216,6 +192,9 @@ class MysqlProvider extends LightOpenIDProvider
$data = getUserData($assoc_handle); $data = getUserData($assoc_handle);
// FIXME this needs to be a template with localised strings
$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 . '">'
. '<input type="hidden" name="login" value="' . $_POST['login'] .'">' . '<input type="hidden" name="login" value="' . $_POST['login'] .'">'
@ -269,10 +248,6 @@ class MysqlProvider extends LightOpenIDProvider
return false; return false;
} }
logger('checkid: checkpoint1');
$q = get_pconfig(local_channel(),'openid',$realm); $q = get_pconfig(local_channel(),'openid',$realm);
$attrs = array(); $attrs = array();
@ -300,9 +275,9 @@ class MysqlProvider extends LightOpenIDProvider
function assoc_handle() function assoc_handle()
{ {
logger('assoc_handle');
$channel = get_app()->get_channel(); $channel = get_app()->get_channel();
return z_root() . '/id/' . $channel['channel_address']; return z_root() . '/channel/' . $channel['channel_address'];
} }
@ -312,7 +287,6 @@ class MysqlProvider extends LightOpenIDProvider
$channel = channelx_by_nick(basename($handle)); $channel = channelx_by_nick(basename($handle));
if($channel) if($channel)
set_pconfig($channel['channel_id'],'openid','associate',$data); set_pconfig($channel['channel_id'],'openid','associate',$data);
} }
function getAssoc($handle) function getAssoc($handle)
@ -334,10 +308,6 @@ class MysqlProvider extends LightOpenIDProvider
} }
} }
$op = new MysqlProvider;
$op->server();
}