Go Back   vBulletin Setup > vBulletinSetup Information > Troubleshooting vBulletin Problems

Reply 
 
LinkBack Thread Tools Display Modes
Old 06-03-2009, 12:03 AM   #1
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Not logging new member in via email link

Hi,
Im new to coding and stumbled across a problem with a mod ive released and was hoping someone might be able to assist.

Its a welcome thread mod (creates a thread when a new member registers.) It works great if email verification is turned off, however I run into some issues when its turned on.

Member 1 registers and is logged in. Member 1 receives email and verifies email address whilst logged in still - thread is created with the members username in the title.

Member 2 registers and logs off

Member 3 registers and logs off

Member 2 receives email and clicks on link to verify email address. The "Congratulations etc etc, you may now edit your profile etc" message is posted, however the member is not automatically logged in. They have to put in there username and password.
This seems to be creating an issue, because the member is not actually logged in when they verify their email address, the welcome thread message displays "Our new member - Unregistered"

I thought I was doing well creating my first mod, but im pulling my hair out now over this problem! Any help and advice to solve this would be greatly appreciated!
powerful_rogue is offline   Reply With Quote

Advertisement [Remove Advertisement]

Old 06-03-2009, 10:08 AM   #2
vBulletin Owner
 
Join Date: Jun 2009
Posts: 19
Wayne Luke is a jewel in the rough
Re: Not logging new member in via email link

Sounds like it is relying on cookies. The email address for verifying new members does not log in the user when they click the link. They would only be shown as logged in if they have the appropriate cookies as well as a valid session or Remember Me checked.

Unfortunately there isn't an easy way around this because of how vBulletin's login procedure works. If the modification, use the hash from the User Activation to get the userid out of the databse, that would probably work better. As I haven't looked at the code or the hooks that it uses, I am not sure how possible that is. I don't think it is impossible though.
__________________
Wayne Luke
Take vBulletin to the next level - vBCodex. Find Tips, Tutorials, and Resources.
Wayne Luke is offline   Reply With Quote
Old 06-03-2009, 11:26 AM   #3
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Hi Wayne,

Thanks for your reply. Ive had a look at the vbulletin database and there is a table called "useractivation"





Its just trying to work out a way to use the details and place them into the mod, so that when the member clicks on the email link, it will place their username in the thread title rather then using "unregistered"
powerful_rogue is offline   Reply With Quote
Old 06-03-2009, 12:04 PM   #4
vBulletin Owner
 
Join Date: Jun 2009
Posts: 19
Wayne Luke is a jewel in the rough
Re: Not logging new member in via email link

SELECT userid, username FROM useractivation LEFT JOIN user ON (useractivation.userid = user.userid) WHERE activationid = XXXX AND emailchange=0;

So you're hook needs to watch for the activationid coming in via the URL and then run the above query. That will get you the username in your results array... You can then use the thread Data Manager to create a new thread in the appropriate forum.
__________________
Wayne Luke
Take vBulletin to the next level - vBCodex. Find Tips, Tutorials, and Resources.
Wayne Luke is offline   Reply With Quote
Old 06-03-2009, 01:41 PM   #5
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Quote:
Originally Posted by Wayne Luke View Post
SELECT userid, username FROM useractivation LEFT JOIN user ON (useractivation.userid = user.userid) WHERE activationid = XXXX AND emailchange=0;

So you're hook needs to watch for the activationid coming in via the URL and then run the above query. That will get you the username in your results array... You can then use the thread Data Manager to create a new thread in the appropriate forum.
Hi Wayne and many thanks for your reply.
This is the code im currently using to deal with the thread being created after email verification using the register_process_complete hook.

PHP Code:
<plugin active="1">
            <
title>welcome thread upon registration</title>
            <
hookname>register_activate_process</hookname>
            <
