1 (edited by KeyDog 2009-01-30 08:38)

Topic: [Mod] Style - Login Box on Frontpage

THIS IS NOW AN EXTENSION
http://punbb.informer.com/forums/topic/ … frontpage/






FORGET THIS:


=========================================================================
##
##        Mod title:  Add a login box above header
##
##      Mod version:  1.0.0
##   Works on PunBB:  1.3.2
##     Release date:  27-JAN-2009
##           Author:  Orginal made by Artic Chill for 1.2.x,
##                    Mod by KeyDog/Garciat for 1.3
##
##      Description:  This mod adds a login box on index page
##                    You are free to place it where you require in :
##
##    Affected file:  include/template/main.tpl
##
##
##   Included Files:  include/user/login.php
##

Download
========================================================================

Rapidshare ZIP

Mediafire ZIP


Bugs
========================================================================

please report here


Demo
========================================================================

Here

========================================================================


Feedback Welcome


========================================================================

inspired by:




http://keydogbb.info/img/xenu.png

any mod or style like this around?
would like to see login on front page....

Re: [Mod] Style - Login Box on Frontpage

old login.php  mod for pun 1.2
looking for what needs to be changed....

<?php

// Show login if not logged in
if($pun_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
    require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

    $required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_common['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_common['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_common['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

then add this to main.tpl


<!-- forum_include "login.php" -->

Re: [Mod] Style - Login Box on Frontpage

new:-->  require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';
old:--> require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';

stuff like that - but no sure about all of them....

Re: [Mod] Style - Login Box on Frontpage

or should i work backwards from this originial login.php of pun 1.3 ?

<?php
/**
 * Handles logins, logouts, and password reset requests.
 *
 * @copyright Copyright (C) 2008 PunBB, partially based on code copyright (C) 2008 FluxBB.org
 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
 * @package PunBB
 */


if (isset($_GET['action']))
    define('FORUM_QUIET_VISIT', 1);

if (!defined('FORUM_ROOT'))
    define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';

($hook = get_hook('li_start')) ? eval($hook) : null;

// Load the login.php language file
require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';


$action = isset($_GET['action']) ? $_GET['action'] : null;
$errors = array();

// Login
if (isset($_POST['form_sent']) && empty($action))
{
    $form_username = forum_trim($_POST['req_username']);
    $form_password = forum_trim($_POST['req_password']);
    $save_pass = isset($_POST['save_pass']);

    ($hook = get_hook('li_login_form_submitted')) ? eval($hook) : null;

    // Get user info matching login attempt
    $query = array(
        'SELECT'    => 'u.id, u.group_id, u.password, u.salt',
        'FROM'        => 'users AS u'
    );

    if ($db_type == 'mysql' || $db_type == 'mysqli')
        $query['WHERE'] = 'username=\''.$forum_db->escape($form_username).'\'';
    else
        $query['WHERE'] = 'LOWER(username)=LOWER(\''.$forum_db->escape($form_username).'\')';

    ($hook = get_hook('li_login_qr_get_login_data')) ? eval($hook) : null;
    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
    list($user_id, $group_id, $db_password_hash, $salt) = $forum_db->fetch_row($result);

    $authorized = false;
    if (!empty($db_password_hash))
    {
        $sha1_in_db = (strlen($db_password_hash) == 40) ? true : false;
        $form_password_hash = forum_hash($form_password, $salt);

        if ($sha1_in_db && $db_password_hash == $form_password_hash)
            $authorized = true;
        else if ((!$sha1_in_db && $db_password_hash == md5($form_password)) || ($sha1_in_db && $db_password_hash == sha1($form_password)))
        {
            $authorized = true;

            $salt = random_key(12);
            $form_password_hash = forum_hash($form_password, $salt);

            // There's an old MD5 hash or an unsalted SHA1 hash in the database, so we replace it
            // with a randomly generated salt and a new, salted SHA1 hash
            $query = array(
                'UPDATE'    => 'users',
                'SET'        => 'password=\''.$form_password_hash.'\', salt=\''.$forum_db->escape($salt).'\'',
                'WHERE'        => 'id='.$user_id
            );

            ($hook = get_hook('li_login_qr_update_user_hash')) ? eval($hook) : null;
            $forum_db->query_build($query) or error(__FILE__, __LINE__);
        }
    }

    ($hook = get_hook('li_login_pre_auth_message')) ? eval($hook) : null;

    if (!$authorized)
        $errors[] = sprintf($lang_login['Wrong user/pass']);

    // Did everything go according to plan?
    if (empty($errors))
    {
        // Update the status if this is the first time the user logged in
        if ($group_id == FORUM_UNVERIFIED)
        {
            $query = array(
                'UPDATE'    => 'users',
                'SET'        => 'group_id='.$forum_config['o_default_user_group'],
                'WHERE'        => 'id='.$user_id
            );

            ($hook = get_hook('li_login_qr_update_user_group')) ? eval($hook) : null;
            $forum_db->query_build($query) or error(__FILE__, __LINE__);
        }

        // Remove this user's guest entry from the online list
        $query = array(
            'DELETE'    => 'online',
            'WHERE'        => 'ident=\''.$forum_db->escape(get_remote_address()).'\''
        );

        ($hook = get_hook('li_login_qr_delete_online_user')) ? eval($hook) : null;
        $forum_db->query_build($query) or error(__FILE__, __LINE__);

        $expire = ($save_pass) ? time() + 1209600 : time() + $forum_config['o_timeout_visit'];
        forum_setcookie($cookie_name, base64_encode($user_id.'|'.$form_password_hash.'|'.$expire.'|'.sha1($salt.$form_password_hash.forum_hash($expire, $salt))), $expire);

        ($hook = get_hook('li_login_pre_redirect')) ? eval($hook) : null;

        redirect(forum_htmlencode($_POST['redirect_url']).((substr_count($_POST['redirect_url'], '?') == 1) ? '&amp;' : '?').'login=1', $lang_login['Login redirect']);
    }
}


// Logout
else if ($action == 'out')
{
    if ($forum_user['is_guest'] || !isset($_GET['id']) || $_GET['id'] != $forum_user['id'])
    {
        header('Location: '.forum_link($forum_url['index']));
        exit;
    }

    // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid.
    // If it's in GET, we need to make sure it's valid.
    if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('logout'.$forum_user['id'])))
        csrf_confirm_form();

    ($hook = get_hook('li_logout_selected')) ? eval($hook) : null;

    // Remove user from "users online" list.
    $query = array(
        'DELETE'    => 'online',
        'WHERE'        => 'user_id='.$forum_user['id']
    );

    ($hook = get_hook('li_logout_qr_delete_online_user')) ? eval($hook) : null;
    $forum_db->query_build($query) or error(__FILE__, __LINE__);

    // Update last_visit (make sure there's something to update it with)
    if (isset($forum_user['logged']))
    {
        $query = array(
            'UPDATE'    => 'users',
            'SET'        => 'last_visit='.$forum_user['logged'],
            'WHERE'        => 'id='.$forum_user['id']
        );

        ($hook = get_hook('li_logout_qr_update_last_visit')) ? eval($hook) : null;
        $forum_db->query_build($query) or error(__FILE__, __LINE__);
    }

    $expire = time() + 1209600;
    forum_setcookie($cookie_name, base64_encode('1|'.random_key(8, false, true).'|'.$expire.'|'.random_key(8, false, true)), $expire);

    // Reset tracked topics
    set_tracked_topics(null);

    ($hook = get_hook('li_logout_pre_redirect')) ? eval($hook) : null;

    redirect(forum_link($forum_url['index']), $lang_login['Logout redirect']);
}


// New password
else if ($action == 'forget' || $action == 'forget_2')
{
    if (!$forum_user['is_guest'])
        header('Location: '.forum_link($forum_url['index']));

    ($hook = get_hook('li_forgot_pass_selected')) ? eval($hook) : null;

    if (isset($_POST['form_sent']))
    {
        // User pressed the cancel button
        if (isset($_POST['cancel']))
            redirect(forum_link($forum_url['index']), $lang_login['New password cancel redirect']);

        if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
            require FORUM_ROOT.'include/email.php';

        // Validate the email-address
        $email = strtolower(forum_trim($_POST['req_email']));
        if (!is_valid_email($email))
            $errors[] = $lang_login['Invalid e-mail'];

        ($hook = get_hook('li_forgot_pass_end_validation')) ? eval($hook) : null;

        // Did everything go according to plan?
        if (empty($errors))
        {
            // Fetch user matching $email
            $query = array(
                'SELECT'    => 'u.id, u.username, u.salt, u.last_email_sent',
                'FROM'        => 'users AS u',
                'WHERE'        => 'u.email=\''.$forum_db->escape($email).'\''
            );

            ($hook = get_hook('li_forgot_pass_qr_get_user_data')) ? eval($hook) : null;
            $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
            if ($forum_db->num_rows($result))
            {
                ($hook = get_hook('li_forgot_pass_pre_email')) ? eval($hook) : null;

                // Load the "activate password" template
                $mail_tpl = forum_trim(file_get_contents(FORUM_ROOT.'lang/'.$forum_user['language'].'/mail_templates/activate_password.tpl'));

                // The first row contains the subject
                $first_crlf = strpos($mail_tpl, "\n");
                $mail_subject = forum_trim(substr($mail_tpl, 8, $first_crlf-8));
                $mail_message = forum_trim(substr($mail_tpl, $first_crlf));

                // Do the generic replacements first (they apply to all e-mails sent out here)
                $mail_message = str_replace('<base_url>', $base_url.'/', $mail_message);
                $mail_message = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $forum_config['o_board_title']), $mail_message);

                ($hook = get_hook('li_forgot_pass_new_general_replace_data')) ? eval($hook) : null;

                // Loop through users we found
                while ($cur_hit = $forum_db->fetch_assoc($result))
                {
                    $forgot_pass_timeout = 3600;

                    ($hook = get_hook('li_forgot_pass_pre_flood_check')) ? eval($hook) : null;

                    if ($cur_hit['last_email_sent'] != '' && (time() - $cur_hit['last_email_sent']) < $forgot_pass_timeout && (time() - $cur_hit['last_email_sent']) >= 0)
                        message(sprintf($lang_login['Email flood'], $forgot_pass_timeout));

                    // Generate a new password activation key
                    $new_password_key = random_key(8, true);

                    $query = array(
                        'UPDATE'    => 'users',
                        'SET'        => 'activate_key=\''.$new_password_key.'\', last_email_sent = '.time(),
                        'WHERE'        => 'id='.$cur_hit['id']
                    );

                    ($hook = get_hook('li_forgot_pass_qr_set_activate_key')) ? eval($hook) : null;
                    $forum_db->query_build($query) or error(__FILE__, __LINE__);

                    // Do the user specific replacements to the template
                    $cur_mail_message = str_replace('<username>', $cur_hit['username'], $mail_message);
                    $cur_mail_message = str_replace('<activation_url>', str_replace('&amp;', '&', forum_link($forum_url['change_password_key'], array($cur_hit['id'], $new_password_key))), $cur_mail_message);

                    ($hook = get_hook('li_forgot_pass_new_user_replace_data')) ? eval($hook) : null;

                    forum_mail($email, $mail_subject, $cur_mail_message);
                }

                message(sprintf($lang_login['Forget mail'], '<a href="mailto:'.forum_htmlencode($forum_config['o_admin_email']).'">'.forum_htmlencode($forum_config['o_admin_email']).'</a>'));
            }
            else
                $errors[] = sprintf($lang_login['No e-mail match'], forum_htmlencode($email));
        }
    }

    // Setup form
    $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
    $forum_page['form_action'] = forum_link($forum_url['request_password']);

    // Setup breadcrumbs
    $forum_page['crumbs'] = array(
        array($forum_config['o_board_title'], forum_link($forum_url['index'])),
        array($lang_login['New password request'], forum_link($forum_url['request_password']))
    );

    ($hook = get_hook('li_forgot_pass_pre_header_load')) ? eval($hook) : null;

    define ('FORUM_PAGE', 'reqpass');
    require FORUM_ROOT.'header.php';

    // START SUBST - <!-- forum_main -->
    ob_start();

    ($hook = get_hook('li_forgot_pass_output_start')) ? eval($hook) : null;

