I need to be able to allow a user to request a one time login link in place of logging in with a username and password. How could I allow an anonymous user to type a valid account email address into a text field and then hit a button to have a login link sent to that email account? At the time the page is generated the current user is anonymous. Is there a way I can lookup the email address that is entered by the user and if it is valid then use the API of this module to send a link to THAT account? The user would just get back a Thank You message and would not be logged in until they click on the link sent to them by this module.

Thanks
Dano

Comments

danielb’s picture

Yeah the user_load() function allows you to load like that

$account = user_load(array('mail' => 'email@address.here'));

You'll need to check the $user is not FALSE, then use the function from this module: login_one_time_send_mail().

danielb’s picture

Priority: Critical » Normal
Status: Active » Fixed
dano’s picture

Status: Fixed » Active

Thanks for the quick response. I have been struggling with this trying to get it to work with no success. I am collecting an email address in $email and using the user_load to fetch the user object for that email and then use that to call the login_one_time_send_mail(). I end up with an error that says "Unable to send e-mail. Please contact the site administrator if the problem persists."

Log in one time works ok when I click on the normal button in another users account page but not when I call it manually here.

Any ideas? I am desperate! :-)

Here is my code BTW: I can echo $email and it is getting passed properly from the form. Also user_load is accepting it just fine. The error comes when I call the login_onetime function.

// Has the form been submitted?
if (isset($_POST['submit']))
   {
   $email = htmlentities($_POST['email']);
   if ($myuser = user_load(array('mail' => $email)) && ($email != null))
      {
      login_one_time_send_mail($myuser);
      drupal_goto($path = 'content/login-link-has-been-sent', $query = NULL, $fragment = NULL, $http_response_code = 302);
      exit;
      }
   else
      {
      printf("<br>The address <strong>%s</strong> is <strong>invalid!</strong><br>PLEASE TRY AGAIN!<br><br><br>", $email);
      }
   }
danielb’s picture

try login_one_time_send_mail($myuser, $_GET['q']);

danielb’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.