Autologin Upon Registration problem

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

Hello,

I discovered Autologin Upon Registration MOD today, installed it, liked and discovered an incompatibility problem with my Welcome PM on First Login MOD.

This last MOD shows a PM popup on a new member´s first login on my board, adverting of the Welcome PM I prepared for him/her. This popup isn´t shown when a new user logs on through the email activation link. It will show up when the user logs out and returns the next visit. Not a big problem really, but it´s agravated a bit because I have the log me on automatically always set to yes in the usercp_register.php. Which means that if the new user doesn´t log out but just leaves the board he won´t have a pm popup on the next visit because he was still logged in.

The question is:
What can be done to get the pm popup back working even if user logs on through the email activation link.

At first I thought the problem lies in usercp_register.php but now I think it is because login.php isn´t used to connect the user. In logn.php there´s this modification

Code: Select all

#
#-----[ OPEN ]------------------------------------------
#
login.php

#
#-----[ FIND ]------------------------------------------
#

<?php

#
#-----[ AFTER, ADD ]------------------------------------------
#

// This file modified for Welcome PM on First Login 1.0.3

#
#-----[ FIND ]------------------------------------------
#

					if( $session_id )
					{

#
#-----[ AFTER, ADD ]------------------------------------------
#

//------------------------------------------------------------------------------
// Welcome PM on First Login - Begin Code Alteration
//
						include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
//
// Welcome PM on First Login - End Code Alteration
//------------------------------------------------------------------------------
I attach a zip with the MOD, and the autologinPM addon.

I hope this is an easy one for you, I don´t want to make your life hard. :)

Thanks op front for your interest.

Greetings.
Attachments
Welcome_PM.rar
(49.95 KiB) Downloaded 290 times
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hi,

I don't use Winrar - would you be able to paste login.php and usercp_register.php within code tags within a post? Thanks :)

Welcome to the forum :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

I can zip it if you prefer.

But have a look first at
login.php

Code: Select all