?>
    <div class="main-head">
        <h2 class="hn"><span><?php echo $lang_login['New password request'] ?></span></h2>
    </div>
    <div class="main-content main-frm">
        <div class="ct-box info-box">
            <p class="important"><?php echo $lang_login['New password info'] ?></p>
        </div>
<?php

    // If there were any errors, show them
    if (!empty($errors))
    {
        $forum_page['errors'] = array();
        foreach ($errors as $cur_error)
            $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';

        ($hook = get_hook('li_forgot_pass_pre_new_password_errors')) ? eval($hook) : null;

?>
        <div class="ct-box error-box">
            <h2 class="warn hn"><?php echo $lang_login['New password errors'] ?></h2>
            <ul class="error-list">
                <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
            </ul>
        </div>
<?php

    }

?>
        <div id="req-msg" class="req-warn ct-box error-box">
            <p class="important"><?php printf($lang_common['Required warn'], '<em>'.$lang_common['Required'].'</em>') ?></p>
        </div>
        <form id="afocus" class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
            <div class="hidden">
                <input type="hidden" name="form_sent" value="1" />
                <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($forum_page['form_action']) ?>" />
            </div>
<?php ($hook = get_hook('li_forgot_pass_pre_group')) ? eval($hook) : null; ?>
            <div class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
