includes/ucp/ucp_activate.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/ucp/ucp_activate.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,147 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package ucp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* ucp_activate
    1.24 +* User activation
    1.25 +* @package ucp
    1.26 +*/
    1.27 +class ucp_activate
    1.28 +{
    1.29 +	var $u_action;
    1.30 +
    1.31 +	function main($id, $mode)
    1.32 +	{
    1.33 +		global $config, $phpbb_root_path, $phpEx;
    1.34 +		global $db, $user, $auth, $template;
    1.35 +
    1.36 +		$user_id = request_var('u', 0);
    1.37 +		$key = request_var('k', '');
    1.38 +
    1.39 +		$sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason
    1.40 +			FROM ' . USERS_TABLE . "
    1.41 +			WHERE user_id = $user_id";
    1.42 +		$result = $db->sql_query($sql);
    1.43 +		$user_row = $db->sql_fetchrow($result);
    1.44 +		$db->sql_freeresult($result);
    1.45 +
    1.46 +		if (!$user_row)
    1.47 +		{
    1.48 +			trigger_error('NO_USER');
    1.49 +		}
    1.50 +
    1.51 +		if ($user_row['user_type'] <> USER_INACTIVE && !$user_row['user_newpasswd'])
    1.52 +		{
    1.53 +			meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
    1.54 +			trigger_error('ALREADY_ACTIVATED');
    1.55 +		}
    1.56 +
    1.57 +		if (($user_row['user_inactive_reason'] ==  INACTIVE_MANUAL) || $user_row['user_actkey'] != $key)
    1.58 +		{
    1.59 +			trigger_error('WRONG_ACTIVATION');
    1.60 +		}
    1.61 +
    1.62 +		// Do not allow activating by non administrators when admin activation is on
    1.63 +		// Only activation type the user should be able to do is INACTIVE_REMIND
    1.64 +		// or activate a new password which is not an activation state :@
    1.65 +		if (!$user_row['user_newpasswd'] && $user_row['user_inactive_reason'] != INACTIVE_REMIND && $config['require_activation'] == USER_ACTIVATION_ADMIN && !$auth->acl_get('a_user'))
    1.66 +		{
    1.67 +			if (!$user->data['is_registered'])
    1.68 +			{
    1.69 +				login_box('', $user->lang['NO_AUTH_OPERATION']);
    1.70 +			}
    1.71 +			trigger_error('NO_AUTH_OPERATION');
    1.72 +		}
    1.73 +
    1.74 +		$update_password = ($user_row['user_newpasswd']) ? true : false;
    1.75 +
    1.76 +		if ($update_password)
    1.77 +		{
    1.78 +			$sql_ary = array(
    1.79 +				'user_actkey'		=> '',
    1.80 +				'user_password'		=> $user_row['user_newpasswd'],
    1.81 +				'user_newpasswd'	=> '',
    1.82 +				'user_pass_convert'	=> 0,
    1.83 +				'user_login_attempts'	=> 0,
    1.84 +			);
    1.85 +
    1.86 +			$sql = 'UPDATE ' . USERS_TABLE . '
    1.87 +				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
    1.88 +				WHERE user_id = ' . $user_row['user_id'];
    1.89 +			$db->sql_query($sql);
    1.90 +
    1.91 +			add_log('user', $user_row['user_id'], 'LOG_USER_NEW_PASSWORD', $user_row['username']);
    1.92 +		}
    1.93 +
    1.94 +		if (!$update_password)
    1.95 +		{
    1.96 +			include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.97 +
    1.98 +			user_active_flip('activate', $user_row['user_id']);
    1.99 +
   1.100 +			$sql = 'UPDATE ' . USERS_TABLE . "
   1.101 +				SET user_actkey = ''
   1.102 +				WHERE user_id = {$user_row['user_id']}";
   1.103 +			$db->sql_query($sql);
   1.104 +
   1.105 +			// Create the correct logs
   1.106 +			add_log('user', $user_row['user_id'], 'LOG_USER_ACTIVE_USER');
   1.107 +			if ($auth->acl_get('a_user'))
   1.108 +			{
   1.109 +				add_log('admin', 'LOG_USER_ACTIVE', $user_row['username']);
   1.110 +			}
   1.111 +		}
   1.112 +
   1.113 +		if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !$update_password)
   1.114 +		{
   1.115 +			include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
   1.116 +
   1.117 +			$messenger = new messenger(false);
   1.118 +
   1.119 +			$messenger->template('admin_welcome_activated', $user_row['user_lang']);
   1.120 +
   1.121 +			$messenger->to($user_row['user_email'], $user_row['username']);
   1.122 +
   1.123 +			$messenger->anti_abuse_headers($config, $user);
   1.124 +
   1.125 +			$messenger->assign_vars(array(
   1.126 +				'USERNAME'	=> htmlspecialchars_decode($user_row['username']))
   1.127 +			);
   1.128 +
   1.129 +			$messenger->send($user_row['user_notify_type']);
   1.130 +
   1.131 +			$message = 'ACCOUNT_ACTIVE_ADMIN';
   1.132 +		}
   1.133 +		else
   1.134 +		{
   1.135 +			if (!$update_password)
   1.136 +			{
   1.137 +				$message = ($user_row['user_inactive_reason'] == INACTIVE_PROFILE) ? 'ACCOUNT_ACTIVE_PROFILE' : 'ACCOUNT_ACTIVE';
   1.138 +			}
   1.139 +			else
   1.140 +			{
   1.141 +				$message = 'PASSWORD_ACTIVATED';
   1.142 +			}
   1.143 +		}
   1.144 +
   1.145 +		meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
   1.146 +		trigger_error($user->lang[$message]);
   1.147 +	}
   1.148 +}
   1.149 +
   1.150 +?>
   1.151 \ No newline at end of file