示例#1
0
function confirm($confirmcode)
{
    global $_CB_framework, $_PLUGINS;
    $_PLUGINS->loadPluginGroup('user');
    $_PLUGINS->trigger('onBeforeUserConfirmationRequest', array());
    if ($_CB_framework->myId() < 1) {
        $unscrambledId = UserTable::getUserIdFromActivationCode($confirmcode);
        if ($unscrambledId) {
            $cbUser = CBuser::getInstance((int) $unscrambledId);
            if ($cbUser) {
                $user = $cbUser->getUserData();
                if ($user && $user->id) {
                    if ($user->confirmed == 0) {
                        if ($user->checkActivationCode($confirmcode)) {
                            // THIS is the normal case: user exists, is not yet confirmed, and confirmation code does match:
                            $messagesToUser = null;
                            $confirmed = $user->confirmUser(1, $messagesToUser);
                        } else {
                            // confirmation code does not match:
                            $messagesToUser = array(CBTxt::Th('UE_WRONG_CONFIRMATION_CODE', 'Wrong confirmation code. Please check your Email and spambox.'));
                            $confirmed = false;
                        }
                    } else {
                        // User has already confirmed: show friendly activation messages depending on his state:
                        $messagesToUser = getActivationMessage($user, 'UserConfirmation');
                        $confirmed = true;
                    }
                    if ($confirmed) {
                        // THIS is the normal case: user exists, is not yet confirmed, and confirmation code does match:
                        $class = 'info';
                    } else {
                        $class = 'error';
                    }
                    $_PLUGINS->trigger('onAfterUserConfirmation', array(&$user, $confirmcode, $confirmed, &$class, &$messagesToUser));
                    $return = '<div class="cbUserConfirmation cb_template cb_template_' . selectTemplate('dir') . '">' . '<div class="' . htmlspecialchars($class) . '">' . implode('</div><div class="' . htmlspecialchars($class) . '">', $messagesToUser) . '</div>' . '</div>';
                    echo $return;
                    return;
                }
            }
        }
        // this is the error case where the URL is simply not right:
        cbNotAuth(true);
        return;
    } else {
        $_CB_framework->enqueueMessage(CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!') . ' ' . CBTxt::Th('UE_DO_LOGOUT', 'You need to logout.'), 'error');
    }
}