<?php ($hook = get_hook('li_forgot_pass_pre_email')) ? eval($hook) : null; ?>
                <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
                    <div class="sf-box text required">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_login['E-mail address'] ?> <em><?php echo $lang_common['Required'] ?></em></span> <small><?php echo $lang_login['E-mail address help'] ?></small></label><br />
                        <span class="fld-input"><input id="fld<?php echo $forum_page['fld_count'] ?>" type="text" name="req_email" value="<?php echo isset($_POST['req_email']) ? forum_htmlencode($_POST['req_email']) : '' ?>" size="35" maxlength="80" /></span>
                    </div>
                </div>
<?php ($hook = get_hook('li_forgot_pass_pre_group_end')) ? eval($hook) : null; ?>
            </div>
<?php ($hook = get_hook('li_forgot_pass_group_end')) ? eval($hook) : null; ?>
            <div class="frm-buttons">
                <span class="submit"><input type="submit" name="request_pass" value="<?php echo $lang_login['Submit password request'] ?>" /></span>
                <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" /></span>
            </div>
        </form>
    </div>
<?php

    ($hook = get_hook('li_forgot_pass_end')) ? eval($hook) : null;

    $tpl_temp = forum_trim(ob_get_contents());
    $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
    ob_end_clean();
    // END SUBST - <!-- forum_main -->

    require FORUM_ROOT.'footer.php';
}

