PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB/includes/ucp/ucp_activate.php

http://github.com/phpbb/phpbb
PHP | 170 lines | 109 code | 30 blank | 31 comment | 22 complexity | ea1ff74cc1881a7ba535c1eb279b921e MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * ucp_activate
  22. * User activation
  23. */
  24. class ucp_activate
  25. {
  26. var $u_action;
  27. function main($id, $mode)
  28. {
  29. global $config, $phpbb_root_path, $phpEx, $request;
  30. global $db, $user, $auth, $phpbb_container, $phpbb_log, $phpbb_dispatcher;
  31. $user_id = $request->variable('u', 0);
  32. $key = $request->variable('k', '');
  33. $sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason
  34. FROM ' . USERS_TABLE . "
  35. WHERE user_id = $user_id";
  36. $result = $db->sql_query($sql);
  37. $user_row = $db->sql_fetchrow($result);
  38. $db->sql_freeresult($result);
  39. if (!$user_row)
  40. {
  41. trigger_error('NO_USER');
  42. }
  43. if ($user_row['user_type'] <> USER_INACTIVE && !$user_row['user_newpasswd'])
  44. {
  45. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  46. trigger_error('ALREADY_ACTIVATED');
  47. }
  48. if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL || $user_row['user_actkey'] !== $key)
  49. {
  50. trigger_error('WRONG_ACTIVATION');
  51. }
  52. // Do not allow activating by non administrators when admin activation is on
  53. // Only activation type the user should be able to do is INACTIVE_REMIND
  54. // or activate a new password which is not an activation state :@
  55. if (!$user_row['user_newpasswd'] && $user_row['user_inactive_reason'] != INACTIVE_REMIND && $config['require_activation'] == USER_ACTIVATION_ADMIN && !$auth->acl_get('a_user'))
  56. {
  57. if (!$user->data['is_registered'])
  58. {
  59. login_box('', $user->lang['NO_AUTH_OPERATION']);
  60. }
  61. send_status_line(403, 'Forbidden');
  62. trigger_error('NO_AUTH_OPERATION');
  63. }
  64. $update_password = ($user_row['user_newpasswd']) ? true : false;
  65. if ($update_password)
  66. {
  67. $sql_ary = array(
  68. 'user_actkey' => '',
  69. 'user_password' => $user_row['user_newpasswd'],
  70. 'user_newpasswd' => '',
  71. 'user_login_attempts' => 0,
  72. );
  73. $sql = 'UPDATE ' . USERS_TABLE . '
  74. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  75. WHERE user_id = ' . $user_row['user_id'];
  76. $db->sql_query($sql);
  77. $user->reset_login_keys($user_row['user_id']);
  78. $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array(
  79. 'reportee_id' => $user_row['user_id'],
  80. $user_row['username']
  81. ));
  82. }
  83. if (!$update_password)
  84. {
  85. include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  86. user_active_flip('activate', $user_row['user_id']);
  87. $sql = 'UPDATE ' . USERS_TABLE . "
  88. SET user_actkey = ''
  89. WHERE user_id = {$user_row['user_id']}";
  90. $db->sql_query($sql);
  91. // Create the correct logs
  92. $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_ACTIVE_USER', false, array(
  93. 'reportee_id' => $user_row['user_id']
  94. ));
  95. if ($auth->acl_get('a_user'))
  96. {
  97. $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_ACTIVE', false, array($user_row['username']));
  98. }
  99. }
  100. if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !$update_password)
  101. {
  102. /* @var $phpbb_notifications \phpbb\notification\manager */
  103. $phpbb_notifications = $phpbb_container->get('notification_manager');
  104. $phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
  105. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  106. $messenger = new messenger(false);
  107. $messenger->template('admin_welcome_activated', $user_row['user_lang']);
  108. $messenger->set_addresses($user_row);
  109. $messenger->anti_abuse_headers($config, $user);
  110. $messenger->assign_vars(array(
  111. 'USERNAME' => htmlspecialchars_decode($user_row['username']))
  112. );
  113. $messenger->send($user_row['user_notify_type']);
  114. $message = 'ACCOUNT_ACTIVE_ADMIN';
  115. }
  116. else
  117. {
  118. if (!$update_password)
  119. {
  120. $message = ($user_row['user_inactive_reason'] == INACTIVE_PROFILE) ? 'ACCOUNT_ACTIVE_PROFILE' : 'ACCOUNT_ACTIVE';
  121. }
  122. else
  123. {
  124. $message = 'PASSWORD_ACTIVATED';
  125. }
  126. }
  127. /**
  128. * This event can be used to modify data after user account's activation
  129. *
  130. * @event core.ucp_activate_after
  131. * @var array user_row Array with some user data
  132. * @var string message Language string of the message that will be displayed to the user
  133. * @since 3.1.6-RC1
  134. */
  135. $vars = array('user_row', 'message');
  136. extract($phpbb_dispatcher->trigger_event('core.ucp_activate_after', compact($vars)));
  137. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  138. trigger_error($user->lang[$message]);
  139. }
  140. }