Provide "remember me" checkbox on registration form (when users are able to login immediately)

greggles - June 11, 2009 - 22:03
Project:Persistent Login
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:greggles
Status:closed
Description

Drupal 6 introduced a feature where users can login immediately. The username/password fields are provided on the registration page and immediately after they are validated/submitted, the user is logged in.

If that mode is enabled, persistent login should provide the checkbox on the registration form.

This is slightly more complex than the normal case because registration forms can have more fields stored in funkier ways than login forms. Fortunately there are only two formats and it is possible to reliably detect them.

#1

greggles - June 11, 2009 - 23:58
Assigned to:Anonymous» greggles
Status:active» needs review

And a patch.

AttachmentSize
489180_persistent_login_register.patch 4.11 KB

#2

markus_petrux - June 16, 2009 - 08:33
Status:needs review» needs work

Hi, :)

This looks like a nice addition, probably something missed when porting the module to D6.

I think the patch needs a bit more love, though:

1) In our implementation of hook_form_alter(), we should not show the "Remember me" checkbox when the account is created by an admin. We shouldn't either if the account requires admin approval. So we probably need to add the following checks: variable_get('user_register', 1) != 1 || !user_access('administer users'). ?

2) We do not need to implement hook_user('insert') because Drupal will log the user in when the account is not created by an admin. In this case, Drupal will still invoke hook_user('login'), which is where we already have the code to create the PL cookie.

3) In our after_build callback, maybe we want to add the "Remember me" checkbox next to the password confirmation field, not before the submit button, just in case another module adds something else to this form?

#3

greggles - June 16, 2009 - 13:59

I definitely agree with points 1 and 3. Thanks for checking those.

Regarding point 2, in my testing hook_user('login') was not invoked. Perhaps there was another module on the dev site which broke that, but can you confirm that you tested this?

#4

markus_petrux - June 16, 2009 - 14:52

On 2: I haven't tested, just looked at user.module.

Unless I'm missing something, I believe hook_user('login') is executed.

If we look at user_register_submit(), we can see the following snippet:

<?php
   
else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
     
// No e-mail verification is required, create new user account, and login
      // user immediately.
     
_user_mail_notify('register_no_approval_required', $account);
      if (
user_authenticate(array_merge($form_state['values'], $merge_data))) {
       
drupal_set_message(t('Registration successful. You are now logged in.'));
      }
     
$form_state['redirect'] = '';
      return;
    }
?>

This is the code that's executed when an anonymous user registers a new account and email verification is not enabled, which is the case where we would add the "Remember me" checkbox.

When user_authenticate() is executed, the last step, if no additional errors are found, user_authenticate_finalize() is executed, and the last statement here is an invocation of hook_user('login').

#5

markus_petrux - August 23, 2009 - 16:29

Just wanted to mention that I expect to have a bit of time for this. In fact, I wanted to get back to this a few weeks ago. But I could not find the time.

Well, I'll post updates here as progress is made...

My intention is to clear the issue queue of PL before creating an stable release. But we somehow depend on a Drupal core issue: #458704: Removing "www." causes problems when creating cookies for www.example.com and example.com :( ...that's related to #456334: Problems when cookie domains are www.example.com and subdomain.example.com (drupal removes www.) (PL issue already committed).

#6

markus_petrux - August 23, 2009 - 19:05
Status:needs work» needs review

In regards to 2) above, about hook_user('login')... Yep! I got "Registration successful. You are now logged in." with a persistent login created during account registration. :)

In the user register form, the "Remember Me" checkbox will only be rendered if:

- Visitors can create accounts and no administrator approval is required.
- E-mail verification is not required when a visitor creates an account.
- The form is not being executed by a user administrator.

Please, test and let me know. Thanks for your patience.

AttachmentSize
persistent_login-489180-6.patch 5.35 KB

#7

markus_petrux - September 20, 2009 - 23:15
Title:if users are able to login immediately, provide "remember me" checkbox on registration form» Provide "remember me" checkbox on registration form (when users are able to login immediately)
Status:needs review» fixed

Committed to CVS in the hope that it can be easily tested.

http://drupal.org/cvs?commit=265370

#8

System Message - October 4, 2009 - 23:20
Status:fixed» closed

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

#9

Mr.Alinaki - October 9, 2009 - 09:39
Status:closed» active

It would be nice to see integration with LoginToBoggan "Immediate login" option

#10

markus_petrux - October 9, 2009 - 09:48
Status:active» closed

Please, open a separate feature request. It would be nice if it comes with a patch for review. Otherwise, it may not happen.

 
 

Drupal is a registered trademark of Dries Buytaert.