if (!$forum_user['is_guest'])
    header('Location: '.forum_link($forum_url['index']));

// Setup form
$forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
$forum_page['form_action'] = forum_link($forum_url['login']);

$forum_page['hidden_fields'] = array(
    'form_sent'        => '<input type="hidden" name="form_sent" value="1" />',
    'redirect_url'    => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_user['prev_url']).'" />',
    'csrf_token'    => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);

// Setup breadcrumbs
$forum_page['crumbs'] = array(
    array($forum_config['o_board_title'], forum_link($forum_url['index'])),
    array(sprintf($lang_login['Login info'], $forum_config['o_board_title']), forum_link($forum_url['login']))
);

($hook = get_hook('li_login_pre_header_load')) ? eval($hook) : null;

define('FORUM_PAGE', 'login');
require FORUM_ROOT.'header.php';

// START SUBST - <!-- forum_main -->
ob_start();

($hook = get_hook('li_login_output_start')) ? eval($hook) : null;

?>
    <div class="main-head">
        <h2 class="hn"><span><?php echo sprintf($lang_login['Login info'], $forum_config['o_board_title']) ?></span></h2>
    </div>
    <div class="main-content main-frm">
        <div class="content-head">
            <p class="hn"><?php printf($lang_login['Login options'], '<a href="'.forum_link($forum_url['register']).'">'.$lang_login['register'].'</a>', '<a href="'.forum_link($forum_url['request_password']).'">'.$lang_login['Obtain pass'].'</a>') ?></p>
        </div>
