Plugin Directory

Changeset 165536


Ignore:
Timestamp:
10/21/2009 07:22:30 PM (16 years ago)
Author:
onigoetz
Message:

Committing 0.5 to trunk

Sync Enabled

Location:
phpbb-single-sign-on/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • phpbb-single-sign-on/trunk/connect-phpbb.php

    r163762 r165536  
    22/*
    33Plugin Name: PHPBB Single Sign On
    4 Version: 0.4.6
     4Version: 0.5
    55Plugin URI: http://www.onigoetz.ch/plugins/wordpress-phpbb-plugin/
    66Description: Connecte un site wordpress à PHPBB
     
    5050add_action('wp_authenticate_user','op_login',10,2);
    5151function op_login(&$userdata,$password){
    52 
    53     global $op_credentials;
    54     $op_credentials = array('username'=>strtolower($userdata->user_login),'password'=>$password); // Set credentials
    5552   
    5653    if(file_exists(ABSPATH.'/'.PHPBBPATH.'config.php')){ // check to see if phpBB exists
     
    5956        }
    6057        op_phpBB3::getIdentity();
    61         $result = op_phpBB3::login();
     58        $result = op_phpBB3::login(strtolower($userdata->user_login),$password);
    6259    }
    6360   
     
    9693}
    9794
    98 
     95/*
    9996add_action('register_post', 'op_wp_userExists',10,3);
    10097//???
     
    152149    }
    153150}
     151
     152*/
  • phpbb-single-sign-on/trunk/files/auth_op.php

    r163762 r165536  
    66*
    77* @package login
    8 * @version 0.4.6
     8* @version 0.5
    99* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1010*
     
    1515    include(dirname(__FILE__).'/auth_db.php');
    1616}
     17
    1718
    1819/**
     
    2930
    3031// Provide option for WordPress path
    31 function acp_op(&$new)
     32/*function acp_op(&$new)
    3233{
    3334    // These are fields required in the config table
     
    4344        'config'    => array('op_path')
    4445    );
    45 }
     46}*/
    4647
    4748/**
     
    5253    global $db, $config;
    5354   
     55    //Still needed ?
    5456    if(defined('SECOND_RUN')){
    5557        return array(
     
    6769       
    6870        global $current_user;
    69 
     71       
     72       
     73        /*
     74        ** Exists in PHPBB ?
     75        */
     76        //TODO :: Replace by generic function op_PHPBB
     77        $sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
     78            FROM ' . USERS_TABLE . "
     79            WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
     80        $result = $db->sql_query($sql);
     81        $phpBB_user = $db->sql_fetchrow($result);
     82       
     83        //$phpBB_user = op_phpBB3::getUserByNameClean($name);
     84       
     85        /*
     86        ** Exists in WP ?
     87        */
    7088        //Loaded from within WP ?
    7189        if(!function_exists('censor_text')){
    72             //use another function, maybe this one is not available at this point of the execution
    73             //$wp_user = wp_get_current_user();
    7490            $wp_user = op_Wordpress::getIdByName($username);
    7591            $in_wp = $wp_user == 0 ? FALSE : TRUE;
    7692        } else {
    7793
     94            //SYNC to WP
     95            op_WordPress::loadAdminAPI();
     96            op_WordPress::changePassword($username, $password);
     97       
    7898            if(isset($current_user)){
    7999                wp_clear_auth_cookie();
     
    97117        }
    98118
    99         //TODO :: Replace by generic function op_PHPBB
    100         //Exists in PHPBB ?
    101         $sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
    102             FROM ' . USERS_TABLE . "
    103             WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
    104         $result = $db->sql_query($sql);
    105         $phpBB_user = $db->sql_fetchrow($result);
    106        
    107         //$phpBB_user = op_phpBB3::getUserByNameClean($name);
    108 
    109         //password ?
    110         /*if($phpBB_user){
    111             //Doit faire la mise à jour du mot de passe ?
    112             if(defined('FROM_WP')){
    113                 //op_phpBB3::changePassword($username,$password);
    114 
    115                 $hashed = md5($password);
    116                 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_password="'.$hashed.'",user_pass_convert=1,user_last_search=1 WHERE username = "' . $username . '"';
    117 
    118                 $hashed = phpbb_hash($password);
    119                 //op_phpBB3::changePassword($username,$password);
    120                 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_password="'.$hashed.'",user_pass_convert=0,user_last_search=1 WHERE username = "' . $username . '"';
    121 
    122 
    123                 $result = $db->sql_query($sql);
    124 
    125                 $phpBB_user['user_password'] = $hashed;
    126                 //echo 'did pass update !';
    127             }
    128 
    129 
    130 
    131             $phpBB_authed = phpbb_check_hash($password, $phpBB_user['user_password']);
    132         }
    133         else{
    134             $phpBB_authed = false;
    135         }*/
    136 
    137         //WP 1 BB 0 ?
    138         if(!$phpBB_user && $in_wp){
    139             //echo 'not in phpbb';
    140 
    141             $email = $wp_user->user_email ? $wp_user->user_email : '';
    142 
    143             // since group IDs may change, use a query to make sure it is the right default group.
    144             $sql = 'SELECT group_id
    145                     FROM ' . GROUPS_TABLE . "
    146                     WHERE group_name = '" . $db->sql_escape(REGISTERED) . "'
    147                         AND group_type = " . GROUP_SPECIAL;
     119        //Checking existence of users
     120        if(!function_exists('censor_text')){
     121            //WP 1 BB 0 ?
     122            if(!$phpBB_user && $in_wp){
     123                //echo 'not in phpbb';
     124
     125                $email = $wp_user->user_email ? $wp_user->user_email : '';
     126
     127                // since group IDs may change, use a query to make sure it is the right default group.
     128                $sql = 'SELECT group_id
     129                        FROM ' . GROUPS_TABLE . "
     130                        WHERE group_name = '" . $db->sql_escape(REGISTERED) . "'
     131                            AND group_type = " . GROUP_SPECIAL;
     132                $result = $db->sql_query($sql);
     133                $row = $db->sql_fetchrow($result);
     134                $group_id = $row['group_id'];
     135
     136                $user_row = array(
     137                    'username'  => $username,
     138                    'user_password' => phpbb_hash($password),
     139                    'group_id'  =>  $group_id,
     140                    'user_email' =>     $email,
     141                    'user_type'     =>  0
     142                );
     143
     144                $id = op_phpBB3::addUser($user_row);
     145                $phpBB_user = op_phpBB3::getUserById($id);
     146            }
     147        } else {
     148            //WP 0 BB 1 ?
     149            if($phpBB_user && !$in_wp){
     150                //echo 'not in wordpress';
     151
     152                $username = $phpBB_user['username'];
     153
     154                $user_row = array(
     155                    'username'  => $username,
     156                    'email' => $phpBB_user['user_email'] ? $phpBB_user['user_email'] : '',
     157                    'password' => html_entity_decode($password)
     158                );
     159
     160                $wp_user = op_WordPress::addUser($user_row);
     161
     162                $wp_user = wp_signon(array(
     163                    'user_login'    => $username,
     164                    'user_password' => html_entity_decode($password)
     165                ), $secure_cookie);
     166
     167                mysql_select_db($db->db_name); // Select phpBB database
     168            }
     169        }
     170       
     171        //SYNC PHPBB Password
     172        if(!function_exists('censor_text')){
     173            //$hashed = md5($password);
     174            //$sql = 'UPDATE ' . USERS_TABLE . ' SET user_password="'.$hashed.'",user_pass_convert=1,user_last_search=1 WHERE username = "' . $username . '"';
     175
     176            $hashed = phpbb_hash($password);
     177            $sql = 'UPDATE ' . USERS_TABLE . ' SET user_password="'.$hashed.'",user_pass_convert=0,user_last_search=1 WHERE username = "' . $username . '"';
     178           
    148179            $result = $db->sql_query($sql);
    149             $row = $db->sql_fetchrow($result);
    150             $group_id = $row['group_id'];
    151 
    152             $user_row = array(
    153                 'username'  => $username,
    154                 'user_password' => phpbb_hash($password),
    155                 'group_id'  =>  $group_id,
    156                 'user_email' =>     $email,
    157                 'user_type'     =>  0
    158             );
    159 
    160             $id = op_phpBB3::addUser($user_row);
    161             $phpBB_user = op_phpBB3::getUserById($id);
    162         }
    163 
    164         //BUG :: user creates duplicata on every connection !!!
    165         //WP 0 BB 1 ?
    166         if($phpBB_user && !$in_wp){
    167             //echo 'not in wordpress';
    168 
    169             $username = $phpBB_user['username'];
    170 
    171             $user_row = array(
    172                 'username'  => $username,
    173                 'email' => $phpBB_user['user_email'] ? $phpBB_user['user_email'] : '',
    174                 'password' => html_entity_decode($password)
    175             );
    176 
    177             $wp_user = op_WordPress::addUser($user_row);
    178 
    179             $wp_user = wp_signon(array(
    180                 'user_login'    => $username,
    181                 'user_password' => html_entity_decode($password)
    182             ), $secure_cookie);
    183 
    184             mysql_select_db($db->db_name); // Select phpBB database
     180
     181            //$phpBB_user['user_password'] = $hashed;
     182            //$phpBB_authed = phpbb_check_hash($password, $phpBB_user['user_password']);
    185183        }
    186184
     
    194192        }   
    195193
    196 
    197         // TODO -- Make sure they are not in all modules active
    198         //if ((!$phpBB_user || !$phpBB_authed) && !$in_wp)
    199194        if ((!$phpBB_user || !$phpBB_authed) && !$in_wp)
    200195        {   
     
    222217}
    223218
    224 //TODO :: Load only when wp is loaded
    225219function logout_op($data, $new_session){
    226220   
    227221    //if WP is loaded   
    228     if(function_exists('wp_signon')){
     222    if(function_exists('wp_clear_auth_cookie')){
    229223        wp_clear_auth_cookie();
    230224    }
  • phpbb-single-sign-on/trunk/files/common.php

    r163762 r165536  
    66*
    77* @package login
    8 * @version 0.4.6
     8* @version 0.5
    99* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1010*
     
    6868$include_common_contents = str_replace($original_get_cookie,$new_get_cookie,$include_common_contents);
    6969
    70 //Include de la version modifiée de common.php
     70//Include de la version modifie de common.php
    7171eval($include_common_contents);
    7272
     73//Include Wordpress
    7374include($root_path.'/'.$extra_path.'wp-blog-header.php');
    7475   
  • phpbb-single-sign-on/trunk/module.phpbb.php

    r162729 r165536  
    6363            $identity = array();
    6464        }
    65        
    66        
    6765    }
    6866
    69     function login(){
     67    function login($uname, $passwd){
    7068        define('IN_PHPBB',TRUE);
    7169
    72         global $op_credentials;
    7370        global $auth;
    74        
    7571
    76         $username = $op_credentials['username']=='' ? request_var('username', '', true) : $op_credentials['username'];
    77         $password = $op_credentials['password']=='' ? request_var('password', '', true) : $op_credentials['password'];
     72        $username = $uname=='' ? request_var('username', '', true) : $uname;
     73        $password = $passwd=='' ? request_var('password', '', true) : $passwd;
    7874
    7975        $result = $auth->login($username, $password);
     
    9692        require($phpbb_root_path.'config.php');
    9793
    98         $dbr = mysql_connect($dbhost,$dbuser,$dbpasswd);
    99         mysql_select_db($dbname);
    100         define('USERS_TABLE', 'phpbb_users');
     94        //$dbr = mysql_connect($dbhost,$dbuser,$dbpasswd);
     95        //mysql_select_db($dbname);
    10196
    10297        // set user_pass_convert to 1 so user's pass will be hashed under phpBB rules when logging in after pass is changed in WordPress
     
    119114
    120115    function addUser($user){
    121         global $phpbb_root_path,$phpEx;
     116        global $phpbb_root_path, $phpEx;
    122117
    123118        // Use the user_add function, this code is from auth.php line 864-869
     
    174169   
    175170    function getUserByNameClean($name){
    176        
    177171        return op_phpBB3::getUserByName($name, true);
    178172    }
  • phpbb-single-sign-on/trunk/module.wp.php

    r162742 r165536  
    6767
    6868        wp_update_user(get_object_vars($user));
     69    }
     70   
     71    function changePassword($username, $password){
     72        $user = array();
     73        $user['ID'] = op_WordPress::getIdByName($username);
     74        $user['user_pass'] = $password;
     75
     76        wp_update_user($user);
    6977    }
    7078
  • phpbb-single-sign-on/trunk/readme.txt

    r163762 r165536  
    1818characters, nor special ones. Check directly in the DB if in doubt.
    1919
     20!IMPORTANT!
     21PHPBB and Wordpress need to run on the same database.
     22otherwise it won't work
    2023
    2124== Changelog ==
     
    2326= Roadmap =
    2427* API to create logons on other CMS's
    25 * Hook for password change
    26 * Profile sync
     28* Make it work on multiple db's
     29
     30= 0.5 =
     31* Enabled synchronisation
    2732
    2833= 0.4.6 =
Note: See TracChangeset for help on using the changeset viewer.