phpcode><![CDATA[if ($vbulletin->options['wtur_active'] AND $vbulletin->options['wtur_activewhen'] == 0)
            {
    
    
// Backend Files
    
require_once('./global.php');
    require_once(
'./includes/class_dm.php');
    require_once(
'./includes/class_dm_threadpost.php');
    require_once(
'./includes/functions_databuild.php');

$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
$foruminfo fetch_foruminfo($foruminfo['forumid']);
$threadinfo = array();
$vboptions =& $vbulletin->options;
$bbuserinfo    =& $vbulletin->userinfo
$username htmlspecialchars_uni($vbulletin->userinfo['username']);  
$forumid $vbulletin->options['wtur_fid'];
eval(
'$title1 = "' addslashes($vbulletin->options['wtur_title1']) . '";');  
eval(
'$title2 = "' addslashes($vbulletin->options['wtur_title2']) . '";');
eval(
'$title3 = "' addslashes($vbulletin->options['wtur_title3']) . '";');
eval(
'$title4 = "' addslashes($vbulletin->options['wtur_title4']) . '";');
$title = array("$title1""$title2""$title3""$title4");
$rand_title array_rand($title4);
$wtur_userids_get explode(","$vbulletin->options['wtur_postinguserid']);
$wtur_userids $wtur_userids_get[array_rand($wtur_userids_get)];
$wtur_userid fetch_userinfo($wtur_userids);
eval(
'$pagetext1 = "' addslashes($vbulletin->options['wtur_content1']) . '";');
eval(
'$pagetext2 = "' addslashes($vbulletin->options['wtur_content2']) . '";');
eval(
'$pagetext3 = "' addslashes($vbulletin->options['wtur_content3']) . '";');
eval(
'$pagetext4 = "' addslashes($vbulletin->options['wtur_content4']) . '";');
$pagetext = array("$pagetext1""$pagetext2""$pagetext3""$pagetext4");
$rand_text array_rand($pagetext4);
$wtur_posticons_get explode(","$vbulletin->options['wtur_posticon']);
$wtur_posticons $wtur_posticons_get[array_rand($wtur_posticons_get)];
$allowsmilie '1';
$visible $vbulletin->options['wtur_moderate'];

$threaddm->set_info('forum'$foruminfo);
$threaddm->set_info('thread'$threadinfo);
$threaddm->setr('forumid'$forumid);
$threaddm->setr('userid'$wtur_userid['userid']);
$threaddm->setr('pagetext'$pagetext[$rand_text[0]]);
$threaddm->setr('title'$title[$rand_title[0]]);
$threaddm->set('iconid'$wtur_posticons['iconid']);
$threaddm->set('allowsmilie'$allowsmilie);
$threaddm->set('visible'$visible);


$threaddm->pre_save();
if(
count($threaddm->errors) < 1)
{
    
$threadid $threaddm->save();
    unset(
$threaddm);
    
build_thread_counters($threaddm);
}
 
build_forum_counters($forumid);
 
 
// update post count for user
    
$posts $vbulletin->db->query_first("
        SELECT posts
        FROM " 
TABLE_PREFIX "user
        WHERE userid = "
.$wtur_userid['userid']."
    "
);
    
    
$newpostcount $posts['posts'] + 1;
    
    
$vbulletin->db->free_result($posts);
    
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET posts = "
.$newpostcount."
        WHERE userid = "
.$wtur_userid['userid']."
    "
);  
 
 ]]>}</
phpcode>
        </
plugin>        
    </
plugins
Am I right in thinking the code would go just prior to the
PHP Code:
$threaddm->set_info('forum'$foruminfo); 
section?

With
PHP Code:
WHERE activationid XXXX 
would that automatically populate, or would I need to do something with that?

At the moment I can see the theory, but being new im struggling to work out how to place it together. Your help so far is really appreciated though.
powerful_rogue is offline   Reply With Quote
Old 06-03-2009, 04:23 PM   #6
vBulletin Owner
 
Join Date: Jun 2009
Posts: 19
Wayne Luke is a jewel in the rough
Re: Not logging new member in via email link

So... I am a little confused. Where are you pulling the user's userid?

