PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/php/Sources/Register.php

https://github.com/dekoza/openshift-smf-2.0.7
PHP | 873 lines | 594 code | 136 blank | 143 comment | 191 complexity | 9515abee269f386b63e63aa571e1e8e5 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0.7
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* This file has two main jobs, but they really are one. It registers new
  15. members, and it helps the administrator moderate member registrations.
  16. Similarly, it handles account activation as well.
  17. void Register()
  18. // !!!
  19. void Register2()
  20. // !!!
  21. void Activate()
  22. // !!!
  23. void CoppaForm()
  24. // !!!
  25. void VerificationCode()
  26. // Show the verification code or let it hear.
  27. void RegisterCheckUsername()
  28. // !!!
  29. */
  30. // Begin the registration process.
  31. function Register($reg_errors = array())
  32. {
  33. global $txt, $boarddir, $context, $settings, $modSettings, $user_info;
  34. global $language, $scripturl, $smcFunc, $sourcedir, $smcFunc, $cur_profile;
  35. // Is this an incoming AJAX check?
  36. if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
  37. return RegisterCheckUsername();
  38. // Check if the administrator has it disabled.
  39. if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
  40. fatal_lang_error('registration_disabled', false);
  41. // If this user is an admin - redirect them to the admin registration page.
  42. if (allowedTo('moderate_forum') && !$user_info['is_guest'])
  43. redirectexit('action=admin;area=regcenter;sa=register');
  44. // You are not a guest, so you are a member - and members don't get to register twice!
  45. elseif (empty($user_info['is_guest']))
  46. redirectexit();
  47. loadLanguage('Login');
  48. loadTemplate('Register');
  49. // Do we need them to agree to the registration agreement, first?
  50. $context['require_agreement'] = !empty($modSettings['requireAgreement']);
  51. $context['registration_passed_agreement'] = !empty($_SESSION['registration_agreed']);
  52. $context['show_coppa'] = !empty($modSettings['coppaAge']);
  53. // Under age restrictions?
  54. if ($context['show_coppa'])
  55. {
  56. $context['skip_coppa'] = false;
  57. $context['coppa_agree_above'] = sprintf($txt['agreement_agree_coppa_above'], $modSettings['coppaAge']);
  58. $context['coppa_agree_below'] = sprintf($txt['agreement_agree_coppa_below'], $modSettings['coppaAge']);
  59. }
  60. // What step are we at?
  61. $current_step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : ($context['require_agreement'] ? 1 : 2);
  62. // Does this user agree to the registation agreement?
  63. if ($current_step == 1 && (isset($_POST['accept_agreement']) || isset($_POST['accept_agreement_coppa'])))
  64. {
  65. $context['registration_passed_agreement'] = $_SESSION['registration_agreed'] = true;
  66. $current_step = 2;
  67. // Skip the coppa procedure if the user says he's old enough.
  68. if ($context['show_coppa'])
  69. {
  70. $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
  71. // Are they saying they're under age, while under age registration is disabled?
  72. if (empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
  73. {
  74. loadLanguage('Login');
  75. fatal_lang_error('under_age_registration_prohibited', false, array($modSettings['coppaAge']));
  76. }
  77. }
  78. }
  79. // Make sure they don't squeeze through without agreeing.
  80. elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
  81. $current_step = 1;
  82. // Show the user the right form.
  83. $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
  84. $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
  85. // Add the register chain to the link tree.
  86. $context['linktree'][] = array(
  87. 'url' => $scripturl . '?action=register',
  88. 'name' => $txt['register'],
  89. );
  90. // If you have to agree to the agreement, it needs to be fetched from the file.
  91. if ($context['require_agreement'])
  92. {
  93. // Have we got a localized one?
  94. if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
  95. $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
  96. elseif (file_exists($boarddir . '/agreement.txt'))
  97. $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
  98. else
  99. $context['agreement'] = '';
  100. }
  101. if (!empty($modSettings['userLanguage']))
  102. {
  103. $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
  104. // Do we have any languages?
  105. if (empty($context['languages']))
  106. getLanguages();
  107. // Try to find our selected language.
  108. foreach ($context['languages'] as $key => $lang)
  109. {
  110. $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
  111. // Found it!
  112. if ($selectedLanguage == $lang['filename'])
  113. $context['languages'][$key]['selected'] = true;
  114. }
  115. }
  116. // Any custom fields we want filled in?
  117. require_once($sourcedir . '/Profile.php');
  118. loadCustomFields(0, 'register');
  119. // Or any standard ones?
  120. if (!empty($modSettings['registration_fields']))
  121. {
  122. require_once($sourcedir . '/Profile-Modify.php');
  123. // Setup some important context.
  124. loadLanguage('Profile');
  125. loadTemplate('Profile');
  126. $context['user']['is_owner'] = true;
  127. // Here, and here only, emulate the permissions the user would have to do this.
  128. $user_info['permissions'] = array_merge($user_info['permissions'], array('profile_account_own', 'profile_extra_own'));
  129. $reg_fields = explode(',', $modSettings['registration_fields']);
  130. // We might have had some submissions on this front - go check.
  131. foreach ($reg_fields as $field)
  132. if (isset($_POST[$field]))
  133. $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
  134. // Load all the fields in question.
  135. setupProfileContext($reg_fields);
  136. }
  137. // Generate a visual verification code to make sure the user is no bot.
  138. if (!empty($modSettings['reg_verification']))
  139. {
  140. require_once($sourcedir . '/Subs-Editor.php');
  141. $verificationOptions = array(
  142. 'id' => 'register',
  143. );
  144. $context['visual_verification'] = create_control_verification($verificationOptions);
  145. $context['visual_verification_id'] = $verificationOptions['id'];
  146. }
  147. // Otherwise we have nothing to show.
  148. else
  149. $context['visual_verification'] = false;
  150. // Are they coming from an OpenID login attempt?
  151. if (!empty($_SESSION['openid']['verified']) && !empty($_SESSION['openid']['openid_uri']))
  152. {
  153. $context['openid'] = $_SESSION['openid']['openid_uri'];
  154. $context['username'] = $smcFunc['htmlspecialchars'](!empty($_POST['user']) ? $_POST['user'] : $_SESSION['openid']['nickname']);
  155. $context['email'] = $smcFunc['htmlspecialchars'](!empty($_POST['email']) ? $_POST['email'] : $_SESSION['openid']['email']);
  156. }
  157. // See whether we have some prefiled values.
  158. else
  159. {
  160. $context += array(
  161. 'openid' => isset($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '',
  162. 'username' => isset($_POST['user']) ? $smcFunc['htmlspecialchars']($_POST['user']) : '',
  163. 'email' => isset($_POST['email']) ? $smcFunc['htmlspecialchars']($_POST['email']) : '',
  164. );
  165. }
  166. // !!! Why isn't this a simple set operation?
  167. // Were there any errors?
  168. $context['registration_errors'] = array();
  169. if (!empty($reg_errors))
  170. foreach ($reg_errors as $error)
  171. $context['registration_errors'][] = $error;
  172. }
  173. // Actually register the member.
  174. function Register2($verifiedOpenID = false)
  175. {
  176. global $scripturl, $txt, $modSettings, $context, $sourcedir;
  177. global $user_info, $options, $settings, $smcFunc;
  178. // Start collecting together any errors.
  179. $reg_errors = array();
  180. // Did we save some open ID fields?
  181. if ($verifiedOpenID && !empty($context['openid_save_fields']))
  182. {
  183. foreach ($context['openid_save_fields'] as $id => $value)
  184. $_POST[$id] = $value;
  185. }
  186. // You can't register if it's disabled.
  187. if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
  188. fatal_lang_error('registration_disabled', false);
  189. // Things we don't do for people who have already confirmed their OpenID allegances via register.
  190. if (!$verifiedOpenID)
  191. {
  192. // Well, if you don't agree, you can't register.
  193. if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
  194. redirectexit();
  195. // Make sure they came from *somewhere*, have a session.
  196. if (!isset($_SESSION['old_url']))
  197. redirectexit('action=register');
  198. // Are they under age, and under age users are banned?
  199. if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
  200. {
  201. // !!! This should be put in Errors, imho.
  202. loadLanguage('Login');
  203. fatal_lang_error('under_age_registration_prohibited', false, array($modSettings['coppaAge']));
  204. }
  205. // Check whether the visual verification code was entered correctly.
  206. if (!empty($modSettings['reg_verification']))
  207. {
  208. require_once($sourcedir . '/Subs-Editor.php');
  209. $verificationOptions = array(
  210. 'id' => 'register',
  211. );
  212. $context['visual_verification'] = create_control_verification($verificationOptions, true);
  213. if (is_array($context['visual_verification']))
  214. {
  215. loadLanguage('Errors');
  216. foreach ($context['visual_verification'] as $error)
  217. $reg_errors[] = $txt['error_' . $error];
  218. }
  219. }
  220. }
  221. foreach ($_POST as $key => $value)
  222. {
  223. if (!is_array($_POST[$key]))
  224. $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
  225. }
  226. // Collect all extra registration fields someone might have filled in.
  227. $possible_strings = array(
  228. 'website_url', 'website_title',
  229. 'aim', 'yim',
  230. 'location', 'birthdate',
  231. 'time_format',
  232. 'buddy_list',
  233. 'pm_ignore_list',
  234. 'smiley_set',
  235. 'signature', 'personal_text', 'avatar',
  236. 'lngfile',
  237. 'secret_question', 'secret_answer',
  238. );
  239. $possible_ints = array(
  240. 'pm_email_notify',
  241. 'notify_types',
  242. 'icq',
  243. 'gender',
  244. 'id_theme',
  245. );
  246. $possible_floats = array(
  247. 'time_offset',
  248. );
  249. $possible_bools = array(
  250. 'notify_announcements', 'notify_regularity', 'notify_send_body',
  251. 'hide_email', 'show_online',
  252. );
  253. if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
  254. $_POST['secret_answer'] = md5($_POST['secret_answer']);
  255. // Needed for isReservedName() and registerMember().
  256. require_once($sourcedir . '/Subs-Members.php');
  257. // Validation... even if we're not a mall.
  258. if (isset($_POST['real_name']) && (!empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum')))
  259. {
  260. $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
  261. if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
  262. $possible_strings[] = 'real_name';
  263. }
  264. if (isset($_POST['msn']) && preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['msn']) != 0)
  265. $profile_strings[] = 'msn';
  266. // Handle a string as a birthdate...
  267. if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
  268. $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
  269. // Or birthdate parts...
  270. elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
  271. $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
  272. // By default assume email is hidden, only show it if we tell it to.
  273. $_POST['hide_email'] = !empty($_POST['allow_email']) ? 0 : 1;
  274. // Validate the passed language file.
  275. if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
  276. {
  277. // Do we have any languages?
  278. if (empty($context['languages']))
  279. getLanguages();
  280. // Did we find it?
  281. if (isset($context['languages'][$_POST['lngfile']]))
  282. $_SESSION['language'] = $_POST['lngfile'];
  283. else
  284. unset($_POST['lngfile']);
  285. }
  286. else
  287. unset($_POST['lngfile']);
  288. // Some of these fields we may not want.
  289. if (!empty($modSettings['registration_fields']))
  290. {
  291. // But we might want some of them if the admin asks for them.
  292. $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender');
  293. $reg_fields = explode(',', $modSettings['registration_fields']);
  294. $exclude_fields = array_diff($standard_fields, $reg_fields);
  295. // Website is a little different
  296. if (!in_array('website', $reg_fields))
  297. $exclude_fields = array_merge($exclude_fields, array('website_url', 'website_title'));
  298. // We used to accept signature on registration but it's being abused by spammers these days, so no more.
  299. $exclude_fields[] = 'signature';
  300. }
  301. else
  302. $exclude_fields = array('signature', 'icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website_url', 'website_title');
  303. $possible_strings = array_diff($possible_strings, $exclude_fields);
  304. $possible_ints = array_diff($possible_ints, $exclude_fields);
  305. $possible_floats = array_diff($possible_floats, $exclude_fields);
  306. $possible_bools = array_diff($possible_bools, $exclude_fields);
  307. // Set the options needed for registration.
  308. $regOptions = array(
  309. 'interface' => 'guest',
  310. 'username' => !empty($_POST['user']) ? $_POST['user'] : '',
  311. 'email' => !empty($_POST['email']) ? $_POST['email'] : '',
  312. 'password' => !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '',
  313. 'password_check' => !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '',
  314. 'openid' => !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '',
  315. 'auth_method' => !empty($_POST['authenticate']) ? $_POST['authenticate'] : '',
  316. 'check_reserved_name' => true,
  317. 'check_password_strength' => true,
  318. 'check_email_ban' => true,
  319. 'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
  320. 'require' => !empty($modSettings['coppaAge']) && !$verifiedOpenID && empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')),
  321. 'extra_register_vars' => array(),
  322. 'theme_vars' => array(),
  323. );
  324. // Include the additional options that might have been filled in.
  325. foreach ($possible_strings as $var)
  326. if (isset($_POST[$var]))
  327. $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
  328. foreach ($possible_ints as $var)
  329. if (isset($_POST[$var]))
  330. $regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
  331. foreach ($possible_floats as $var)
  332. if (isset($_POST[$var]))
  333. $regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
  334. foreach ($possible_bools as $var)
  335. if (isset($_POST[$var]))
  336. $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
  337. // Registration options are always default options...
  338. if (isset($_POST['default_options']))
  339. $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
  340. $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
  341. // Make sure they are clean, dammit!
  342. $regOptions['theme_vars'] = htmlspecialchars__recursive($regOptions['theme_vars']);
  343. // If Quick Reply hasn't been set then set it to be shown but collapsed.
  344. if (!isset($regOptions['theme_vars']['display_quick_reply']))
  345. $regOptions['theme_vars']['display_quick_reply'] = 1;
  346. // Check whether we have fields that simply MUST be displayed?
  347. $request = $smcFunc['db_query']('', '
  348. SELECT col_name, field_name, field_type, field_length, mask, show_reg
  349. FROM {db_prefix}custom_fields
  350. WHERE active = {int:is_active}',
  351. array(
  352. 'is_active' => 1,
  353. )
  354. );
  355. $custom_field_errors = array();
  356. while ($row = $smcFunc['db_fetch_assoc']($request))
  357. {
  358. // Don't allow overriding of the theme variables.
  359. if (isset($regOptions['theme_vars'][$row['col_name']]))
  360. unset($regOptions['theme_vars'][$row['col_name']]);
  361. // Not actually showing it then?
  362. if (!$row['show_reg'])
  363. continue;
  364. // Prepare the value!
  365. $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
  366. // We only care for text fields as the others are valid to be empty.
  367. if (!in_array($row['field_type'], array('check', 'select', 'radio')))
  368. {
  369. // Is it too long?
  370. if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
  371. $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
  372. // Any masks to apply?
  373. if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
  374. {
  375. //!!! We never error on this - just ignore it at the moment...
  376. if ($row['mask'] == 'email' && (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $value) === 0 || strlen($value) > 255))
  377. $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
  378. elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
  379. $custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
  380. elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
  381. $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
  382. }
  383. }
  384. // Is this required but not there?
  385. if (trim($value) == '' && $row['show_reg'] > 1)
  386. $custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
  387. }
  388. $smcFunc['db_free_result']($request);
  389. // Process any errors.
  390. if (!empty($custom_field_errors))
  391. {
  392. loadLanguage('Errors');
  393. foreach ($custom_field_errors as $error)
  394. $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
  395. }
  396. // Lets check for other errors before trying to register the member.
  397. if (!empty($reg_errors))
  398. {
  399. $_REQUEST['step'] = 2;
  400. return Register($reg_errors);
  401. }
  402. // If they're wanting to use OpenID we need to validate them first.
  403. if (empty($_SESSION['openid']['verified']) && !empty($_POST['authenticate']) && $_POST['authenticate'] == 'openid')
  404. {
  405. // What do we need to save?
  406. $save_variables = array();
  407. foreach ($_POST as $k => $v)
  408. if (!in_array($k, array('sc', 'sesc', $context['session_var'], 'passwrd1', 'passwrd2', 'regSubmit')))
  409. $save_variables[$k] = $v;
  410. require_once($sourcedir . '/Subs-OpenID.php');
  411. smf_openID_validate($_POST['openid_identifier'], false, $save_variables);
  412. }
  413. // If we've come from OpenID set up some default stuff.
  414. elseif ($verifiedOpenID || (!empty($_POST['openid_identifier']) && $_POST['authenticate'] == 'openid'))
  415. {
  416. $regOptions['username'] = !empty($_POST['user']) && trim($_POST['user']) != '' ? $_POST['user'] : $_SESSION['openid']['nickname'];
  417. $regOptions['email'] = !empty($_POST['email']) && trim($_POST['email']) != '' ? $_POST['email'] : $_SESSION['openid']['email'];
  418. $regOptions['auth_method'] = 'openid';
  419. $regOptions['openid'] = !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : $_SESSION['openid']['openid_uri'];
  420. }
  421. $memberID = registerMember($regOptions, true);
  422. // What there actually an error of some kind dear boy?
  423. if (is_array($memberID))
  424. {
  425. $reg_errors = array_merge($reg_errors, $memberID);
  426. $_REQUEST['step'] = 2;
  427. return Register($reg_errors);
  428. }
  429. // Do our spam protection now.
  430. spamProtection('register');
  431. // We'll do custom fields after as then we get to use the helper function!
  432. if (!empty($_POST['customfield']))
  433. {
  434. require_once($sourcedir . '/Profile.php');
  435. require_once($sourcedir . '/Profile-Modify.php');
  436. makeCustomFieldChanges($memberID, 'register');
  437. }
  438. // If COPPA has been selected then things get complicated, setup the template.
  439. if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
  440. redirectexit('action=coppa;member=' . $memberID);
  441. // Basic template variable setup.
  442. elseif (!empty($modSettings['registration_method']))
  443. {
  444. loadTemplate('Register');
  445. $context += array(
  446. 'page_title' => $txt['register'],
  447. 'title' => $txt['registration_successful'],
  448. 'sub_template' => 'after',
  449. 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
  450. );
  451. }
  452. else
  453. {
  454. call_integration_hook('integrate_activate', array($row['member_name']));
  455. setLoginCookie(60 * $modSettings['cookieTime'], $memberID, sha1(sha1(strtolower($regOptions['username']) . $regOptions['password']) . $regOptions['register_vars']['password_salt']));
  456. redirectexit('action=login2;sa=check;member=' . $memberID, $context['server']['needs_login_fix']);
  457. }
  458. }
  459. function Activate()
  460. {
  461. global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language;
  462. loadLanguage('Login');
  463. loadTemplate('Login');
  464. if (empty($_REQUEST['u']) && empty($_POST['user']))
  465. {
  466. if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
  467. fatal_lang_error('no_access', false);
  468. $context['member_id'] = 0;
  469. $context['sub_template'] = 'resend';
  470. $context['page_title'] = $txt['invalid_activation_resend'];
  471. $context['can_activate'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] == 1;
  472. $context['default_username'] = isset($_GET['user']) ? $_GET['user'] : '';
  473. return;
  474. }
  475. // Get the code from the database...
  476. $request = $smcFunc['db_query']('', '
  477. SELECT id_member, validation_code, member_name, real_name, email_address, is_activated, passwd, lngfile
  478. FROM {db_prefix}members' . (empty($_REQUEST['u']) ? '
  479. WHERE member_name = {string:email_address} OR email_address = {string:email_address}' : '
  480. WHERE id_member = {int:id_member}') . '
  481. LIMIT 1',
  482. array(
  483. 'id_member' => isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0,
  484. 'email_address' => isset($_POST['user']) ? $_POST['user'] : '',
  485. )
  486. );
  487. // Does this user exist at all?
  488. if ($smcFunc['db_num_rows']($request) == 0)
  489. {
  490. $context['sub_template'] = 'retry_activate';
  491. $context['page_title'] = $txt['invalid_userid'];
  492. $context['member_id'] = 0;
  493. return;
  494. }
  495. $row = $smcFunc['db_fetch_assoc']($request);
  496. $smcFunc['db_free_result']($request);
  497. // Change their email address? (they probably tried a fake one first :P.)
  498. if (isset($_POST['new_email'], $_REQUEST['passwd']) && sha1(strtolower($row['member_name']) . $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
  499. {
  500. if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
  501. fatal_lang_error('no_access', false);
  502. // !!! Separate the sprintf?
  503. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['new_email']) == 0)
  504. fatal_error(sprintf($txt['valid_email_needed'], htmlspecialchars($_POST['new_email'])), false);
  505. // Make sure their email isn't banned.
  506. isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
  507. // Ummm... don't even dare try to take someone else's email!!
  508. $request = $smcFunc['db_query']('', '
  509. SELECT id_member
  510. FROM {db_prefix}members
  511. WHERE email_address = {string:email_address}
  512. LIMIT 1',
  513. array(
  514. 'email_address' => $_POST['new_email'],
  515. )
  516. );
  517. // !!! Separate the sprintf?
  518. if ($smcFunc['db_num_rows']($request) != 0)
  519. fatal_lang_error('email_in_use', false, array(htmlspecialchars($_POST['new_email'])));
  520. $smcFunc['db_free_result']($request);
  521. updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
  522. $row['email_address'] = $_POST['new_email'];
  523. $email_change = true;
  524. }
  525. // Resend the password, but only if the account wasn't activated yet.
  526. if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'resend' && ($row['is_activated'] == 0 || $row['is_activated'] == 2) && (!isset($_REQUEST['code']) || $_REQUEST['code'] == ''))
  527. {
  528. require_once($sourcedir . '/Subs-Post.php');
  529. $replacements = array(
  530. 'REALNAME' => $row['real_name'],
  531. 'USERNAME' => $row['member_name'],
  532. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $row['id_member'] . ';code=' . $row['validation_code'],
  533. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $row['id_member'],
  534. 'ACTIVATIONCODE' => $row['validation_code'],
  535. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  536. );
  537. $emaildata = loadEmailTemplate('resend_activate_message', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  538. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  539. $context['page_title'] = $txt['invalid_activation_resend'];
  540. // This will ensure we don't actually get an error message if it works!
  541. $context['error_title'] = '';
  542. fatal_lang_error(!empty($email_change) ? 'change_email_success' : 'resend_email_success', false);
  543. }
  544. // Quit if this code is not right.
  545. if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
  546. {
  547. if (!empty($row['is_activated']))
  548. fatal_lang_error('already_activated', false);
  549. elseif ($row['validation_code'] == '')
  550. {
  551. loadLanguage('Profile');
  552. fatal_error($txt['registration_not_approved'] . ' <a href="' . $scripturl . '?action=activate;user=' . $row['member_name'] . '">' . $txt['here'] . '</a>.', false);
  553. }
  554. $context['sub_template'] = 'retry_activate';
  555. $context['page_title'] = $txt['invalid_activation_code'];
  556. $context['member_id'] = $row['id_member'];
  557. return;
  558. }
  559. // Let the integration know that they've been activated!
  560. call_integration_hook('integrate_activate', array($row['member_name']));
  561. // Validation complete - update the database!
  562. updateMemberData($row['id_member'], array('is_activated' => 1, 'validation_code' => ''));
  563. // Also do a proper member stat re-evaluation.
  564. updateStats('member', false);
  565. if (!isset($_POST['new_email']))
  566. {
  567. require_once($sourcedir . '/Subs-Post.php');
  568. adminNotify('activation', $row['id_member'], $row['member_name']);
  569. }
  570. $context += array(
  571. 'page_title' => $txt['registration_successful'],
  572. 'sub_template' => 'login',
  573. 'default_username' => $row['member_name'],
  574. 'default_password' => '',
  575. 'never_expire' => false,
  576. 'description' => $txt['activate_success']
  577. );
  578. }
  579. // This function will display the contact information for the forum, as well a form to fill in.
  580. function CoppaForm()
  581. {
  582. global $context, $modSettings, $txt, $smcFunc;
  583. loadLanguage('Login');
  584. loadTemplate('Register');
  585. // No User ID??
  586. if (!isset($_GET['member']))
  587. fatal_lang_error('no_access', false);
  588. // Get the user details...
  589. $request = $smcFunc['db_query']('', '
  590. SELECT member_name
  591. FROM {db_prefix}members
  592. WHERE id_member = {int:id_member}
  593. AND is_activated = {int:is_coppa}',
  594. array(
  595. 'id_member' => (int) $_GET['member'],
  596. 'is_coppa' => 5,
  597. )
  598. );
  599. if ($smcFunc['db_num_rows']($request) == 0)
  600. fatal_lang_error('no_access', false);
  601. list ($username) = $smcFunc['db_fetch_row']($request);
  602. $smcFunc['db_free_result']($request);
  603. if (isset($_GET['form']))
  604. {
  605. // Some simple contact stuff for the forum.
  606. $context['forum_contacts'] = (!empty($modSettings['coppaPost']) ? $modSettings['coppaPost'] . '<br /><br />' : '') . (!empty($modSettings['coppaFax']) ? $modSettings['coppaFax'] . '<br />' : '');
  607. $context['forum_contacts'] = !empty($context['forum_contacts']) ? $context['forum_name_html_safe'] . '<br />' . $context['forum_contacts'] : '';
  608. // Showing template?
  609. if (!isset($_GET['dl']))
  610. {
  611. // Shortcut for producing underlines.
  612. $context['ul'] = '<u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u>';
  613. $context['template_layers'] = array();
  614. $context['sub_template'] = 'coppa_form';
  615. $context['page_title'] = $txt['coppa_form_title'];
  616. $context['coppa_body'] = str_replace(array('{PARENT_NAME}', '{CHILD_NAME}', '{USER_NAME}'), array($context['ul'], $context['ul'], $username), $txt['coppa_form_body']);
  617. }
  618. // Downloading.
  619. else
  620. {
  621. // The data.
  622. $ul = ' ';
  623. $crlf = "\r\n";
  624. $data = $context['forum_contacts'] . $crlf . $txt['coppa_form_address'] . ':' . $crlf . $txt['coppa_form_date'] . ':' . $crlf . $crlf . $crlf . $txt['coppa_form_body'];
  625. $data = str_replace(array('{PARENT_NAME}', '{CHILD_NAME}', '{USER_NAME}', '<br>', '<br />'), array($ul, $ul, $username, $crlf, $crlf), $data);
  626. // Send the headers.
  627. header('Connection: close');
  628. header('Content-Disposition: attachment; filename="approval.txt"');
  629. header('Content-Type: ' . ($context['browser']['is_ie'] || $context['browser']['is_opera'] ? 'application/octetstream' : 'application/octet-stream'));
  630. header('Content-Length: ' . count($data));
  631. echo $data;
  632. obExit(false);
  633. }
  634. }
  635. else
  636. {
  637. $context += array(
  638. 'page_title' => $txt['coppa_title'],
  639. 'sub_template' => 'coppa',
  640. );
  641. $context['coppa'] = array(
  642. 'body' => str_replace('{MINIMUM_AGE}', $modSettings['coppaAge'], $txt['coppa_after_registration']),
  643. 'many_options' => !empty($modSettings['coppaPost']) && !empty($modSettings['coppaFax']),
  644. 'post' => empty($modSettings['coppaPost']) ? '' : $modSettings['coppaPost'],
  645. 'fax' => empty($modSettings['coppaFax']) ? '' : $modSettings['coppaFax'],
  646. 'phone' => empty($modSettings['coppaPhone']) ? '' : str_replace('{PHONE_NUMBER}', $modSettings['coppaPhone'], $txt['coppa_send_by_phone']),
  647. 'id' => $_GET['member'],
  648. );
  649. }
  650. }
  651. // Show the verification code or let it hear.
  652. function VerificationCode()
  653. {
  654. global $sourcedir, $modSettings, $context, $scripturl;
  655. $verification_id = isset($_GET['vid']) ? $_GET['vid'] : '';
  656. $code = $verification_id && isset($_SESSION[$verification_id . '_vv']) ? $_SESSION[$verification_id . '_vv']['code'] : (isset($_SESSION['visual_verification_code']) ? $_SESSION['visual_verification_code'] : '');
  657. // Somehow no code was generated or the session was lost.
  658. if (empty($code))
  659. {
  660. header('Content-Type: image/gif');
  661. die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
  662. }
  663. // Show a window that will play the verification code.
  664. elseif (isset($_REQUEST['sound']))
  665. {
  666. loadLanguage('Login');
  667. loadTemplate('Register');
  668. $context['verification_sound_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand()) . ($verification_id ? ';vid=' . $verification_id : '') . ';format=.wav';
  669. $context['sub_template'] = 'verification_sound';
  670. $context['template_layers'] = array();
  671. obExit();
  672. }
  673. // If we have GD, try the nice code.
  674. elseif (empty($_REQUEST['format']))
  675. {
  676. require_once($sourcedir . '/Subs-Graphics.php');
  677. if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
  678. header('HTTP/1.1 400 Bad Request');
  679. // Otherwise just show a pre-defined letter.
  680. elseif (isset($_REQUEST['letter']))
  681. {
  682. $_REQUEST['letter'] = (int) $_REQUEST['letter'];
  683. if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= strlen($code) && !showLetterImage(strtolower($code{$_REQUEST['letter'] - 1})))
  684. {
  685. header('Content-Type: image/gif');
  686. die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
  687. }
  688. }
  689. // You must be up to no good.
  690. else
  691. {
  692. header('Content-Type: image/gif');
  693. die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
  694. }
  695. }
  696. elseif ($_REQUEST['format'] === '.wav')
  697. {
  698. require_once($sourcedir . '/Subs-Sound.php');
  699. if (!createWaveFile($code))
  700. header('HTTP/1.1 400 Bad Request');
  701. }
  702. // We all die one day...
  703. die();
  704. }
  705. // See if a username already exists.
  706. function RegisterCheckUsername()
  707. {
  708. global $sourcedir, $smcFunc, $context, $txt;
  709. // This is XML!
  710. loadTemplate('Xml');
  711. $context['sub_template'] = 'check_username';
  712. $context['checked_username'] = isset($_GET['username']) ? $_GET['username'] : '';
  713. $context['valid_username'] = true;
  714. // Clean it up like mother would.
  715. $context['checked_username'] = preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $context['checked_username']);
  716. if ($smcFunc['strlen']($context['checked_username']) > 25)
  717. $context['checked_username'] = $smcFunc['htmltrim']($smcFunc['substr']($context['checked_username'], 0, 25));
  718. // Only these characters are permitted.
  719. if (preg_match('~[<>&"\'=\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $context['checked_username'])) != 0 || $context['checked_username'] == '_' || $context['checked_username'] == '|' || strpos($context['checked_username'], '[code') !== false || strpos($context['checked_username'], '[/code') !== false)
  720. $context['valid_username'] = false;
  721. if (stristr($context['checked_username'], $txt['guest_title']) !== false)
  722. $context['valid_username'] = false;
  723. if (trim($context['checked_username']) == '')
  724. $context['valid_username'] = false;
  725. else
  726. {
  727. require_once($sourcedir . '/Subs-Members.php');
  728. $context['valid_username'] &= isReservedName($context['checked_username'], 0, false, false) ? 0 : 1;
  729. }
  730. }
  731. ?>