Hack Name: Account Activation via Email v1.0

Hack Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Hack Description:
This modification will require that all members activate their account before they are allowed to make any posts.
Upon registration an email will be sent to the address they provide with a link to the activation area.
All registered members will already be activated (i.e. all members existing upon installation of this hack will automatically be activated).
If a member loses the email and isn't activated they will have the option to send a new email.
This new version includes and on/off switch.

Supported Version: XMB 1.9.8 Engage Final SP2/SP3

Updated for 1.9.8 by: WormHole @ XMB Garage

Installation Note: Before adding this hack to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License.

=======================================================================================================================

=======
Step 1:
=======

============================================
Go To Administration Panel -> Insert Raw SQL
============================================

ALTER TABLE `$table_members` ADD `activated` SET('yes','no') NOT NULL default 'no';
ALTER TABLE `$table_members` ADD `activate_password` VARCHAR(32) default '';
ALTER TABLE `$table_settings` ADD `account_activation` SET('on','off') NOT NULL default 'on';
UPDATE `$table_members` SET activated='yes';

=======================================================================================================================

=======
Step 2:
=======

============
Edit cp.php:
============

=====
Find:
=====

        $reportposton = $reportpostoff = '';
        settingHTML('reportpost', $reportposton, $reportpostoff);
        
==========
Add Below:
==========

        // Account Activation Via Email Mod Begin
        $account_activationon = $account_activationoff = '';
        settingHTML('account_activation', $account_activationon, $account_activationoff);
        // Account Activation Via Email Mod End
        
=====
Find:
=====

        printsetting1($lang['reportpoststatus'], 'reportpostnew', $reportposton, $reportpostoff);
        
==========
Add Below:
==========

        // Account Activation Via Email Mod Begin
        printsetting1($lang['activate_status'], 'account_activationnew', $account_activationon, $account_activationoff);
        // Account Activation Via Email Mod End

=====
Find:
=====

        $onlinetoday_statusnew = formOnOff('onlinetoday_statusnew');

=========
Add Below:
=========

        // Account Activation Via Email Mod Begin
        $account_activationnew = formOnOff('account_activationnew');
        // Account Activation Via Email Mod End

=====
Find:
=====

            onlinetoday_status='$onlinetoday_statusnew'
        
============
Replace With:
============

            onlinetoday_status='$onlinetoday_statusnew',
            account_activation='$account_activationnew'

=======================================================================================================================

=======
Step 3:
=======

================
Edit: index.php:
================

==========
Find Code:
==========

    eval('$ticker = "'.template('index_ticker').'";');
}

===============
Add Code Below:
===============

// Account Activation Via Email Mod Begin
// Check if users account is activated
$activated = '';
if (X_MEMBER && $SETTINGS['account_activation'] == 'on' && $self['activated'] == 'no') {
    $activated = error(str_replace('*USER*', rawurlencode($self['username']), $lang['howtoactivate']), false, '', '', false, false, true, false);
}
// Account Activation Via Email Mod End

=======================================================================================================================

=======
Step 4:
=======

=====================
Edit File: member.php
=====================

