Account activation logic problem
#1
I am trying to create a pm on registration plugin that doesn't require you to alter the permissions for "awaiting activation" group.

There is a hook in member.php:

member_activate_accountactivated

However the problem is that in my plugin the user permissions still display group 5 when in fact the user should at that point be in group 2 (registered). So my PMs aren't passing validation.

This is driving me nuts as the logic appears fine.

Here is the action from member.php:

elseif($mybb->input['action'] == "activate")
{
	$plugins->run_hooks("member_activate_start");

	if($mybb->input['username'])
	{
		$query = $db->simple_select(TABLE_PREFIX."users", "*", "LOWER(username)='".$db->escape_string(my_strtolower($mybb->input['username']))."'");
		$user = $db->fetch_array($query);
		if(!$user['username'])
		{
			error($lang->error_invalidusername);
		}
		$uid = $user['uid'];
	}
	else
	{
		$query = $db->simple_select(TABLE_PREFIX."users", "*", "uid='".intval($mybb->input['uid'])."'");
		$user = $db->fetch_array($query);
	}
	if($mybb->input['code'] && $user['uid'])
	{
		$mybb->settings['awaitingusergroup'] = "5";
		$query = $db->simple_select(TABLE_PREFIX."awaitingactivation", "*", "uid='".$user['uid']."' AND (type='r' OR type='e')");
		$activation = $db->fetch_array($query);
		if(!$activation['uid'])
		{
			error($lang->error_alreadyactivated);
		}
		if($activation['code'] != $mybb->input['code'])
		{
			error($lang->error_badactivationcode);
		}
		$db->delete_query(TABLE_PREFIX."awaitingactivation", "uid='".$user['uid']."' AND (type='r' OR type='e')");
		if($user['usergroup'] == 5 && $activation['type'] != "e")
		{
			$newgroup = array(
				"usergroup" => 2,
				);
			$db->update_query(TABLE_PREFIX."users", $newgroup, "uid='".$user['uid']."'");
		}
		if($activation['type'] == "e")
		{
			$newemail = array(
				"email" => $db->escape_string($activation['misc']),
				);
			$db->update_query(TABLE_PREFIX."users", $newemail, "uid='".$user['uid']."'");
			if(function_exists("emailChanged"))
			{
				emailChanged($mybb->user['uid'], $email);
			}

			$plugins->run_hooks("member_activate_emailupdated");

			redirect("usercp.php", $lang->redirect_emailupdated);
		}
		else
		{
			if(function_exists("accountActivated") && $activation['type'] == "r")
			{
				accountActivated($user['uid']);
			}

			$plugins->run_hooks("member_activate_accountactivated");

			redirect("index.php", $lang->redirect_accountactivated);
		}
	}
	else
	{
		$plugins->run_hooks("member_activate_form");

		eval("\$activate = \"".$templates->get("member_activate")."\";");
		output_page($activate);
	}

Here is my plugin function:

function pmonreg()
{
	global $mybb, $db, $user;

	if($mybb->settings['pmonreg_enable'] == "on")
	{
		require_once MYBB_ROOT."inc/datahandlers/pm.php";
	
		$pmhandler = new PMDataHandler();

        $pm = array(
            "subject" => $mybb->settings['pmonreg_subject'],
            "message" => str_replace('{username}', $user['username'], $mybb->settings['pmonreg_message']),
            "icon" => -1,
            "fromid" => intval($mybb->settings['pmonreg_send_uid']),
            "toid" => intval($user['uid']),
            "do" => '',
            "pmid" => ''
        );

	
        $pm['options'] = array(
	    "savecopy" => "no",
            "saveasdraft" => 0,
            "signature" => "no",
            "disablesmilies" => "no",
        );

		$pm['saveasdraft'] = 0;
		$pmhandler->admin_override = 1;
		$pmhandler->set_data($pm);

		if($pmhandler->validate_pm())
		{
			$pmhandler->insert_pm();

		}
	}
}

It's getting tiring trying dozens of things to no effect. Any help is appreciated. I ain't that great with OOP yet.
Reply
#2
I haven't looked, but:
Quote:However the problem is that in my plugin the user permissions still display group 5 when in fact the user should at that point be in group 2 (registered).
The reason is because I don't think that piece of code updates the cached version of the user (only the DB).
Reply
#3
There is a cached version of users? I was trying to find if someone was cached somewhere.

I have to go back to the code then. Do you know how I would update that cache in my functions sir?
Reply
#4
Again, haven't checked, but I'd imagine:
$mybb->user['usergroup'] = 5; // send cached user to the new group

// update $mybb->usergroup
global $groupscache, $cache;
if(!is_array($groupscache)) $groupscache = $cache->read('usergroups');
$mybb->usergroup = &$groupscache[$mybb->user['usergroup']];

Hope that helps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)