path . 'register.php') {
bb_die(__('Registration is disabled for this forum, please login using your HTTP username and password.'));
}
}
function http_disable_http_password_recovery() {
global $HTTP_enabled, $bb;
if ($HTTP_enabled && $_SERVER['PHP_SELF'] == $bb->path . 'bb-reset-password.php') {
$user_login = user_sanitize($_POST['user_login']);
if (!empty($user_login)) {
$user = bb_get_user_by_name($user_login);
if (substr($user->user_pass, 0, 5) == '^HTTP') {
bb_die(__('Password recovery is not possible for this account because it uses an HTTP username and password to login. To change your HTTP password, please contact your system administrator.'));
}
}
}
}
function http_disable_password_editing() {
global $HTTP_enabled, $bb, $bb_current_user;
if ($HTTP_enabled && (($_SERVER['PHP_SELF'] == $bb->path . 'profile.php' && $_GET['tab'] == 'edit') || $_SERVER['PHP_SELF'] == $bb->path . 'profile-edit.php')) {
add_filter( 'bb_user_has_cap' , 'http_remove_password_capability' , 10, 2);
}
}
function http_remove_password_capability($allcaps, $caps) {
global $user;
if ($caps[0] == 'change_password' && substr($user->user_pass, 0, 5) == '^HTTP') {
unset($allcaps['change_password']);
}
return $allcaps;
}
function bb_check_login($user = null, $pass = null, $already_md5 = false) {
global $bbdb;
if (!$user) {
$user = $_SERVER['PHP_AUTH_USER'];
}
if (!$pass) {
$pass = $_SERVER['PHP_AUTH_PW'];
}
$user = user_sanitize( $user );
if ( !$already_md5 ) {
$user_exists = bb_user_exists( $user );
if ( !$user_exists ) {
// Check using HTTP
if ( !bb_get_option('HTTP_disable_automatic_registration') ) {
// Create the new user in the local database
if ( $user_id = http_new_user( $user, $pass ) ) {
return $bbdb->get_row("SELECT * FROM $bbdb->users WHERE `ID` = $user_id");
} else {
bb_die(__('Failed to add new HTTP user to local database.'));
}
} else {
return FALSE;
}
} else {
if ( substr($user_exists->user_pass, 0, 5) == '^HTTP' ) {
$bbdb->query("UPDATE $bbdb->users SET user_pass = '^HTTP-" . md5($pass) . "' WHERE user_login = '$user'");
// Get their record from the local database
return $bbdb->get_row("SELECT * FROM $bbdb->users WHERE user_login = '$user' AND SUBSTRING(SUBSTRING_INDEX( user_pass, '---', 1 ), 1, 5) = '^HTTP'");
} else {
$pass = user_sanitize( md5( $pass ) );
return $bbdb->get_row("SELECT * FROM $bbdb->users WHERE user_login = '$user' AND SUBSTRING_INDEX( user_pass, '---', 1 ) = '$pass'");
}
}
} else {
return $bbdb->get_row("SELECT * FROM $bbdb->users WHERE user_login = '$user' AND MD5( user_pass ) = '$pass'");
}
}
function http_new_user($user_login, $user_pass) {
global $bbdb, $bb_table_prefix;
$now = bb_current_time('mysql');
$password = '^HTTP-' . md5($user_pass);
$bbdb->query("INSERT INTO $bbdb->users (user_login, user_pass, user_registered) VALUES ('$user_login', '$password', '$now')");
$user_id = $bbdb->insert_id;
bb_update_usermeta( $user_id, $bb_table_prefix . 'capabilities', array('member' => true) );
do_action('http_new_user', $user_id);
return $user_id;
}
function http_login_init() {
return bb_login(null, null);
}
add_action( 'bb_got_roles', 'http_login_init' );
}
?>