PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/core/resend.php

http://snowcms.googlecode.com/
PHP | 189 lines | 104 code | 30 blank | 55 comment | 12 complexity | dd2d517223a0eb8fb0263f663499f03d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////
  3. // SnowCMS v2.0 //
  4. // By the SnowCMS Team //
  5. // www.snowcms.com //
  6. // Released under the Microsoft Reciprocal License //
  7. // www.opensource.org/licenses/ms-rl.html //
  8. ////////////////////////////////////////////////////////////////////////////
  9. // //
  10. // SnowCMS originally pawned by soren121 started in early 2008 //
  11. // //
  12. ////////////////////////////////////////////////////////////////////////////
  13. // //
  14. // SnowCMS v2.0 began in November 2009 //
  15. // //
  16. ////////////////////////////////////////////////////////////////////////////
  17. // File version: SnowCMS 2.0 //
  18. ////////////////////////////////////////////////////////////////////////////
  19. if(!defined('INSNOW'))
  20. {
  21. die('Nice try...');
  22. }
  23. // Title: Resend activation email
  24. if(!function_exists('resend_view'))
  25. {
  26. /*
  27. Function: resend_view
  28. Handles the resending of activation emails, you know, just incase ;)
  29. Parameters:
  30. none
  31. Returns:
  32. void - Nothing is returned by this function.
  33. Note:
  34. This function is overloadable.
  35. */
  36. function resend_view()
  37. {
  38. api()->run_hooks('resend_view');
  39. if(member()->is_logged())
  40. {
  41. redirect(baseurl());
  42. }
  43. elseif(settings()->get('registration_type', 'int', 1) != 3)
  44. {
  45. theme()->set_title(l('An Error Occurred'));
  46. theme()->header();
  47. api()->context['error_title'] = l('Registration Error');
  48. api()->context['error_message'] = l('It appears that the current type of registration isn\'t email activation, so you cannot resend your activation email.');
  49. theme()->render('error');
  50. exit;
  51. }
  52. $form = api()->load_class('Form');
  53. $form->add('resend_form', array(
  54. 'action' => baseurl('index.php?action=resend'),
  55. 'method' => 'post',
  56. 'submit' => l('Resend activation'),
  57. 'callback' => 'resend_process',
  58. ));
  59. $form->current('resend_form');
  60. $form->add_input(array(
  61. 'name' => 'member_name',
  62. 'type' => 'string',
  63. 'label' => l('Username'),
  64. 'subtext' => l('The name you used to register your account.'),
  65. 'callback' => create_function('$name, &$value, &$error', '
  66. if(empty($value))
  67. {
  68. $error = l(\'Please enter a username or email address.\');
  69. return false;
  70. }
  71. return true;'),
  72. 'default_value' => !empty($_REQUEST['member_name']) ? $_REQUEST['member_name'] : '',
  73. ));
  74. // So, you submitting it?
  75. if(!empty($_POST['resend_form']))
  76. {
  77. $form->process('resend_form');
  78. }
  79. theme()->set_title(l('Request a New Activation Email'));
  80. api()->context['form'] = $form;
  81. theme()->render('resend_view');
  82. }
  83. }
  84. if(!function_exists('resend_process'))
  85. {
  86. /*
  87. Function: resend_process
  88. Processes the form for resending your activation email.
  89. Parameters:
  90. array $resend - The array containing the form data.
  91. array &$errors
  92. Returns:
  93. bool - Returns true on success, false on failure.
  94. Note:
  95. This function is overloadable.
  96. */
  97. function resend_process($resend, &$errors = array())
  98. {
  99. $members = api()->load_class('Members');
  100. // Let's see if the member even exists... ;)
  101. $member_id = $members->name_to_id($resend['member_name']);
  102. if(empty($member_id))
  103. {
  104. $errors[] = l('There is no account with that username or email address.');
  105. return false;
  106. }
  107. // Load up the member information.
  108. $members->load($member_id);
  109. $member_info = $members->get($member_id);
  110. // Is the account already activated? No go!
  111. if($member_info['is_activated'] != 0)
  112. {
  113. $errors[] = l('That account is already activated and you can <a href="%s">log in</a> if it is your account.', baseurl('index.php?action=login'));
  114. return false;
  115. }
  116. elseif(isset($member_info['data']['activation_last_resent']) && ($member_info['data']['activation_last_resent'] + 900) > time_utc())
  117. {
  118. $errors[] = l('You can only request a new activation email every 15 minutes. Please try again in %u minutes.', ceil((900 - (time_utc() - $member_info['data']['activation_last_resent'])) / 60));
  119. return false;
  120. }
  121. // Well, let's regenerate your activation code.
  122. $member_acode = sha1($members->rand_str(mt_rand(30, 40)));
  123. $members->update($member_id, array(
  124. 'member_acode' => $member_acode,
  125. 'data' => array(
  126. 'activation_last_resent' => time_utc(),
  127. ),
  128. ));
  129. // Resend it! Woo!
  130. if(!function_exists('register_send_email'))
  131. {
  132. require_once(coredir. '/register.php');
  133. }
  134. if(!register_send_email($member_id))
  135. {
  136. // We should tell the administrator that the message couldn't be sent.
  137. trigger_error(l('An error occurred while trying to resend the user their activation email. This could indicate that the SMTP settings are incorrect or the server does not have the mail() function enabled.'), E_USER_WARNING);
  138. // Then tell the user! D:
  139. $errors[] = l('An error occurred while trying to resend your activation email. Please contact the administrator if this issue continues.');
  140. return false;
  141. }
  142. api()->add_filter('resend_form_messages', create_function('$value', '
  143. $value[] = l(\'A new activation email has been sent. The email should be received shortly.\');
  144. return $value;'));
  145. return true;
  146. }
  147. }
  148. ?>