includes/ucp/ucp_remind.php
changeset 0 ceef6d64c21d
equal deleted inserted replaced
-1:000000000000 0:ceef6d64c21d
       
     1 <?php
       
     2 /**
       
     3 *
       
     4 * @package ucp
       
     5 * @version $Id$
       
     6 * @copyright (c) 2005 phpBB Group
       
     7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
     8 *
       
     9 */
       
    10 
       
    11 /**
       
    12 * @ignore
       
    13 */
       
    14 if (!defined('IN_PHPBB'))
       
    15 {
       
    16 	exit;
       
    17 }
       
    18 
       
    19 /**
       
    20 * ucp_remind
       
    21 * Sending password reminders
       
    22 * @package ucp
       
    23 */
       
    24 class ucp_remind
       
    25 {
       
    26 	var $u_action;
       
    27 
       
    28 	function main($id, $mode)
       
    29 	{
       
    30 		global $config, $phpbb_root_path, $phpEx;
       
    31 		global $db, $user, $auth, $template;
       
    32 
       
    33 		$username	= request_var('username', '', true);
       
    34 		$email		= strtolower(request_var('email', ''));
       
    35 		$submit		= (isset($_POST['submit'])) ? true : false;
       
    36 
       
    37 		if ($submit)
       
    38 		{
       
    39 			$sql = 'SELECT user_id, username, user_permissions, user_email, user_jabber, user_notify_type, user_type, user_lang, user_inactive_reason
       
    40 				FROM ' . USERS_TABLE . "
       
    41 				WHERE user_email_hash = '" . $db->sql_escape(phpbb_email_hash($email)) . "'
       
    42 					AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
       
    43 			$result = $db->sql_query($sql);
       
    44 			$user_row = $db->sql_fetchrow($result);
       
    45 			$db->sql_freeresult($result);
       
    46 
       
    47 			if (!$user_row)
       
    48 			{
       
    49 				trigger_error('NO_EMAIL_USER');
       
    50 			}
       
    51 
       
    52 			if ($user_row['user_type'] == USER_IGNORE)
       
    53 			{
       
    54 				trigger_error('NO_USER');
       
    55 			}
       
    56 
       
    57 			if ($user_row['user_type'] == USER_INACTIVE)
       
    58 			{
       
    59 				if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL)
       
    60 				{
       
    61 					trigger_error('ACCOUNT_DEACTIVATED');
       
    62 				}
       
    63 				else
       
    64 				{
       
    65 					trigger_error('ACCOUNT_NOT_ACTIVATED');
       
    66 				}
       
    67 			}
       
    68 
       
    69 			// Check users permissions
       
    70 			$auth2 = new auth();
       
    71 			$auth2->acl($user_row);
       
    72 
       
    73 			if (!$auth2->acl_get('u_chgpasswd'))
       
    74 			{
       
    75 				trigger_error('NO_AUTH_PASSWORD_REMINDER');
       
    76 			}
       
    77 
       
    78 			$server_url = generate_board_url();
       
    79 
       
    80 			// Make password at least 8 characters long, make it longer if admin wants to.
       
    81 			// gen_rand_string() however has a limit of 12 or 13.
       
    82 			$user_password = gen_rand_string_friendly(max(8, mt_rand((int) $config['min_pass_chars'], (int) $config['max_pass_chars'])));
       
    83 
       
    84 			// For the activation key a random length between 6 and 10 will do.
       
    85 			$user_actkey = gen_rand_string(mt_rand(6, 10));
       
    86 
       
    87 			$sql = 'UPDATE ' . USERS_TABLE . "
       
    88 				SET user_newpasswd = '" . $db->sql_escape(phpbb_hash($user_password)) . "', user_actkey = '" . $db->sql_escape($user_actkey) . "'
       
    89 				WHERE user_id = " . $user_row['user_id'];
       
    90 			$db->sql_query($sql);
       
    91 
       
    92 			include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
       
    93 
       
    94 			$messenger = new messenger(false);
       
    95 
       
    96 			$messenger->template('user_activate_passwd', $user_row['user_lang']);
       
    97 
       
    98 			$messenger->to($user_row['user_email'], $user_row['username']);
       
    99 			$messenger->im($user_row['user_jabber'], $user_row['username']);
       
   100 
       
   101 			$messenger->assign_vars(array(
       
   102 				'USERNAME'		=> htmlspecialchars_decode($user_row['username']),
       
   103 				'PASSWORD'		=> htmlspecialchars_decode($user_password),
       
   104 				'U_ACTIVATE'	=> "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
       
   105 			);
       
   106 
       
   107 			$messenger->send($user_row['user_notify_type']);
       
   108 
       
   109 			meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
       
   110 
       
   111 			$message = $user->lang['PASSWORD_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
       
   112 			trigger_error($message);
       
   113 		}
       
   114 
       
   115 		$template->assign_vars(array(
       
   116 			'USERNAME'			=> $username,
       
   117 			'EMAIL'				=> $email,
       
   118 			'S_PROFILE_ACTION'	=> append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=sendpassword'))
       
   119 		);
       
   120 
       
   121 		$this->tpl_name = 'ucp_remind';
       
   122 		$this->page_title = 'UCP_REMIND';
       
   123 	}
       
   124 }
       
   125 
       
   126 ?>