I see this code here:
Code:
$wtur_userids_get = explode(",", $vbulletin->options['wtur_postinguserid']);
$wtur_userids = $wtur_userids_get[array_rand($wtur_userids_get)];
$wtur_userid = fetch_userinfo($wtur_userids);
That looks like its pulling from a pre-determined array stored in a setting.

You should run a check before this:
Code:
$username = htmlspecialchars_uni($vbulletin->userinfo['username']);
If $bbuserinfo doesn't contain a username e.g. its a guest user, then run the query to get the user information based on the Activation ID provided above. Can make is simpler and just pull the userid and feed that into fetch_user_info() and use that array in the rest of your plugin.
__________________
Wayne Luke
Take vBulletin to the next level - vBCodex. Find Tips, Tutorials, and Resources.

Last edited by Wayne Luke; 06-03-2009 at 04:29 PM.
Wayne Luke is offline   Reply With Quote
Old 06-03-2009, 08:44 PM   #7
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Quote:
Originally Posted by Wayne Luke View Post
So... I am a little confused. Where are you pulling the user's userid?

I see this code here:
Code:
$wtur_userids_get = explode(",", $vbulletin->options['wtur_postinguserid']);
$wtur_userids = $wtur_userids_get[array_rand($wtur_userids_get)];
$wtur_userid = fetch_userinfo($wtur_userids);
That looks like its pulling from a pre-determined array stored in a setting.
This piece of code relates to the UserID of the member pre-defined in the ACP who the thread will be created by. Ive set it so that if you enter a variety of UserID's - It would randomly pick one.


Quote:
You should run a check before this:
Code:
$username = htmlspecialchars_uni($vbulletin->userinfo['username']);
Ive added that into the code now. I didnt realise code needed to be sanitised before.

Quote:
If $bbuserinfo doesn't contain a username e.g. its a guest user, then run the query to get the user information based on the Activation ID provided above. Can make is simpler and just pull the userid and feed that into fetch_user_info() and use that array in the rest of your plugin.
The only reason ive got
PHP Code:
$bbuserinfo    =& $vbulletin->userinfo
in the code is so members can link the members profile to their username in the thread text. Is their an additional variable I would be able to use?

Was I right in saying that the query would go prior to the thread create function?

Also in relation to
PHP Code:
WHERE activationid XXXX 
would I need to have a variable before hand to somehow grab the activiationid? If so, how would I be able to place the activationid in the variable?

PHP Code:
$useractivation 
PHP Code:
WHERE activationid "$useractivation" 

Last edited by powerful_rogue; 06-04-2009 at 05:55 AM.
powerful_rogue is offline   Reply With Quote
Old 06-04-2009, 08:56 AM   #8
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Ive been having a little play around using the below query

PHP Code:
$username $db->query_first("
SELECT userid, username 
FROM useractivation 
LEFT JOIN user ON (useractivation.userid = user.userid) 
WHERE activationid = '" 
$db->escape_string($vbulletin->GPC['i']) . "'
AND emailchange=0;
    "
); 
However when a member clicks on the link in the email it throws a database error

Invalid SQL:

