0

I want to create simple confirmation page. It means that after user change his email then he gets confirmation email with link to page. This link contains token. This link should open page for user with appropriate message (success or fail if token expired). I want to create simple module, But I don't know which hook I should use to create this simple page. I must check this token by sending POST request to REST API before rendering page.

Any advice?

0

I suggest you use hook_user_update. Then you compare $account->mail and $account->original->mail. If the two email addresses are different, the user's email address changed. Next you generate the token and send an email to the user with a link to your page.

For the page, create a new menu entry via hook_menu and do the logic for the REST call there. You can get URL query parameters (especially the token) by using drupal_get_query_parameters. Maybe you should ensure that the token is unique and store it with the email address and the creation time (to check if it has expired) in the database.

The documentation for hook_menu (or 99% of all other modules available) should give you an example on how to use it.

| improve this answer | |
0

I wrote a blog post that you may find helpful. Good luck!

| improve this answer | |
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Krishna Mohan Jun 23 '15 at 12:50
0
function custom_menu() {
  $items = array();
  $items['admin/sendmail/%'] = array(
    'title' => t('Delete Entry'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_confirm_form'),
    'access arguments' => array('send mail'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

  function custom_confirm_form($form_state){
    return confirm_form($form, t('Are you sure you want to Send Mail?'), //message title
    'admin/send-mail', //redirect if cancelled
    t('Only say yes if you are really sure. Otherwise please click on cancel button.'), //message description
    t('Yes'), //confirm button text
    t('Cancel') //cancel button text
  );
}

function custom_confirm_form_submit($form, &$form_state){
   //verify that the form was confirmed
  if ($form_state['values']['confirm']) {  
     custom_send_mail();
  }
}
| improve this answer | |
  • I thought this same at first, but my PM told me that it's not a form, but page with simple message of it. User should not do anything, there's only 'success' or 'fail' message. – MathewDragon Jun 25 '15 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.