<?php

    // If there were any errors, show them
    if (!empty($errors))
    {
        $forum_page['errors'] = array();
    foreach ($errors as $cur_error)
            $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';

        ($hook = get_hook('li_pre_login_errors')) ? eval($hook) : null;

?>
        <div class="ct-box error-box">
            <h2 class="warn hn"><?php echo $lang_login['Login errors'] ?></h2>
            <ul class="error-list">
                <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
            </ul>
        </div>
<?php

    }

?>
        <div id="req-msg" class="req-warn ct-box error-box">
            <p class="important"><?php printf($lang_common['Required warn'], '<em>'.$lang_common['Required'].'</em>') ?></p>
        </div>
        <form id="afocus" class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
            <div class="hidden">
                <?php echo implode("\n\t\t\t\t", $forum_page['hidden_fields'])."\n" ?>
            </div>
<?php ($hook = get_hook('li_login_pre_login_group')) ? eval($hook) : null; ?>
            <div class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
<?php ($hook = get_hook('li_login_pre_username')) ? eval($hook) : null; ?>
                <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
                    <div class="sf-box text required">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_login['Username'] ?> <em><?php echo $lang_common['Required'] ?></em></span></label><br />
                        <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_username" value="<?php echo isset($_POST['req_username']) ? forum_htmlencode($_POST['req_username']) : '' ?>" size="35" maxlength="25" /></span>
                    </div>
                </div>
<?php ($hook = get_hook('li_login_pre_pass')) ? eval($hook) : null; ?>
                <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
                    <div class="sf-box text required">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_login['Password'] ?> <em><?php echo $lang_common['Required'] ?></em></span></label><br />
                        <span class="fld-input"><input type="password" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_password" value="<?php echo isset($_POST['req_password']) ? forum_htmlencode($_POST['req_password']) : '' ?>" size="35" /></span>
                    </div>
                </div>
<?php ($hook = get_hook('li_login_pre_remember_me_checkbox')) ? eval($hook) : null; ?>
                <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
                    <div class="sf-box checkbox">
                        <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="save_pass" value="1" /></span>
                        <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_login['Remember me'] ?></span> <?php echo $lang_login['Persistent login'] ?></label>
                    </div>
                </div>
<?php ($hook = get_hook('li_login_pre_group_end')) ? eval($hook) : null; ?>
            </div>
<?php ($hook = get_hook('li_login_group_end')) ? eval($hook) : null; ?>
            <div class="frm-buttons">
                <span class="submit"><input type="submit" name="login" value="<?php echo $lang_login['Login'] ?>" /></span>
            </div>
        </form>
    </div>
<?php

($hook = get_hook('li_end')) ? eval($hook) : null;

$tpl_temp = forum_trim(ob_get_contents());
$tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <!-- forum_main -->

require FORUM_ROOT.'footer.php';

there must be some easy way to put login on frontpage - not rocket science is it big_smile

5 (edited by KeyDog 2009-01-24 18:55)

Re: [Mod] Style - Login Box on Frontpage

<?php

