I need to send messages for some users via PHP with login url, for users can login into site by this url without entering password.
But I can't find the function in your module, that return this url. Did your module have any API for get login url for user via uid?
Something like user_get_loginurl($uid,$url) that returns url as string?
If your module must not used for this way, can you recommend me other modules that can do this?

Comments

murz’s picture

Seems that I can use for generate url something like this construction?

$url=urllogin_encode($uid, variable_get('urllogin_codekey', 0), urllogin_passphrase().'/my/destination');

But will be better to use function with less parameters.

seandunaway’s picture

Something like this instead:

$href = 'node/' . $node->nid . '/edit';
// Automatically log in, if urllogin is available.
if (module_load_include('inc', 'urllogin', 'urllogin_security')) {
  $href = 'l/' . urllogin_encode($node->uid, variable_get('urllogin_codekey', 0), urllogin_passphrase()) . '/' . $href;
}
return l(t('Edit this node as the author'), $href, array('absolute' => TRUE));
seandunaway’s picture

I agree this could be more clear in the documentation, 'cause I had to read the entire source of the module to figure it out.

murz’s picture

Because my site needs only API for generating those urls and login process, without other additional functional, I create my own lightweight module for those needs: http://drupal.org/sandbox/murz/1779836
Thanks to author of this module for the idea and code examples.
My module have only function for generating login url and callback for processing those urls.
Maybe it will help anything else.

darrellduane’s picture

Issue summary: View changes

Here is a function that works for me :




/**
 * This is an API function to get a urllogin link by another module.
 *
 * @return
 *   A URL for the given UID to login with
 */
function urllogin_get_login_link($uid,$dest='') {
  $resultmsg = '';
  $account = _urllogin_testuid($uid, $resultmsg);
  watchdog('urllogin', $resultmsg . ' - urllogin_get_login_link()' , array(), WATCHDOG_NOTICE);
  if(!count($account)) {

    return NULL;

  }else{

    $codekey = variable_get('urllogin_codekey', 0);
    $passphrase = urllogin_passphrase();
    $thissite = url('l/', array('absolute' => TRUE));
    $destination = '/' . $dest;

    return $thissite . urllogin_encode($uid, $codekey, $passphrase) . $destination;
  }
}  // done urllogin_get_login_link
andrewfn’s picture

This looks like a good idea. I'll take a look at incorporating it. Thanks.

darrellduane’s picture

Here's a patch for the latest commit to add this API function into the code.

It also cleans up some of the documentation.

darrellduane’s picture

Please don't use this patch for final inclusion-- you can use it for testing, but I've done a lot more work on this module and incorporated all of my fixes, including the fixes here in the patch

https://www.drupal.org/node/2041029

daluxz’s picture

Status: Active » Needs work

I'm not so sure if an API function to create the login URL is very useful.
I think it would be more useful to have an API function which generates only the hash.
Once you know the hash, it's easy to generate a link from that.

Let's say there is a good usecase for generating a login URL as well.
I think the following should happen:

  • Create an extra API-function where you only generate the hash.
  • Make use of the extra API-functions. The code of this module could probably be simplified by using the new API functions. This patch should incorporate these changes as well.
  • The use of watchdog() and $resultmsg. You shouldn't use variables in watchdog-messages. "The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact." This is probably an issue that should be worked out seperately, since that happens throughout the urllogin module.
  • The return value of the function:
    $thissite = url('l/', array('absolute' => TRUE));
        $destination = '/' . $dest;
    
        return $thissite . urllogin_encode($uid, $codekey, $passphrase) . $destination;

    - Could be a one-liner, which might be easier to read: return url('l/' . urllogin_encode($uid, $codekey, $passphrase) . '/' . $dest, array('absolute' => TRUE));
    - You might not want to return an absolute URL. You could add an extra parameter to the function, and give it a default value

  • Remove the comment // Done urllogin_get_login_link"
  • Personal preference: Could you change !count($account) with empty($account)? The count() got me confused about what _urllogin_testuid() returns.
darrellduane’s picture

Great points, I'll work on cleaning this up.

jvdkolk’s picture

Any news on this issue? I would love to use this api :).

W.M.’s picture

Any news guys?