PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/ucp/ucp_remind.php

https://bitbucket.org/jablonski/yebood
PHP | 126 lines | 81 code | 25 blank | 20 comment | 10 complexity | 0a3ab38800edfc38f10020c178ef42d6 MD5 | raw file
Possible License(s): AGPL-1.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_remind
  19. * Sending password reminders
  20. * @package ucp
  21. */
  22. class ucp_remind
  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. $username = request_var('username', '', true);
  30. $email = strtolower(request_var('email', ''));
  31. $submit = (isset($_POST['submit'])) ? true : false;
  32. if ($submit)
  33. {
  34. $sql = 'SELECT user_id, username, user_permissions, user_email, user_jabber, user_notify_type, user_type, user_lang, user_inactive_reason
  35. FROM ' . USERS_TABLE . "
  36. WHERE user_email_hash = '" . $db->sql_escape(phpbb_email_hash($email)) . "'
  37. AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  38. $result = $db->sql_query($sql);
  39. $user_row = $db->sql_fetchrow($result);
  40. $db->sql_freeresult($result);
  41. if (!$user_row)
  42. {
  43. trigger_error('NO_EMAIL_USER');
  44. }
  45. if ($user_row['user_type'] == USER_IGNORE)
  46. {
  47. trigger_error('NO_USER');
  48. }
  49. if ($user_row['user_type'] == USER_INACTIVE)
  50. {
  51. if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL)
  52. {
  53. trigger_error('ACCOUNT_DEACTIVATED');
  54. }
  55. else
  56. {
  57. trigger_error('ACCOUNT_NOT_ACTIVATED');
  58. }
  59. }
  60. // Check users permissions
  61. $auth2 = new auth();
  62. $auth2->acl($user_row);
  63. if (!$auth2->acl_get('u_chgpasswd'))
  64. {
  65. trigger_error('NO_AUTH_PASSWORD_REMINDER');
  66. }
  67. $server_url = generate_board_url();
  68. // Make password at least 8 characters long, make it longer if admin wants to.
  69. // gen_rand_string() however has a limit of 12 or 13.
  70. $user_password = gen_rand_string_friendly(max(8, mt_rand((int) $config['min_pass_chars'], (int) $config['max_pass_chars'])));
  71. // For the activation key a random length between 6 and 10 will do.
  72. $user_actkey = gen_rand_string(mt_rand(6, 10));
  73. $sql = 'UPDATE ' . USERS_TABLE . "
  74. SET user_newpasswd = '" . $db->sql_escape(phpbb_hash($user_password)) . "', user_actkey = '" . $db->sql_escape($user_actkey) . "'
  75. WHERE user_id = " . $user_row['user_id'];
  76. $db->sql_query($sql);
  77. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  78. $messenger = new messenger(false);
  79. $messenger->template('user_activate_passwd', $user_row['user_lang']);
  80. $messenger->to($user_row['user_email'], $user_row['username']);
  81. $messenger->im($user_row['user_jabber'], $user_row['username']);
  82. $messenger->assign_vars(array(
  83. 'USERNAME' => htmlspecialchars_decode($user_row['username']),
  84. 'PASSWORD' => htmlspecialchars_decode($user_password),
  85. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
  86. );
  87. $messenger->send($user_row['user_notify_type']);
  88. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  89. $message = $user->lang['PASSWORD_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  90. trigger_error($message);
  91. }
  92. $template->assign_vars(array(
  93. 'USERNAME' => $username,
  94. 'EMAIL' => $email,
  95. 'S_PROFILE_ACTION' => append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=sendpassword'))
  96. );
  97. $this->tpl_name = 'ucp_remind';
  98. $this->page_title = 'UCP_REMIND';
  99. }
  100. }
  101. ?>