<?php
// This file modified for Welcome PM on First Login 1.0.3
/***************************************************************************
 *                                login.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: login.php,v 1.47.2.23 2006/01/13 20:10:02 grahamje Exp $
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

//
// Allow people to reach login page if
// board is shut down
//
define("IN_LOGIN", true);

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Set page ID for session management
//
$userdata = session_pagestart($user_ip, PAGE_LOGIN);
init_userprefs($userdata);
//
// End session management
//

// session id check
if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
{
	$sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
}
else
{
	$sid = '';
}

if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
{
	if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && (!$userdata['session_logged_in'] || isset($HTTP_POST_VARS['admin'])) )
	{
		$username = isset($HTTP_POST_VARS['username']) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
		$password = isset($HTTP_POST_VARS['password']) ? $HTTP_POST_VARS['password'] : '';

		$sql = "SELECT user_id, username, user_password, user_active, user_level, user_login_tries, user_last_login_try
			FROM " . USERS_TABLE . "
			WHERE username = '" . str_replace("\\'", "''", $username) . "'";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
		}

		if( $row = $db->sql_fetchrow($result) )
		{
			if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
			{
				redirect(append_sid("index.$phpEx", true));
			}
			else
			{
				// If the last login is more than x minutes ago, then reset the login tries/time
				if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $row['user_last_login_try'] < (time() - ($board_config['login_reset_time'] * 60)))
				{
					$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);
					$row['user_last_login_try'] = $row['user_login_tries'] = 0;
				}
				
				// Check to see if user is allowed to login again... if his tries are exceeded
				if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $board_config['max_login_attempts'] && 
					$row['user_last_login_try'] >= (time() - ($board_config['login_reset_time'] * 60)) && $row['user_login_tries'] >= $board_config['max_login_attempts'] && $userdata['user_level'] != ADMIN)
				{
					message_die(GENERAL_MESSAGE, sprintf($lang['Login_attempts_exceeded'], $board_config['max_login_attempts'], $board_config['login_reset_time']));
				}

				if( md5($password) == $row['user_password'] && $row['user_active'] )
				{
					$autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;

					$admin = (isset($HTTP_POST_VARS['admin'])) ? 1 : 0;
					$session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin, $admin);

					// Reset login tries
					$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);

					if( $session_id )
					{
//------------------------------------------------------------------------------
// Welcome PM on First Login - Begin Code Alteration
//
						include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
//
// Welcome PM on First Login - End Code Alteration
//------------------------------------------------------------------------------
						$url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
						redirect(append_sid($url, true));
					}
					else
					{
						message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
					}
				}
				// Only store a failed login attempt for an active user - inactive users can't login even with a correct password
				elseif( $row['user_active'] )
				{
					// Save login tries and last login
					if ($row['user_id'] != ANONYMOUS)
					{
						$sql = 'UPDATE ' . USERS_TABLE . '
							SET user_login_tries = user_login_tries + 1, user_last_login_try = ' . time() . '
							WHERE user_id = ' . $row['user_id'];
						$db->sql_query($sql);
					}
					
				}

				$redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : '';
				$redirect = str_replace('?', '&', $redirect);

				if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
				{
					message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
				}

				$template->assign_vars(array(
					'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
				);

				$message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

				message_die(GENERAL_MESSAGE, $message);

			}
		}
		else
		{
			$redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "";
			$redirect = str_replace("?", "&", $redirect);

			if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
			{
				message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
			}

			$template->assign_vars(array(
				'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
			);

			$message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

			message_die(GENERAL_MESSAGE, $message);
		}
	}
	else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
	{
		// session id check
		if ($sid == '' || $sid != $userdata['session_id'])
		{
			message_die(GENERAL_ERROR, 'Invalid_session');
		}

		if( $userdata['session_logged_in'] )
		{
			session_end($userdata['session_id'], $userdata['user_id']);
		}

		if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
		{
			$url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
			$url = str_replace('&', '&', $url);
			redirect(append_sid($url, true));
		}
		else
		{
			redirect(append_sid("index.$phpEx", true));
		}
	}
	else
	{
		$url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
		redirect(append_sid($url, true));
	}
}
else
{
	//
	// Do a full login page dohickey if
	// user not already logged in
	//
	if( !$userdata['session_logged_in'] || (isset($HTTP_GET_VARS['admin']) && $userdata['session_logged_in'] && $userdata['user_level'] == ADMIN))
	{
		// Start Guest See Only First Post by Wicher
		if ( isset($HTTP_GET_VARS[POST_DATA_URL]) )
		{
			//
			// Update the GSOFP login counter
			//
			$sql = "UPDATE " . GSOFP_TABLE . "
				SET GSOFP_logins = GSOFP_logins + 1";
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "Could not update GSOFP login counter.", '', __LINE__, __FILE__, $sql);
			}
		}
		// End Guest See Only First Post by Wicher
		
		$page_title = $lang['Login'];
		include($phpbb_root_path . 'includes/page_header.'.$phpEx);

		$template->set_filenames(array(
			'body' => 'login_body.tpl')
		);

		$forward_page = '';

		if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
		{
			$forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];

			if( preg_match("/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si", $forward_to, $forward_matches) )
			{
				$forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
				$forward_match = explode('&', $forward_to);

				if(count($forward_match) > 1)
				{
					for($i = 1; $i < count($forward_match); $i++)
					{
						if( !ereg("sid=", $forward_match[$i]) )
						{
							if( $forward_page != '' )
							{
								$forward_page .= '&';
							}
							$forward_page .= $forward_match[$i];
						}
					}
					$forward_page = $forward_match[0] . '?' . $forward_page;
					$forward_page = preg_replace("/\?".POST_DATA_URL."=/", "&".POST_DATA_URL."=", $forward_page);
					
				}
				else
				{
					$forward_page = $forward_match[0];
				}
			}
		}

		$username = ( $userdata['user_id'] != ANONYMOUS ) ? $userdata['username'] : '';

		$s_hidden_fields = '<input type="hidden" name="redirect" value="' . $forward_page . '" />';
		$s_hidden_fields .= (isset($HTTP_GET_VARS['admin'])) ? '<input type="hidden" name="admin" value="1" />' : '';

		make_jumpbox('viewforum.'.$phpEx);
		$template->assign_vars(array(
			'USERNAME' => $username,

			'L_ENTER_PASSWORD' => (isset($HTTP_GET_VARS['admin'])) ? $lang['Admin_reauthenticate'] : $lang['Enter_password'],
			'L_SEND_PASSWORD' => $lang['Forgotten_password'],
			'L_RESEND_ACTIVATION_EMAIL' => $lang['Resend_activation_email'],	// Resend Account Activation E-mail MOD

			'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
			'U_RESEND_ACTIVATION_EMAIL' => append_sid("request_actmail.$phpEx"),	// Resend Account Activation E-mail MOD

			'S_HIDDEN_FIELDS' => $s_hidden_fields)
		);
		if ( !isset($HTTP_GET_VARS['admin']) )
		{
			$template->assign_block_vars('switch_resend_activation_email_block', array() );
		}

		$template->pparse('body');

		include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
	}
	else
	{
		redirect(append_sid("index.$phpEx", true));
	}

}

?>
and usercp_register.php (in the next post because I exceeded the 60000caracter limit in one post. :oops:
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

Wow,

My usercp_register.php is too big to paste in one post,

Here it is as a .txt-file
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Okay, it looks like I will need to search through the source a bit more than I was expecting for this. I will have a look at this tomorrow :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

No problem Battye,

No hurry, just take a look when you can and feel like it. :wink:
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hmm, I misread your post :cry:

I thought the auto login wasn't working, no wonder I was stumped. So the auto login works but the PM doesn't display? Have you modified the file includes/page_header.php ... can you post it here in code tags (or as a .txt file on your site is fine too) :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

That´s what´s happening, the auto login works but the Welcome PM on first login through the activation link in the activation email don´t display. That Welcome PM displays on the next login through the login screen.

It´s a bit complicated

Here is my page_header.php and yes, it´s modified.

If you want to see what happens, PM me an email adress, I´ll create an account for you and you´ll receive the activation email.

Thanks so far, have a nice weekend. :)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I can see one obvious change in the PM area: print "<div id='CSSPM'><p class='alert'><font align='center' class='mainmenu' color=008080>Tienes un nuevo <a class='mainmenu' href='privmsg.php?folder=inbox'><b>Mensaje Privado</b>, click aquí para verlo.</a></font></p></div>";

And quite a few others. So yeah, the file has been heavily modified. Do you still get a message saying "You have 1 new private message". Or does neither that message or the box appear?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

When a new member enters the first time, through the now converted into autologin link in the activation email, no PM alert happens.

When that new member logs out and then logs in again the PM alert for the Welcome PM pops up.

I changed the PM box for a css pop up but I'd say that has nothing to do with the problem.

I believe the Autologin bypasses the login.php, and it´s in the login.php where the mods/wpm/login_wpm.php is called.

Code: Select all

    #
    #-----[ OPEN ]------------------------------------------
    #
    login.php

    #
    #-----[ FIND ]------------------------------------------
    #

    <?php

    #
    #-----[ AFTER, ADD ]------------------------------------------
    #

    // This file modified for Welcome PM on First Login 1.0.3

    #
    #-----[ FIND ]------------------------------------------
    #

                   if( $session_id )
                   {

    #
    #-----[ AFTER, ADD ]------------------------------------------
    #

    //------------------------------------------------------------------------------
    // Welcome PM on First Login - Begin Code Alteration
    //
                      include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
    //
    // Welcome PM on First Login - End Code Alteration
    //------------------------------------------------------------------------------
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Sorry, I'm unfamilar with that MOD. I assumed the PM process would be similar to a normal PM.

You'd be right, because it is bypassing login.php the call is not being made. Try adding it to page_header.php:

FIND in page_header.php

Code: Select all

//
// Smartor's Visit Counter MOD
//

BEFORE ADD:

Code: Select all

 if( $userdata['user_lastvisit'] == 0 )
{
include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
}


Does that help?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

That gives this error when I log out:

Code: Select all

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND user_id <> -1' at line 4

SELECT * FROM phpbb_users WHERE user_id = AND user_id <> -1

Line : 30
File : functions_wpm.php
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Ah, okay. Try this:

Instead of:

Code: Select all

 if( $userdata['user_lastvisit'] == 0 )
{
include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
}
Try

Code: Select all

 if( $userdata['user_lastvisit'] == 0 && $userdata['session_logged_in'] )
{
include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
}
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Dogs and things
Greenhorn
Greenhorn
Posts: 10
Joined: Wed Jan 23, 2008 3:30 pm

Thank you,

The error is gone,

But the Welcome PM doesn´t pop up on autologin through email activation llink. :cry:

It does pop up after logout on next login, which it considers that new user´s first login.
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Just to make sure it's including the file:

FIND

Code: Select all

if( $userdata['user_lastvisit'] == 0 && $userdata['session_logged_in'] )
{
include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
}
replace with

Code: Select all

if( $userdata['user_lastvisit'] == 0 && $userdata['session_logged_in'] )
{
include_once($phpbb_root_path . 'mods/wpm/login_wpm.' . $phpEx);
echo 'This works';
}
It should say "This works" with a lot of errors when you click the email link. Once you verify this, undo that change and the errors will go away :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Post Reply