Combining login code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cybersnac
Forum Newbie
Posts: 1
Joined: Thu Sep 13, 2007 12:28 pm

Combining login code

Post by cybersnac »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello everyone.

I'm very new to PHP and need some help, if possible with a feature I'd like to implement on my site.

What currently happens is this. A user logs into my Joomla CMS site and gets authenticated with the Joomla system. This is done with this code:

Code: Select all

<?php
/**
* @version $Id: mod_login.php 7211 2007-04-29 02:26:51Z robs $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mosConfig_frontend_login;

if ( $mosConfig_frontend_login != NULL && ($mosConfig_frontend_login === 0 || $mosConfig_frontend_login === '0')) {
	return;
}

// url of current page that user will be returned to after login
if ($query_string = mosGetParam( $_SERVER, 'QUERY_STRING', '' )) {
	$return = 'index.php?' . $query_string;
} else {
	$return = 'index.php';
}

$registration_enabled 	= $mainframe->getCfg( 'allowUserRegistration' );
$message_login 			= $params->def( 'login_message', 	0 );
$message_logout 		= $params->def( 'logout_message', 	0 );
$login 					= $params->def( 'login', 			$return );
$logout 				= $params->def( 'logout', 			$return );
$name 					= $params->def( 'name', 			1 );
$greeting 				= $params->def( 'greeting', 		1 );
$pretext 				= $params->get( 'pretext' );
$posttext 				= $params->get( 'posttext' );

if ( $my->id ) {
// Logout output
// ie HTML when already logged in and trying to logout
	if ( $name ) {
		$name = $my->name;
	} else {
		$name = $my->username;
	}
	?>
	<form action="<?php echo sefRelToAbs( 'index.php?option=logout' ); ?>" method="post" name="logout">
	<?php
	if ( $greeting ) {
		echo _HI;
		echo $name;
	}
	?>
	<br />

	<div align="center">
		<input type="submit" name="Submit" class="button" value="<?php echo _BUTTON_LOGOUT; ?>" />
	</div>

	<input type="hidden" name="option" value="logout" />
	<input type="hidden" name="op2" value="logout" />
	<input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" />
	<input type="hidden" name="return" value="<?php echo htmlspecialchars( sefRelToAbs( $logout ) ); ?>" />
	<input type="hidden" name="message" value="<?php echo htmlspecialchars( $message_logout ); ?>" />
	</form>
	<?php
} else {
// Login output
// ie HTML when not logged in and trying to login
	// used for spoof hardening
	$validate = josSpoofValue(1);
	?>
	<form action="<?php echo sefRelToAbs( 'index.php' ); ?>" method="post" name="login" >
	<?php
	echo $pretext;
	?>

	<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
	<tr>
		<td>
			<label for="mod_login_username">
				<?php echo _USERNAME; ?>
			</label>
			<br />
			<input name="username" id="mod_login_username" type="text" class="inputbox" alt="username" size="10" />
		</td>
		<td>
			<label for="mod_login_password">
				<?php echo _PASSWORD; ?>
			</label>
			<br />
			<input type="password" id="mod_login_password" name="passwd" class="inputbox" size="10" alt="password" />
		</td>
	</tr>
	<tr>
		<td>
			<input type="checkbox" name="remember" id="mod_login_remember" class="inputbox" value="yes" alt="Remember Me" />
			<label for="mod_login_remember">
				<?php echo _REMEMBER_ME; ?>
			</label>
			<br />
			<input type="submit" name="Submit" class="button" value="<?php echo _BUTTON_LOGIN; ?>" />
		</td>
	</tr>
	<tr>
		<td>
			<a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=lostPassword' ); ?>">
				<?php echo _LOST_PASSWORD; ?></a>
		</td>
	</tr>
	<?php
	if ( $registration_enabled ) {
		?>
		<tr>
			<td>
				<?php echo _NO_ACCOUNT; ?>
				<a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=register' ); ?>">
					<?php echo _CREATE_ACCOUNT; ?></a>
			</td>
		</tr>
		<?php
	}
	?>
	</table>
	<?php
	echo $posttext;
	?>

	<input type="hidden" name="option" value="login" />
	<input type="hidden" name="op2" value="login" />
	<input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" />
	<input type="hidden" name="return" value="<?php echo htmlspecialchars( sefRelToAbs( $login ) ); ?>" />
	<input type="hidden" name="message" value="<?php echo htmlspecialchars( $message_login ); ?>" />
	<input type="hidden" name="force_session" value="1" />
	<input type="hidden" name="<?php echo $validate; ?>" value="1" />
	</form>
	<?php
}
?>
Upon authentication with the Joomla system, the user will see a "block" if you will that contains code that displays a form where the user can then enter a second set of credentials and submit that to an external server. Those credentials authenticate the user with the system that resides on that server. The code in the block is as follows:

Code: Select all

<?php
/**
* @version $Id: mod_jflogin.php Wed Apr 05 10:46:26 WST 2006 shaynebartlett
* @package J!FAQ
* @copyright Copyright (C) 2005 theJ!factory. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* J!Login is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// NO DIRECT ACCESS
defined( '_VALID_MOS' ) or die( 'Restricted access' );

$return = mosGetParam( $_SERVER, 'REQUEST_URI', null );
// converts & to & for xtml compliance
$return = str_replace( '&', '&', $return );

$url = $params->def( 'url', $return );
$user_label = $params->def( '_user', $return );
$user_field = $params->def( 'user', $return );
$pass_label = $params->def( '_pass', $return );
$pass_field = $params->def( 'pass', $return );
$login = $params->def( 'login', $return );
$class = $params->def( 'moduleclass_sfx', $return );

$username = strval( mosGetParam( $_POST, 'username', '' ) );



$password = mosGetParam( $_POST, 'passwd', '' );
?>

<div title="JF login" align="left">
<form action="<?php echo $url; ?>" target="_blank" method="post">
		<label for="<?php echo $user_field; ?>"><?php echo $user_label; ?></label>
		<br />
		<input accesskey="U" id="<?php echo $user_field; ?>" tabindex="1" name="<?php echo $user_field; ?>" value="<?php echo $username; ?>" type="hidden" alt="username" size="20" class="inputbox<?php echo $class; ?>"/>
		<br />
		<label for="<?php echo $pass_field; ?>"><?php echo $pass_label; ?></label>
		<br />
		<input accesskey="P" id="<?php echo $pass_field; ?>" tabindex="2" name="<?php echo $pass_field; ?>" value="<?php echo $password; ?>" type="hidden" class="inputbox<?php echo $class; ?>" alt="password" size="20"/>
		<br />
		<input tabindex="3" type="submit" name="Submit" value="<?php echo $login; ?>" class="button<?php echo $class; ?>" />
</form>
</div>
What I would really like to do is have the user log into the Joomla system and have those credentials sent to both the Joomla system AND the server that they normally have to do the second authentication for.

Can anyone show me how to have both of these php files run at the time the user enters their set of credentials the FIRST time where both sets of code take the credentials supplied and pass them to both the Joomla system AND the external server?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply