PageRenderTime 114ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/ucp/ucp_activate.php

https://github.com/marcfuentes/dal2012_noestoysolo
PHP | 147 lines | 100 code | 27 blank | 20 comment | 23 complexity | 2daf1afdafa5995b590944973b32fedd MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  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. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * ucp_activate
  19. * User activation
  20. * @package ucp
  21. */
  22. class ucp_activate
  23. {
  24. var $u_action;
  25. function main($id, $mode)
  26. {
  27. global $config, $phpbb_root_path, $phpEx;
  28. global $db, $user, $auth, $template;
  29. $user_id = request_var('u', 0);
  30. $key = request_var('k', '');
  31. $sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason
  32. FROM ' . USERS_TABLE . "
  33. WHERE user_id = $user_id";
  34. $result = $db->sql_query($sql);
  35. $user_row = $db->sql_fetchrow($result);
  36. $db->sql_freeresult($result);
  37. if (!$user_row)
  38. {
  39. trigger_error('NO_USER');
  40. }
  41. if ($user_row['user_type'] <> USER_INACTIVE && !$user_row['user_newpasswd'])
  42. {
  43. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  44. trigger_error('ALREADY_ACTIVATED');
  45. }
  46. if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] != $key)
  47. {
  48. trigger_error('WRONG_ACTIVATION');
  49. }
  50. // Do not allow activating by non administrators when admin activation is on
  51. // Only activation type the user should be able to do is INACTIVE_REMIND
  52. // or activate a new password which is not an activation state :@
  53. if (!$user_row['user_newpasswd'] && $user_row['user_inactive_reason'] != INACTIVE_REMIND && $config['require_activation'] == USER_ACTIVATION_ADMIN && !$auth->acl_get('a_user'))
  54. {
  55. if (!$user->data['is_registered'])
  56. {
  57. login_box('', $user->lang['NO_AUTH_OPERATION']);
  58. }
  59. trigger_error('NO_AUTH_OPERATION');
  60. }
  61. $update_password = ($user_row['user_newpasswd']) ? true : false;
  62. if ($update_password)
  63. {
  64. $sql_ary = array(
  65. 'user_actkey' => '',
  66. 'user_password' => $user_row['user_newpasswd'],
  67. 'user_newpasswd' => '',
  68. 'user_pass_convert' => 0,
  69. 'user_login_attempts' => 0,
  70. );
  71. $sql = 'UPDATE ' . USERS_TABLE . '
  72. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  73. WHERE user_id = ' . $user_row['user_id'];
  74. $db->sql_query($sql);
  75. add_log('user', $user_row['user_id'], 'LOG_USER_NEW_PASSWORD', $user_row['username']);
  76. }
  77. if (!$update_password)
  78. {
  79. include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  80. user_active_flip('activate', $user_row['user_id']);
  81. $sql = 'UPDATE ' . USERS_TABLE . "
  82. SET user_actkey = ''
  83. WHERE user_id = {$user_row['user_id']}";
  84. $db->sql_query($sql);
  85. // Create the correct logs
  86. add_log('user', $user_row['user_id'], 'LOG_USER_ACTIVE_USER');
  87. if ($auth->acl_get('a_user'))
  88. {
  89. add_log('admin', 'LOG_USER_ACTIVE', $user_row['username']);
  90. }
  91. }
  92. if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !$update_password)
  93. {
  94. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  95. $messenger = new messenger(false);
  96. $messenger->template('admin_welcome_activated', $user_row['user_lang']);
  97. $messenger->to($user_row['user_email'], $user_row['username']);
  98. $messenger->anti_abuse_headers($config, $user);
  99. $messenger->assign_vars(array(
  100. 'USERNAME' => htmlspecialchars_decode($user_row['username']))
  101. );
  102. $messenger->send($user_row['user_notify_type']);
  103. $message = 'ACCOUNT_ACTIVE_ADMIN';
  104. }
  105. else
  106. {
  107. if (!$update_password)
  108. {
  109. $message = ($user_row['user_inactive_reason'] == INACTIVE_PROFILE) ? 'ACCOUNT_ACTIVE_PROFILE' : 'ACCOUNT_ACTIVE';
  110. }
  111. else
  112. {
  113. $message = 'PASSWORD_ACTIVATED';
  114. }
  115. }
  116. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  117. trigger_error($user->lang[$message]);
  118. }
  119. }
  120. ?>