================
Find Code (2 times):
================

) VALUES ('$username', '$password'

======================
Replace Code With (2 times):
======================

, activated, activate_password) VALUES ('$username', '$password'

================
Find Code (2 times):
================

, '$useoldu2u'

======================
Replace Code With (2 times):
======================

, '$useoldu2u', 'no', '$activate_password'

================
Find Code (2 times):
================

                $db->query("INSERT INTO ".X_PREFIX."members

=====================
Add Code Above (2 times):
=====================

                // Account Activation Via Email Mod Begin
                if ($SETTINGS['account_activation'] == 'on') {
                    $activate_password = md5(uniqid(mt_rand()));
                    altMail($email, $lang['activate_mailsub'], str_replace(array('*BOARDNAME*', '*FULL_URL*', '*USER*', '*CODE*'), array($SETTINGS['bbname'], $full_url, $username, $activate_password), $lang['activate_mailmess']), 'From: '.$SETTINGS['bbname'].' <'.$SETTINGS['adminemail'].'>');
                }
                // Account Activation Via Email Mod End

==========
Find Code:
==========

            echo ($SETTINGS['emailcheck'] == 'on') ? "<center><span class=\"mediumtxt \">$lang[emailpw]</span></center>" : "<center><span class=\"mediumtxt \">$lang[regged]</span></center>";

==================
Replace Code With:
==================

            $activatemsg = ($SETTINGS['account_activation'] == 'on') ? $lang['activate_message'] : '';
            echo ($SETTINGS['emailcheck'] == 'on') ? "<center><span class=\"mediumtxt \">$lang[emailpw]</span></center>" : "<center><span class=\"mediumtxt \">$lang[regged]<br />$activatemsg</span></center>";

==========
Find Code:
==========

    default:
        error($lang['textnoaction']);

===============
Add Code Above:
===============

    // Account Activation Via Email Mod Begin
    case 'activate':
        if (!X_MEMBER || $self['activated'] == 'yes') {
            error($lang['textnoaction']);
        } else {
            if (!$activate_password || empty($activate_password)) {
                eval('echo "'.template('header').'";');
            
                if ($SETTINGS['account_activation'] == 'on') {
                    $activate_password2 = md5(uniqid(mt_rand()));

                    altMail($self['email'], $lang['activate_mailsub'], str_replace(array('*BOARDNAME*', '*FULL_URL*', '*USER*', '*CODE*'), array($SETTINGS['bbname'], $full_url, $self['username'], $activate_password), $lang['activate_mailmess']), "From: $bbname <$adminemail>");
                    $db->query("UPDATE ".X_PREFIX."members SET activate_password='$activate_password2' WHERE username='$self[username]'");

                    echo "<center><span class=\"mediumtxt \">$lang[activate_message]</span></center>";
                    redirect('index.php', 2, X_REDIRECT_JS);
                } else {
                    echo "<center><span class=\"mediumtxt \">$lang[activate_featureoff]</span></center>";
                    redirect('index.php', 2, X_REDIRECT_JS);
                }
            } else {
                eval('echo "'.template('header').'";');
                if ($activate_password == $self['activate_password']) {
                    $db->query("UPDATE ".X_PREFIX."members SET activated='yes' WHERE username='$self[username]'");
                    echo "<center><span class=\"mediumtxt \">$lang[account_activated]</span></center>";
                    redirect('index.php', 2, X_REDIRECT_JS);
                } else {
                    error($lang['invalidactivecode']);
                }
            }
        }
        break;
        // Account Activation Via Email Mod End

=======================================================================================================================

=======
Step 5:
=======

===================
Edit File: post.php
===================

==========
Find Code:
==========

    case 'newthread':

===============
Add Code Below:
===============

        // Account Activation Via Email Mod Begin
        // Check if users account is activated
        if ($SETTINGS['account_activation'] == 'on' && $self['activated'] == 'no') {
            error($lang['inactivated_account']);
        }
        // Account Activation Via Email Mod End

==========
Find Code:
==========

    case 'reply':

===============
Add Code Below:
===============

        // Account Activation Via Email Mod Begin
        // Check if users account is activated
        if ($SETTINGS['account_activation'] == 'on' && $self['activated'] == 'no') {
            error($lang['inactivated_account']);
        }
        // Account Activation Via Email Mod End

=======================================================================================================================

=======
Step 6:
=======

===================
Edit File: u2u.php:
===================

=====
Find:
=====

        $msgto = postedVar('msgto', 'javascript', TRUE, TRUE, TRUE);

==========
Add Below:
==========

        // Account Activation Via Email Mod Begin
        if ($SETTINGS['account_activation'] == 'on' && $self['activated'] == 'no') {
            error($lang['inactivenou2u'], false, $u2uheader, $u2ufooter, false, true, false, false);
        }
        // Account Activation Via Email Mod End

=======================================================================================================================

=======
Step 7:
=======

===========================
Edit File: English.lang.php
===========================

===================
Add to End of File:
===================

// Account Activation Via Email
$lang['inactivated_account'] = "Account not activated! You must activate your account before you can post.";
$lang['howtoactivate'] = "Your account is not activated! To activate your account, <a href=\"./member.php?action=activate&amp;member=*USER*\">click here</a> if you have not received the activation email";
$lang['activate_account'] = "Activate Account";
$lang['activate_message'] = "An Activation email has been sent to the email address on file.";
$lang['activate_mailsub'] = "Activate your account at $bbname";
$lang['activate_mailmess'] = "To activate your account at *BOARDNAME*, click this link *FULL_URL*member.php?action=activate&member=*USER*&activate_password=*CODE*";
$lang['activate_status'] = "Account Activation via E-Mail Status:";
$lang['activate_featureoff'] = "This feature is currently disabled.";
$lang['account_activated'] = "Thank you. Your account has been activated. You may now post and send U2Us.";
$lang['invalidactivecode'] = "Invalid Activation Code! If you copied the link, please make sure you got the entire link from your email. If you need the email to be sent again, please <a href=\"./member.php?action=activate\">click here</a>.";
$lang['inactivenou2u'] = "You Must Activate your account before being allowed to send U2Us!";
// End Account Activation Via Email

=======================================================================================================

=======
Step 8:
=======

========================================
Go To Administration Panel -> Templates:
========================================

====================
Edit Template index:
====================

==========
Find Code:
==========

$ticker

==================
Replace Code With:
==================

$ticker
$activated

=======================================================================================================

Enjoy!