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']))
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($abook_flags),
intval($xchan_flags)
@ -748,12 +748,10 @@ function contact_block() {
$contacts = t('No connections');
$micropro = null;
} else {
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$randfunc = 'RANDOM()';
} 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 not ( abook_flags & %d)>0 and not (xchan_flags & %d )>0 ORDER BY $randfunc LIMIT %d",
$randfunc = db_getfunc('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",
intval($a->profile['uid']),
intval($abook_flags|ABOOK_FLAG_ARCHIVED),
intval($xchan_flags),

View File

@ -39,7 +39,7 @@ function channel_init(&$a) {
// 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.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
// we start loading content

View File

@ -1,5 +1,37 @@
<?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) {
logger('id: ' . print_r($_REQUEST,true));
@ -17,11 +49,14 @@ function id_init(&$a) {
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()) {
notice( t('Permission denied.') . EOL);
get_app()->page['content'] = login();
@ -54,9 +89,6 @@ function getUserData($handle=null)
intval($r[0]['channel_account_id'])
);
$gender = '';
if($p[0]['gender'] == t('Male'))
$gender = 'M';
@ -85,100 +117,43 @@ function getUserData($handle=null)
return $r[0];
/*
if(isset($_POST['login'],$_POST['password'])) {
$login = mysql_real_escape_string($_POST['login']);
$password = sha1($_POST['password']);
$q = mysql_query("SELECT * FROM Users WHERE login = '$login' AND password = '$password'");
if($data = mysql_fetch_assoc($q)) {
return $data;
}
if($handle) {
echo 'Wrong login/password.';
}
}
if($handle) {
?>
<form action="" method="post">
<input type="hidden" name="openid.assoc_handle" value="<?php echo $handle?>">
Login: <input type="text" name="login"><br>
Password: <input type="password" name="password"><br>
<button>Submit</button>
</form>
<?php
die();
}
* if(isset($_POST['login'],$_POST['password'])) {
* $login = mysql_real_escape_string($_POST['login']);
* $password = sha1($_POST['password']);
* $q = mysql_query("SELECT * FROM Users WHERE login = '$login' AND password = '$password'");
* if($data = mysql_fetch_assoc($q)) {
* return $data;
* }
* if($handle) {
* echo 'Wrong login/password.';
* }
* }
* if($handle) {
* ?>
* <form action="" method="post">
* <input type="hidden" name="openid.assoc_handle" value="<?php echo $handle?>">
* Login: <input type="text" name="login"><br>
* Password: <input type="password" name="password"><br>
* <button>Submit</button>
* </form>
* <?php
* 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
{
// See http://openid.net/specs/openid-attribute-properties-list-1_0-01.html
// This list contains a few variations of these attributes to maintain
// 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(
'namePerson/first' => 'firstName',
'namePerson/last' => 'lastName',
@ -208,6 +183,7 @@ class MysqlProvider extends LightOpenIDProvider
function setup($identity, $realm, $assoc_handle, $attributes)
{
global $attrMap;
// logger('identity: ' . $identity);
// logger('realm: ' . $realm);
@ -216,6 +192,9 @@ class MysqlProvider extends LightOpenIDProvider
$data = getUserData($assoc_handle);
// FIXME this needs to be a template with localised strings
$o .= '<form action="" method="post">'
. '<input type="hidden" name="openid.assoc_handle" value="' . $assoc_handle . '">'
. '<input type="hidden" name="login" value="' . $_POST['login'] .'">'
@ -269,10 +248,6 @@ class MysqlProvider extends LightOpenIDProvider
return false;
}
logger('checkid: checkpoint1');
$q = get_pconfig(local_channel(),'openid',$realm);
$attrs = array();
@ -300,9 +275,9 @@ class MysqlProvider extends LightOpenIDProvider
function assoc_handle()
{
logger('assoc_handle');
$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));
if($channel)
set_pconfig($channel['channel_id'],'openid','associate',$data);
}
function getAssoc($handle)
@ -334,10 +308,6 @@ class MysqlProvider extends LightOpenIDProvider
}
}
$op = new MysqlProvider;
$op->server();
}