email_required.pages.inc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Form to submit for an email verification
  4. */
  5. function email_required_verification_form($form, &$form_state) {
  6. global $user;
  7. drupal_set_title(t('You must verify your email address to continue'));
  8. $form['warning'] = array(
  9. '#type' => 'item',
  10. '#markup' => t('The page you requested requires that you first verify your email address. Clicking the button below will send an email to the address associated with your account. It will contain a link that, when clicked, will verify your email address. You will only have to do this once.'),
  11. );
  12. $form['email'] = array(
  13. '#type' => 'item',
  14. '#markup' => t('Your current email address is %email. !link to change it before verifying.', array('%email' => $user->mail, '!link' => l(t('Click here'), "user/{$user->uid}/edit", array('query' => array('destination' => 'email/verify'))))),
  15. );
  16. $form['submit'] = array(
  17. '#type' => 'submit',
  18. '#value' => t('Send the verification email'),
  19. );
  20. return $form;
  21. }
  22. /**
  23. * Submit handler for the email verification form
  24. */
  25. function email_required_verification_form_submit(&$form, &$form_state) {
  26. global $user;
  27. // Insert a new hash
  28. email_required_create_hash($user);
  29. // Send the email
  30. drupal_mail('email_required', 'verification', $user->mail, user_preferred_language($user));
  31. // Set a message
  32. drupal_set_message(t('A verification email has been sent to you.'));
  33. // Log the action
  34. watchdog('email_required', 'Verification email sent to !user (!uid)', array('!user' => $user->name, '!uid' => $user->uid));
  35. // Go home
  36. $form_state['redirect'] = '<front>';
  37. }
  38. /**
  39. * Page callback for verification hash links
  40. *
  41. * @param $account
  42. * A user object specified in the link
  43. * @param $string
  44. * The hash string on the URL
  45. */
  46. function email_required_verification_page($account, $string) {
  47. global $user;
  48. $output = '';
  49. // See if the user is already validated
  50. if (email_required_user_is_validated($account)) {
  51. $output .= t('You have already validated your email address.');
  52. }
  53. // Load the hash for this user and see if it's a match
  54. else if (($hash = email_required_load_hash($account)) && ($hash->hash == $string)) {
  55. // Verify the email address
  56. email_required_validate_hash($account);
  57. // Log the action
  58. watchdog('email_required', '!user (!uid) has validated their email address.', array('!user' => $account->name, '!uid' => $account->uid));
  59. // Set a message
  60. $output = t('Your email address has been verified.');
  61. // Set the title
  62. drupal_set_title(t('Verified!'));
  63. }
  64. else {
  65. $output .= t('Invalid verification link. It is possible that this link has expired. !link to have another one emailed to you.', array('!link' => l(t('Click here'), 'email/verify')));
  66. }
  67. $output .= "<br/><br/>" . l(t('Return to the homepage'), '<front>');
  68. return $output;
  69. }