0
votes

I have my wordpress install at localhost/ and my joomla install at localhost/s .

The code for my login form for wordpress is

<?php
/**
 * @package   gantry
 * @subpackage widgets
 * @version   1.0 March 15, 2011
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */ 

defined('GANTRY_VERSION') or die();

gantry_import('core.gantrywidget');

add_action('widgets_init', array("GantryWidgetLoginForm","init"));

class GantryWidgetLoginForm extends GantryWidget {
    var $short_name = 'loginform';
    var $wp_name = 'gantry_loginform';
    var $long_name = 'Gantry Login Form';
    var $description = 'Gantry Login Form Widget';
    var $css_classname = 'widget_gantry_loginform';
    var $width = 200;
    var $height = 400;

    function init() {
        register_widget("GantryWidgetLoginForm");
    }

    function render_title($args, $instance) {
        global $gantry;
        if($instance['title'] != '') :
            echo $instance['title'];
        endif;
    }

    function render($args, $instance){
        global $gantry, $current_user;
        ob_start();
        ?>

        <?php if(!is_user_logged_in()) : ?>

            <form id="form-login" action="<?php echo wp_login_url(get_bloginfo('url')); ?>" method="post">
                <fieldset class="input">
                    <p id="form-login-username">
                        <input id="modlgn_username" type="text" name="log" class="inputbox" alt="username" size="18" value="<?php _re('Username'); ?>" onfocus="if (this.value=='<?php _re('Username'); ?>') this.value=''" onblur="if(this.value=='') { this.value='<?php _re('Username'); ?>'; return false; }" />
                    </p>
                    <p id="form-login-password">
                        <input id="modlgn_passwd" type="password" name="pwd" class="inputbox" size="18" alt="password" value="<?php _re('Password'); ?>" onfocus="if (this.value=='<?php _re('Password'); ?>') this.value=''" onblur="if(this.value=='') { this.value='<?php _re('Password'); ?>'; return false; }" />
                    </p>
                    <p id="form-login-remember">
                        <input type="checkbox" name="rememberme" class="checkbox" alt="<?php _re('Remember Me'); ?>" />
                        <label class="rememberme"><?php _re('Remember Me'); ?></label>
                    </p>
                    <div class="readon"><input type="submit" value="<?php _re('Login'); ?>" class="button" name="submit" /></div>
                </fieldset>             
                <ul>
                    <li>
                        <a href="<?php echo wp_lostpassword_url(); ?>"><?php _re('Forgot your password?'); ?></a>
                    </li>
                    <?php if(get_option('users_can_register')) : ?>
                    <li>
                        <a href="<?php bloginfo('wpurl'); ?>/wp-register.php"><?php _re('Register'); ?></a>
                    </li>
                    <?php endif; ?>
                </ul>               
            </form>

        <?php else : ?>

            <form id="form-login" action="<?php echo wp_logout_url(get_bloginfo('url')); ?>" method="post">
                <fieldset class="input">

                    <div class="user-greeting">
                        <b><?php echo $instance['user_greeting']; ?> <?php echo $current_user->display_name; ?></b><br />
                    </div>
                    <div class="readon"><input type="submit" name="Submit" class="button" value="Log out" /></div>

                </fieldset>
            </form>

        <?php endif; ?>

        <?php 

        echo ob_get_clean();

    }

The code for my joomla login form is

<?php
/**
 * @version     $Id: login.php 303 2010-01-07 02:56:33Z joomlaworks $
 * @package     K2
 * @author    JoomlaWorks http://www.joomlaworks.gr
 * @copyright   Copyright (c) 2006 - 2010 JoomlaWorks Ltd. All rights reserved.
 * @license     GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

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

// OpenID stuff (do not edit)
if(JPluginHelper::isEnabled('authentication', 'openid')){
    $lang->load( 'plg_authentication_openid', JPATH_ADMINISTRATOR );
    $langScript = '
        var JLanguage = {};
        JLanguage.WHAT_IS_OPENID = \''.JText::_( 'WHAT_IS_OPENID' ).'\';
        JLanguage.LOGIN_WITH_OPENID = \''.JText::_( 'LOGIN_WITH_OPENID' ).'\';
        JLanguage.NORMAL_LOGIN = \''.JText::_( 'NORMAL_LOGIN' ).'\';
        var modlogin = 1;
    ';
    $document = &JFactory::getDocument();
    $document->addScriptDeclaration( $langScript );
    JHTML::_('script', 'openid.js');
}

// Get user stuff (do not edit)
$usersConfig = &JComponentHelper::getParams( 'com_users' );

?>

<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2LoginBlock <?php echo $params->get('moduleclass_sfx'); ?>">
    <form action="<?php echo JRoute::_( 'index.php', true, $params->get('usesecure')); ?>" method="post" name="login" id="form-login" >

        <?php if($params->get('pretext')): ?>
        <p class="preText"><?php echo $params->get('pretext'); ?></p>
      <?php endif; ?>

      <fieldset class="input">
        <p id="form-login-username">
          <label for="modlgn_username"><?php echo JText::_('Username') ?></label>
          <input id="modlgn_username" type="text" name="username" class="inputbox" alt="username" size="18" />
        </p>
        <p id="form-login-password">
          <label for="modlgn_passwd"><?php echo JText::_('Password') ?></label>
          <input id="modlgn_passwd" type="password" name="passwd" class="inputbox" size="18" alt="password" />
        </p>
        <?php if(JPluginHelper::isEnabled('system', 'remember')) : ?>
        <p id="form-login-remember">
          <input id="modlgn_remember" type="checkbox" name="remember" class="inputbox" value="yes" alt="Remember Me" />
          <label for="modlgn_remember"><?php echo JText::_('Remember me') ?></label>
        </p>
        <?php endif; ?>

        <div class="readon"><input type="submit" name="Submit" class="button" value="<?php echo JText::_('LOGIN') ?>" /></div>
      </fieldset>

      <ul>
        <li><a href="<?php echo JRoute::_( 'index.php?option=com_user&view=reset' ); ?>"><?php echo JText::_('Forgot your password?'); ?></a></li>
        <li><a href="<?php echo JRoute::_( 'index.php?option=com_user&view=remind' ); ?>"><?php echo JText::_('Forgot your username?'); ?></a></li>
        <?php if ($usersConfig->get('allowUserRegistration')): ?>
        <li><a href="<?php echo JRoute::_( 'index.php?option=com_user&view=register' ); ?>"><?php echo JText::_('Create an account'); ?></a></li>
        <?php endif; ?>
      </ul>

      <?php if($params->get('posttext')): ?>
      <p class="postText"><?php echo $params->get('posttext'); ?></p>
      <?php endif; ?>

      <input type="hidden" name="option" value="com_user" />
      <input type="hidden" name="task" value="login" />
      <input type="hidden" name="return" value="<?php echo $return; ?>" />
      <?php echo JHTML::_( 'form.token' ); ?>
    </form>
    </div>    

I want it so that when the user clicks the login button on my wordpress page with his user and pass , the user and pass should get submitted to joomla for login purpose and user should be logged into joomla instead of wordpress . The normal login url for joomla is localhost/s/index.php?option=com_user&view=login&Itemid=204 .

This problem was somewhat addressed at Diverting WordPress login and register links to Joomla but didnt help me much .

2

2 Answers

1
votes

You can post your from to /index.php?option=com_user&view=login&Itemid=204 with one input hidden field from wordpress.

<input type="hidden" value="wordpress" name="wp">

Now in joomla check the post value of hidden field that the request is coming from joomla form or wordpress form. If request is coming from wordpress, avoid to check user token.

if(!isset($_POST['wp'])) {
// Check for request forgeries
JRequest::checkToken('request') or jexit( 'Invalid Token' );
}

0
votes

You need more than just login redirection. You have to be able to synchronize the users across both Joomla and WordPress. Otherwise, if the user is only present in one user table, the second login will fail. You need a bridge. As far as I know, there is no purpose built Joomla/WordPress bridge though you can accomplish it with the Joomla extension JFusion.