Skip to content

Commit

Permalink
Consolidate members activation into approveMembers, including integra…
Browse files Browse the repository at this point in the history
…te_activate hook - fixes #2078

Signed-off-by: emanuele <emanuele45@gmail.com>
  • Loading branch information
emanuele45 committed Jul 27, 2015
1 parent edcf250 commit 1a4a375
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
7 changes: 0 additions & 7 deletions sources/admin/ManageMembers.controller.php
Expand Up @@ -1036,13 +1036,6 @@ public function action_approve()
// Approve / activate this member.
approveMembers($conditions);

// Do we have to let the integration code know about the activations?
if (!empty($modSettings['integrate_activate']))
{
foreach ($member_info as $member)
call_integration_hook('integrate_activate', array($member['username']));
}

// Check for email.
if ($_POST['todo'] == 'okemail')
{
Expand Down
8 changes: 3 additions & 5 deletions sources/controllers/ProfileAccount.controller.php
Expand Up @@ -520,19 +520,17 @@ public function action_activateaccount()

if (isset($_REQUEST['save']) && isset($user_profile[$memID]['is_activated']) && $user_profile[$memID]['is_activated'] != 1)
{
require_once(SUBSDIR . '/Members.subs.php');

// If we are approving the deletion of an account, we do something special ;)
if ($user_profile[$memID]['is_activated'] == 4)
{
require_once(SUBSDIR . '/Members.subs.php');
deleteMembers($context['id_member']);
redirectexit();
}

// Let the integrations know of the activation.
call_integration_hook('integrate_activate', array($user_profile[$memID]['member_name']));

// Actually update this member now, as it guarantees the unapproved count can't get corrupted.
updateMemberData($context['id_member'], array('is_activated' => $user_profile[$memID]['is_activated'] >= 10 ? 11 : 1, 'validation_code' => ''));
approveMembers(array('members' => array($context['id_member']), 'activated_status' => $user_profile[$memID]['is_activated']))

// Log what we did?
logAction('approve_member', array('member' => $memID), 'admin');
Expand Down
10 changes: 3 additions & 7 deletions sources/controllers/Register.controller.php
Expand Up @@ -589,7 +589,7 @@ public function action_register2($verifiedOpenID = false)
}
else
{
call_integration_hook('integrate_activate', array($regOptions['username']));
call_integration_hook('integrate_activate', array($regOptions['username'], 1, 1));

setLoginCookie(60 * $modSettings['cookieTime'], $memberID, hash('sha256', Util::strtolower($regOptions['username']) . $regOptions['password'] . $regOptions['register_vars']['password_salt']));

Expand Down Expand Up @@ -649,8 +649,6 @@ public function action_activate()
}

// Change their email address? (they probably tried a fake one first :P.)
require_once(SUBSDIR . '/Auth.subs.php');

if (isset($_POST['new_email'], $_REQUEST['passwd']) && validateLoginPassword($_REQUEST['passwd'], $row['passwd'], $row['member_name'], true) && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
{
if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
Expand Down Expand Up @@ -718,12 +716,10 @@ public function action_activate()

return;
}

// Let the integration know that they've been activated!
call_integration_hook('integrate_activate', array($row['member_name']));
require_once(SUBSDIR . '/Members.subs.php');

// Validation complete - update the database!
updateMemberData($row['id_member'], array('is_activated' => 1, 'validation_code' => ''));
approveMembers(array('members' => array($row['id_member'], array('activated_status' => 0)));

// Also do a proper member stat re-evaluation.
updateStats('member', false);
Expand Down
26 changes: 24 additions & 2 deletions sources/subs/Members.subs.php
Expand Up @@ -1978,13 +1978,29 @@ function approveMembers($conditions)
);

// @todo maybe an hook here?
$query_cond = array();
$query = false;
foreach ($conditions as $key => $dummy)
{
if (isset($available_conditions[$key]))
{
if ($key === 'time_before')
$query = true;
$query_cond[] = $available_conditions[$key];
}
}

$conditions['is_activated'] = 1;
if ($query)
{
$data = retrieveMemberData($conditions);
$members_id = $data['members'];
}
else
{
$members_id = $conditions['members'];
}

$conditions['is_activated'] = $conditions['activated_status'] >= 10 ? 11 : 1;
$conditions['blank_string'] = '';

// Approve/activate this member.
Expand All @@ -1994,6 +2010,12 @@ function approveMembers($conditions)
WHERE is_activated = {int:activated_status}' . implode('', $query_cond),
$conditions
);

// Let the integration know that they've been activated!
foreach ($members_id as $member_id)
call_integration_hook('integrate_activate', array($member_id, $conditions['activated_status'], $conditions['is_activated']));

return $conditions['is_activated'];
}

/**
Expand Down

0 comments on commit 1a4a375

Please sign in to comment.