PHP Code:
SELECT useridusername
FROM useractivation
LEFT JOIN user ON 
(useractivation.userid user.useridWHERE activationid 'dba13005e074c04398289d78d93e6dac91c2af3f'
AND emailchange=0;;

MySQL Error   Column 'userid' in field list is ambiguous
Error Number  
1052 
It does however bring up the correct activationid for that user.
powerful_rogue is offline   Reply With Quote
Old 06-04-2009, 09:04 AM   #9
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Managed to solve the error by changing

PHP Code:
SELECT useridusername 
to

PHP Code:
SELECT useractivation.useridusername 
After a member verifies their email its now showing

" has joined the forum" instead of "Unregistered has joined the forum"
but its not placing their username into the title.
powerful_rogue is offline   Reply With Quote
Old 06-04-2009, 07:18 PM   #10
vBulletin Owner
 
Join Date: Jun 2009
Posts: 19
Wayne Luke is a jewel in the rough
Re: Not logging new member in via email link

Right because $vbulletin->userinfo[] has an empty username as they are a guest. You need to run a check on $vbulletin->userinfo['username']. If it does not have a username than you would use the value from this query:
Code:
$username = $db->query_first("
SELECT useractivation.userid, username 
FROM useractivation 
LEFT JOIN user ON (useractivation.userid = user.userid) 
WHERE activationid = '" . $db->escape_string($vbulletin->GPC['i']) . "'
AND emailchange=0;
    ");
Or $username['username']

$subjectname = $vbulletin->userinfo['username'] != '' ? $vbulletin->userinfo['username'] : $username['username'];

Roughly.
__________________
Wayne Luke
Take vBulletin to the next level - vBCodex. Find Tips, Tutorials, and Resources.

Last edited by Wayne Luke; 06-04-2009 at 07:21 PM.
Wayne Luke is offline   Reply With Quote
Old 06-06-2009, 08:07 AM   #11
vBulletin Owner
 
Join Date: Mar 2008
Posts: 26
powerful_rogue will become famous soon enough
Re: Not logging new member in via email link

Quote:
Originally Posted by Wayne Luke View Post
Right because $vbulletin->userinfo[] has an empty username as they are a guest. You need to run a check on $vbulletin->userinfo['username']. If it does not have a username than you would use the value from this query:
Code:
$username = $db->query_first("
SELECT useractivation.userid, username 
FROM useractivation 
LEFT JOIN user ON (useractivation.userid = user.userid) 
WHERE activationid = '" . $db->escape_string($vbulletin->GPC['i']) . "'
AND emailchange=0;
    ");
Or $username['username']

$subjectname = $vbulletin->userinfo['username'] != '' ? $vbulletin->userinfo['username'] : $username['username'];

Roughly.
Hi Wayne,

I get the logic behind this, but struggling a bit at the moment to work out how to code it.

Would the below SQL query do the same as the one you posted

PHP Code:
$wturid $db->query_first("
SELECT userid 
FROM useractivation 
WHERE activationid = '" 
$db->escape_string($vbulletin->GPC['i']) . "'
AND emailchange=0;
    "
);

$username $db->query_first("
SELECT username 
FROM user 
WHERE userid = $wturid['userid'] 
    "
); 
The first query gets the UserID based on th activation id of the email. The second query that compares the first UserID with those in the User table and gets the username.

Im guessing it will all need to be placed inside and <if> statement, but what would the statement be?

Ive tried the following:

PHP Code:
$username $db->query_first("
SELECT useractivation.userid, username 
FROM useractivation 
LEFT JOIN user ON (useractivation.userid = user.userid) 
WHERE activationid = '" 
$db->escape_string($vbulletin->GPC['i']) . "'
AND emailchange=0;
    "
);

$subjectname $vbulletin->userinfo['username'] != '' $vbulletin->userinfo['username'] : $username['username']; 
however the output is still coming up as "Unregistered"

I feel im getting so close now!

Last edited by powerful_rogue; 06-06-2009 at 08:22 AM.
powerful_rogue is offline   Reply With Quote
Reply 
vBulletin Setup > vBulletinSetup Information > Troubleshooting vBulletin Problems

Tags
email, link, logging, member

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Members having trouble logging in??? Sweetnkky Troubleshooting vBulletin Problems 3 10-13-2008 09:04 AM
Sending an email to every member? glennybee Troubleshooting vBulletin Problems 14 08-25-2008 12:54 PM
Premium Member, Plus Member or Subscriber, etc. LinkBliss Community Forum Management 7 07-23-2008 08:13 AM
Logging in Anorak Feedback and Suggestions 10 12-12-2006 06:38 PM
Logging on joh Troubleshooting vBulletin Problems 2 12-06-2006 10:51 PM


All times are GMT -8. The time now is 03:24 AM.