"; openid_help(); exit;}
// error_reporting(E_ALL);
function openid() {
global $openid_options, $bb_current_user, $bbdb;
openid_remove(); // check for request to remove session or attached account
if (bb_get_location()=="register-page") {
if (!empty($_POST) && function_exists('instant_password')) { // means we are on register page and instant password is running - need password
if (empty($_POST['password']) || empty($_POST['pass2'])) {
$length=rand(12,16); $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$password = ''; for ( $i = 0; $i < $length; $i++ ) {$password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);}
$_POST['password']=$_POST['pass2']=$password;
}
}
// openid_session();
}
if (isset($_POST['openid_url'])) {$openid_url=$_POST['openid_url'];}
elseif (isset($_GET['openid_url'])) {$openid_url=$_GET['openid_url'];}
if (!empty($openid_url)){
// helpers for the services that don't recognize partial words
if (preg_match("/^(https?\:\/\/)?google(\.com)?\/?/simU",$openid_url)) {$openid_url="google.com/accounts/o8/id";}
// elseif (preg_match("/^(https?\:\/\/)?aol(\.com)?\/?/simU",$openid_url)) {$openid_url="openid.aol.com";}
@require_once('class.openid.php');
$openid = new OpenIDService;
$openid->SetIdentity($openid_url);
$openid->SetTrustRoot($openid_options['root']);
$openid->SetRequiredFields(array('email'));
// $openid->SetOptionalFields(array('fullname','dob','gender','postcode','country','language','timezone'));
if ($openid->GetOpenIDServer()){
$openid_approve="http://".$_SERVER['HTTP_HOST'].remove_query_arg('openid_url'); // add_query_arg( 're',urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].(empty($_SERVER["QUERY_STRING"]) ? "" : '?'.$_SERVER["QUERY_STRING"])));
$openid->SetApprovedURL($openid_approve);
$openid->Redirect(); // This will redirect user to OpenID Server
exit;
}else{
$error = $openid->GetError();
$error ="ERROR CODE: " . $error['code'] . "
".
"ERROR DESCRIPTION: " . $error['description'] . "
";
openid_redirect($error);
}
}
elseif (isset($_GET['openid_mode'])) {
if ($_GET['openid_mode'] == 'cancel') {openid_redirect(__("USER CANCELED REQUEST"));}
elseif ($_GET['openid_mode'] != 'id_res') {openid_redirect(__("INVALID OPENID REQUEST"));}
@require_once('class.openid.php');
$openid = new OpenIDService;
$openid->SetIdentity($_GET['openid_identity']);
$openid_result = $openid->ValidateWithServer();
if ($openid->IsError() == true) {
$error = $openid->GetError();
$error="ERROR CODE: " . $error['code'] . "
".
"ERROR DESCRIPTION: " . $error['description'] . "
";
openid_redirect($error);
}
elseif (empty($openid_result)===true || empty($_GET['openid_identity'])===true) {openid_redirect(__("INVALID AUTHORIZATION"));}
else { // valid result
$openid=addslashes(substr($_GET['openid_identity'],0,256)); // openid_assoc_handle
$openid_user_id=$bbdb->get_var("SELECT user_id FROM $bbdb->usermeta WHERE meta_key='openid' AND meta_value LIKE '%:\"$openid\";%' LIMIT 1");
if (!$bb_current_user) {
if ($openid_user_id) { // we found a user, give them a cookie
if ($openid_options['debug']) {bb_update_usermeta($openid_user_id,'openid_debug',$_GET);}
wp_set_auth_cookie( (int) $openid_user_id, 0 ); // 0 = don't remember, short login, todo: use form value
do_action('bb_user_login', (int) $openid_user_id );
openid_redirect();
} else { // openid is valid but no user_id, we need to create a user
// $error="Sorry, account creation is not supported yet.
The following OpenID is not attached to any forum account:
$openid";
// openid_redirect($error);
openid_session();
$_SESSION['OPENID']=$_GET['openid_identity'];
bb_safe_redirect(bb_get_option('uri')."register.php");
}
}
elseif (!empty($bb_current_user->ID) && bb_get_location()=="profile-page" && isset($_GET['tab']) && $_GET['tab']=="edit") {
if (!$openid_user_id) { // no one owns this ID
$user = bb_get_user($bb_current_user->ID);
(array) $user->openid[]=$openid;
bb_update_usermeta($bb_current_user->ID,'openid',(array) $user->openid);
openid_redirect();
} else {
if ($openid_user_id==$bb_current_user->ID) {openid_redirect(__("THIS PROVIDER IS ALREADY ON YOUR ACCOUNT"));}
else {openid_redirect(__("THIS PROVIDER IS OWNED BY ANOTHER ACCOUNT"));}
}
}
} // valid result
} // openid_mode
}
function openid_session() {
if (!isset($_SESSION)) {
@ini_set('session.use_trans_sid', false);
@ini_set("url_rewriter.tags","");
@session_start(); // sent with headers
}
}
function openid_register_success($user_id=0) {
if (!$user_id) {return;}
openid_session();
if (empty($_SESSION['OPENID'])) {return;}
else {$openid[]=$_SESSION['OPENID']; $_SESSION['OPENID']=""; unset($_SESSION['OPENID']);}
global $bbdb;
$bbdb->query("UPDATE $bbdb->users SET user_status=0 WHERE ID=$user_id LIMIT 1"); // 0.9 has a typo bug in update_user_status function
bb_update_usermeta($user_id,'openid',$openid);
wp_set_auth_cookie( (int) $user_id, 0 );
do_action('bb_user_login', (int) $user_id );
if (isset($_REQUEST['re'])) {$re=$_REQUEST['re'];} else {$re=bb_get_option('uri');}
bb_safe_redirect($re);
}
function openid_profile_edit() {
global $bbdb,$user_id,$openid_options;
if (!bb_get_location()=="register-page") {echo '';}
echo '