// Show login if not logged in
if($forum_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php';
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($forum_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

    $required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_common['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_common['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_common['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

tried this login.php  in include/user  - but it spits out error:
Notice: Undefined index: Password in

on line 16 and 26 

it does show the boxes on my frontpage - but not quite there yet....

Re: [Mod] Style - Login Box on Frontpage

All you need is a form that will serve just like the one on 'login.php'.

You to pass these variables through POST:

  • form_sent = 1

  • redirect_url = forum_link($forum_url['index'])

  • csrf_token = generate_form_token(forum_link($forum_url['login']))

  • reg_username = {username}

  • req_password = {password}

  • save_pass (stay logged in) = 1 or 0

I guess that's it.

Re: [Mod] Style - Login Box on Frontpage

hm thanks.

but in practical terms for my file?

you'd build a new one based on those variables?
or are there 2-3 things i can change in the above pasted include/user/login.php

?

thx

Re: [Mod] Style - Login Box on Frontpage

Just build a new one.

Re: [Mod] Style - Login Box on Frontpage

nearly got it. this shows login without any errors now. BUT I get error when I try to login: that it can't confirm security token.
where do I need to put that in - or change what if any ideas? appreciate it...

<?php

// Show login if not logged in
if($forum_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php';
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($forum_config['o_board_title']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

    $required_fields = array('req_username' => $lang_login['Username'], 'req_password' => $lang_login['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_login['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_login['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_login['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

10 (edited by KeyDog 2009-01-24 22:24)

Re: [Mod] Style - Login Box on Frontpage

<?php

// Show login if not logged in
if($forum_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php';
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($forum_config['o_board_title']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

    $required_fields = array('req_username' => $lang_login['Username'], 'req_password' => $lang_login['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($forum_page['form_action']) ?>" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_login['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_login['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_login['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

added the token line big_smile

seems to work!

EDIT: NOT  - still token trouble...

Unable to confirm security token. A likely cause for this is that some time passed between when you first entered the page and when you submitted a form or clicked a link. If that is the case and you would like to continue with your action, please click the Confirm button. Otherwise, you should click the Cancel button to return to where you were.

11 (edited by User33 2009-01-24 23:17)

Re: [Mod] Style - Login Box on Frontpage

Of course it doesn't work. This:

$forum_page['form_action']

is not set. Use this instead

forum_link($forum_url['login'])

12

Re: [Mod] Style - Login Box on Frontpage

same result
http://punbb-a.keydogbb.info   

same error as before

13

Re: [Mod] Style - Login Box on Frontpage

Can I see the code?

14

Re: [Mod] Style - Login Box on Frontpage

sure thanks

<?php


// Show login if not logged in
if($forum_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php';
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';



    $required_fields = array('req_username' => $lang_login['Username'], 'req_password' => $lang_login['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="save_pass" value="1" />
                    <input type="hidden" name="csrf_token" value="<?php echo generate_form_token(forum_link($forum_url['login'])) ?>" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_login['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_login['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_login['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

this is what I am using.

thx for looking.

15 (edited by User33 2009-01-27 16:11)

Re: [Mod] Style - Login Box on Frontpage

Use

<?php echo forum_link($forum_url['login']); ?>

on the form action and see if that works.

16 (edited by KeyDog 2009-01-27 16:33)

Re: [Mod] Style - Login Box on Frontpage

thanks. that gives me
undefined variable   redirect_url    in /include/user/login.php

put in that code you gave in action=" yourcode    "

also this error

<br%20/><b>Notice</b>
:%20%20Undefined%20var20<b>25</b><br%20/>?login=1

any ideas?

17

Re: [Mod] Style - Login Box on Frontpage

Try again. I edited my post like 10 seconds after I posted it.

18 (edited by KeyDog 2009-01-27 17:08)

Re: [Mod] Style - Login Box on Frontpage

following thing is happen:

I enter log in details

I see REDIRECTING page aka successfully logged in

but then it sends me to some page that doesn't exist

with the errors described above in the url bar

and the page displaying

object not found


EDIT:
.keydogbb.info/<br%20/><b>Notice</b>:%20%20Undefined%20variable:%20redirect_url%20in%20<b>etc in the url bar...

19 (edited by KeyDog 2009-01-27 17:27)

Re: [Mod] Style - Login Box on Frontpage

// Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($forum_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

I had taken out this code (from the original mod) stupidly - well it was given me errors (but as shown in the code posted to you)

What does it need to be  - http_referer doesn't work does it?

20

Re: [Mod] Style - Login Box on Frontpage

forum_htmlencode($forum_user['prev_url'])

That would be it.

21

Re: [Mod] Style - Login Box on Frontpage

HALLELUJA big_smile

haha


<?php


// Show login if not logged in
if($forum_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php';
    require FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.forum_htmlencode($forum_user['prev_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

    
    $required_fields = array('req_username' => $lang_login['Username'], 'req_password' => $lang_login['Password']);

?>
        <div class="logintop">
            <form id="login" name="login" name="qpost" method="post" action="<?php echo forum_link($forum_url['login']); ?>" onsubmit="return process_form(this)">
                <p>
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="save_pass" value="1" />
                    <input type="hidden" name="csrf_token" value="<?php echo generate_form_token(forum_link($forum_url['login'])) ?>" />
                    <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                    <?php echo $lang_login['Username'] ?>:
                    <input type="text" name="req_username" size="16" maxlength="25" />
                    &nbsp;<?php echo $lang_login['Password'] ?>:

                    <input type="password" name="req_password" size="16" maxlength="16" wrap="virtual" onkeypress="if(event.keyCode==13) document.login.submit()" />
                    &nbsp;<a href="#" onclick="document.login.submit(); return true"><?php echo $lang_login['Login'] ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register.php"><?php echo $lang_common['Register'] ?></a>
                </p>
            </form>
        </div>
<?php
    }
}
?>

it works.

anything else strike you  that could give grief - let me know garcia

22

Re: [Mod] Style - Login Box on Frontpage

You should make this an extension or a 1-step cut-and-paste mod.

23

Re: [Mod] Style - Login Box on Frontpage

=========================================================================
##
##        Mod title:  Add a login box above header
##
##      Mod version:  1.0.0
##   Works on PunBB:  1.3.2
##     Release date:  27-JAN-2009
##           Author:  Orginal made by Artic Chill for 1.2.x,
##                    Mod by KeyDog/Garciat for 1.3
##
##      Description:  This mod adds a login box on index page
##                    You are free to place it where you require in :
##
##    Affected file:  include/template/main.tpl
##
##
##   Included Files:  include/user/login.php
##

Download
========================================================================

Rapidshare ZIP

Mediafire ZIP


Bugs
========================================================================

please report here


Demo
========================================================================

Here

========================================================================


Feedback Welcome


========================================================================

24 (edited by KeyDog 2009-01-27 18:56)

Re: [Mod] Style - Login Box on Frontpage

hm can this topic be moved to additions?
or shall i start new one?


Garciat wrote:

You should make this an extension or a 1-step cut-and-paste mod.

Can one make it an extension seeing as it affects main.tpl?
Kind of thing 2.0 will need to be able to do for sure....!

25 (edited by KeyDog 2009-01-28 12:05)

Re: [Mod] Style - Login Box on Frontpage

@garciat

could this approach be used to make the mods "login on frontpage" and also your "users online" work via extension + change to main.tpl?

Reines wrote:

You could add a new section inside the template (include/template/main.tpl), place something like <!-- forum_newthing --> where you want to add new content, then in your hook do something like:

<hook id="ft_end"><![CDATA[
    ob_start();

    require_once $ext_info['path'].'/hook_ft_end.php';

    $tpl_temp = forum_trim(ob_get_contents());
    $tpl_main = str_replace('<!-- forum_newthing -->', $tpl_temp, $tpl_main);
    ob_end_clean();
]]></hook>

Edit: Since that requires editing the template you can simple edit the one in include/template/main.tpl, but if you'd rather you could make use of the hd_pre_template_loaded hook to load a template from your extension directory instead of the default one.

part of quotes from:
http://fluxbb.org/forums/topic/2592/hoo … t-problem/