We'd like users to choose their password on registration.
However they shouldn't be capable of logging in till they confirmed email.

An additional checkbox "Disable pre authentication role to login" could be added.
On authentication check we might test for this setting and ban login. In our addon code we also resent validation email and displayed an error message about need of mail confirmation.

Would you like this feature?

Comments

miro_dietiker’s picture

BTW we've used something like this in our custom contrib user_login_authenticate_validate replacement:

// logintoboggan disallow incomplete logins
  if (module_exists('logintoboggan')) {
    $id = logintoboggan_validating_id();
    $in_pre_auth_role = in_array($id, array_keys($account->roles));

    if ($in_pre_auth_role) {
      form_set_error('logintoboggan-role', t('Your registration has not completed yet.'));
      logintoboggan_resend_validation($account);
      return;
    }
  }

We additionally would need to check the setting and add it to the admin form.

hunmonk’s picture

Status: Active » Closed (works as designed)

i had this debate before with somebody.

core's workflow is to log somebody in if they can create their own password -- this is a sensible convenience. LT extends the registration workflow by allowing the insertion of a pre-auth role in the case when user's set their own password, which helps to prevent spam registrations causing a problem -- admins can simply set the pre-auth permissions to a level that suits the site (which can be the same level of permissions that the anonymous user has if you're really security conscious).

everybody has a special feature they would like to see -- i'm still not convinced that this feature is really worth the extra code. not to mention that it seems potentially confusing for users to have a user name and password, but not be able to log into a site -- i don't recall seeing other websites using that workflow.

amateescu’s picture

i'm still not convinced that this feature is really worth the extra code

are you kidding? i've been trying to implement this feature for almost two days and can't seem to make it.

i think this would be a great addition for this module because, personally, i can't imagine how a user email verification system would allow the user to log in (with any role) if he hasn't validated his email address.

miro_dietiker’s picture

Status: Closed (works as designed) » Active

Reactivating once to try explaining the clear need:

A user that is not validated should really not be able to login.
We're encountered many problems with other modules in (loggedin) preauth role state. First of all, users really think they're authenticated and the registration was passed finally. They think "OK, i'm in, so the registration process must have been completed". They tend to ignore the activation mail. And they finally also don't understand why there's some limited functionality at some point - since they see they're loggedin. Indeed already two customers (their administration team) where unable to understand the idea of being logged-in even if not yet validated.

On a big site it is very complex to setup the special pre-auth role. All/Some permissions you allow to a authenticated user need to be added to the pre-auth role. You also need to check the site functionality twice -- once for registered, once for pre-auth. The application complexity is becoming bigger.
We're encountering problems with modules that don't show some features due to missing authenticated role. Sure this is a bad implementation (because they rely on the authenticated state instead of a permission.. in fact i was unable to identify all sources of this mess on a huge platform...) but we can be much more failproof from LoginToboggan point.

Simply allowing to drop this intermediate login state makes many things easyer.

So i see this extension as a process/state simplification feature.

hunmonk’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

are you kidding? i've been trying to implement this feature for almost two days and can't seem to make it.

i don't see why that equates to making it a worthwhile addition to the module. try something like this in your own mini-module:

function prevent_pre_auth_login_form_alter((&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
    case 'user_login_block':
      $form['#validate'][] = 'prevent_pre_auth_login_validate';
      break;
  }
}

function prevent_pre_auth_login_validate($form, &$form_state) {
  if (isset($form_state['values']['name']) && $form_state['values']['name']) {
    if ($account = user_load(array('name' => $form_state['values']['name']))) {
      $validating_id = logintoboggan_validating_id();
      if ($validating_id != DRUPAL_AUTHENTICATED_RID && in_array($validating_id, array_keys($account->roles))) {
        form_set_error('name', t("You cannot log in until you have validated your user account"));
      }
    }
  }
}

@miro_dietiker: you make some valid points. however, instead of getting into a point by point debate, i'd like to point out the larger problem: core's registration workflow has fundamental problems.

i have to do many unholy things to make LT function as well as it does, and i'm not sure i'm interested in piling even more code in there. the correct direction to go is: fix core's limitations by moving LT-like functionality to core:
#783184: Add email validation to registration workflow

now, i realize that 8.x is a long way away. i'm willing to reconsider this feature for 7.x (not for 6.x, as that branch is effective closed for new features). the example code above is written for 6.x, so anybody who really wants this in 6.x can take that ball and run with it.

miro_dietiker’s picture

Providing modified version of our setup for D6.

Note that the login happens in the validation function.
If we append this in the validate stack we're doing something wrong. See user_login_final_validate stating "Should be the last validator".

You might need to scan for the right position or unshift at the very beginning.

Finally what we're doing is replacing the user_login_authenticate_validate function since this shouldn't be executed if this earlier rid validation fails.

Also we're resending the email each time a user tries to login with not-yet-validated credentials.

<?php
function prevent_pre_auth_login_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
    case 'user_login_block':
      $key = array_search('user_login_authenticate_validate', $form['#validate']);
      $form['#validate'][$key] = 'prevent_pre_auth_login_validate';
      break;
  }
}

function prevent_pre_auth_login_validate($form, &$form_state) {
  // pre-auth check (logintoboggan.module)
  if (isset($form_state['values']['name']) && $form_state['values']['name']) {
    if ($account = user_load(array('name' => $form_state['values']['name']))) {
      $validating_id = logintoboggan_validating_id();
      if ($validating_id != DRUPAL_AUTHENTICATED_RID && in_array($validating_id, array_keys($account->roles))) {
        form_set_error('name', t("You cannot log in until you have validated your user account"));
        // resend validation email
        logintoboggan_resend_validation($account);
        // terminate login processing
        return;
      }
    }
  }

  // regular drupal authentication_validate check
  // this doesn't set errors for wrong password submissions!
  user_authenticate($form_state['values']);
}
?>

A tiny step forward.

miro_dietiker’s picture

Status: Active » Postponed

Added a maintainable project (currently only D6) for this functionality due to contact requests and our usage in multiple modules.
http://drupal.org/project/logintoboggan_prevent

I'm also open to add a D7 version if this is the preferred way.
We can then check the stats and have data to decide if this is a commonly used LT feature.

YK85’s picture

awesome - I will be trying out your module soon miro_dietiker!

hunmonk’s picture

Status: Postponed » Closed (won't fix)

@miro: yes, please update your module for 7.x. the real work should happen at #783184: Add email validation to registration workflow -- i'm not putting any more time into this in LT.