From: <lph...@us...> - 2007-09-09 15:41:20
|
Update of /cvsroot/tikiwiki/tiki In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26725 Modified Files: tiki-login_openid.php tiki-setup.php Log Message: Support for login and logout, plus partial user switch Index: tiki-login_openid.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/tiki-login_openid.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- tiki-login_openid.php 9 Sep 2007 00:39:26 -0000 1.4 +++ tiki-login_openid.php 9 Sep 2007 15:41:20 -0000 1.5 @@ -37,6 +37,23 @@ die; } +function setupFromAddress() // {{{ +{ + global $url_scheme, $url_host, $url_port, $base_url; + // Remember where the page was requested from (from tiki-login.php) + if ( ! isset($_SESSION['loginfrom']) ) { + $_SESSION['loginfrom'] = ( isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $tikiIndex ); + if ( ! ereg('^http', $_SESSION['loginfrom']) ) { + if ( $_SESSION['loginfrom']{0} == '/' ) $_SESSION['loginfrom'] = $url_scheme.'://'.$url_host.(($url_port!='')?":$url_port":'').$_SESSION['loginfrom']; + else $_SESSION['loginfrom'] = $base_url.$_SESSION['loginfrom']; + } + } + + if( strpos( $_SESSION['loginfrom'], 'openid' ) !== false ) + $_SESSION['loginfrom'] = $base_url; + +} // }}} + function getAccountsMatchingIdentifier( $identifier ) // {{{ { global $tikilib; @@ -53,6 +70,9 @@ function loginUser( $identifier ) // {{{ { $_SESSION['tiki-user-tikiwiki'] = $identifier; + header('location: '.$_SESSION['loginfrom']); + unset( $_SESSION['loginfrom'] ); + exit; } // }}} function filterExistingInformation( &$data, &$messages ) // {{{ @@ -74,13 +94,32 @@ { global $smarty; + // Default values for the registration form $smarty->assign( 'username', $data['nickname'] ); $smarty->assign( 'email', $data['email'] ); + // Changing some system values to get the login box to display properly in the context + $smarty->assign( 'rememberme', 'disabled' ); + $smarty->assign( 'forgotPass', 'n' ); + $smarty->assign( 'allowRegister', 'n' ); + $smarty->assign( 'change_password', 'n' ); + $smarty->assign( 'feature_openid', 'n' ); + $smarty->assign( 'feature_switch_ssl_mode', 'n' ); + + // Display $smarty->assign( 'mid', 'tiki-openid_register.tpl' ); $smarty->display('tiki.tpl'); } // }}} + function displaySelectionList( $data, $messages ) // {{{ + { + global $smarty; + + // Display + $smarty->assign( 'mid', 'tiki-openid_select.tpl' ); + $smarty->display('tiki.tpl'); + } // }}} + function displayError($message) { // {{{ global $smarty; @@ -151,6 +190,8 @@ } // }}} function runAuth() { // {{{ + setupFromAddress(); + $openid = getOpenIDURL(); $consumer = getConsumer(); @@ -215,6 +256,8 @@ } // }}} function runFinish() { // {{{ + global $smarty; + $consumer = getConsumer(); // Complete the authentication process using the server's @@ -224,10 +267,10 @@ // Check the response status. if ($response->status == Auth_OpenID_CANCEL) { // This means the authentication was cancelled. - $msg = 'Verification cancelled.'; + displayError( 'Verification cancelled.' ); } else if ($response->status == Auth_OpenID_FAILURE) { // Authentication failed; display the error message. - $msg = "OpenID authentication failed: " . $response->message; + displayError( "OpenID authentication failed: " . $response->message ); } else if ($response->status == Auth_OpenID_SUCCESS) { // This means the authentication succeeded; extract the // identity URL and Simple Registration data (if it was @@ -257,6 +300,10 @@ // If OpenID identifier exists in the database $list = getAccountsMatchingIdentifier( $data['identifier'] ); + + $_SESSION['openid_userlist'] = $list; + $smarty->assign( 'openid_userlist', $list ); + if( count( $list ) > 0 ) { // If Single account @@ -284,8 +331,27 @@ } } // }}} -if( isset( $_GET['action'] ) && $_GET['action'] == 'return' ) - runFinish(); +function runSelect() // {{{ +{ + setupFromAddress(); + + $user = $_GET['select']; + + if( in_array( $user, $_SESSION['openid_userlist'] ) ) + loginUser( $user ); + else + displayError( tra('The selected account is not associated with your identity.') ); +} // }}} + +if( isset( $_GET['action'] ) ) +{ + if( $_GET['action'] == 'return' ) + runFinish(); + elseif( $_GET['action'] == 'select' && isset( $_GET['select'] ) ) + runSelect(); + else + displayError( tra('unknown action') ); +} else runAuth(); Index: tiki-setup.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/tiki-setup.php,v retrieving revision 1.457 retrieving revision 1.458 diff -u -d -r1.457 -r1.458 --- tiki-setup.php 29 Aug 2007 14:15:26 -0000 1.457 +++ tiki-setup.php 9 Sep 2007 15:41:20 -0000 1.458 @@ -1905,4 +1905,16 @@ $smarty->assign_by_ref('phpErrors',$phpErrors); $smarty->assign_by_ref('cookie',$_SESSION['tiki_cookie_jar']); + +// OpenID support +if( isset( $_SESSION['openid_userlist'] ) && isset( $_SESSION['openid_url'] ) ) +{ + $smarty->assign( 'openid_url', $_SESSION['openid_url'] ); + $smarty->assign( 'openid_userlist', $_SESSION['openid_userlist'] ); +} +else +{ + $smarty->assign( 'openid_url', '' ); + $smarty->assign( 'openid_userlist', array() ); +} ?> |