Steps to reproduce:
1. Enable password policy and add password expiry rule.
1. Enable modal forms for login form.
2. Log in using the user whose password has expired.
3. Ideally the user should be redirected to account edit form (something like this - user/25/edit/account?destination=node/30).
4. Redirection fails and import statements are displayed in popup.

In password policy module file, in function _password_policy_go_to_password_change_page, drupal_goto is used to redirect user to password change screen.

I tried to replace drupal_goto with following code:

$password_change_path = _password_policy_get_preferred_password_change_path();
ctools_include('modal');
ctools_include('ajax');
$output = array();
ctools_add_js('ajax-responder');
$output[] = ctools_modal_command_dismiss();
$output[] = ctools_ajax_command_redirect($password_change_path, 2000);
print ajax_render($output);

But this does not work. I understand this is not a complete solution. We have to add a check, if modal forms is enabled for login form then only ctools code should run, goto should work in other cases.

I have posted issue earlier here: https://www.drupal.org/node/2541194

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pooja.sarvaiye created an issue. See original summary.

pooja.sarvaiye’s picture

Title: Redirect after password expiry in fails for modal forms login » Redirect after password expiry fails for modal forms login
pooja.sarvaiye’s picture

Issue summary: View changes
rteijeiro’s picture

pooja.sarvaiye’s picture

neerajskydiver’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: password_policy-modal_forms_support-2583109-5.patch, failed testing.

pooja.sarvaiye’s picture

pooja.sarvaiye’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: password_policy-modal_forms_support-2583109-8-d7.patch, failed testing.

pooja.sarvaiye’s picture

pooja.sarvaiye’s picture

Status: Needs work » Needs review
amolnw2778’s picture

@pooja One minor change - First letter of comment needs to be uppercase. // prompted for their current password on password change page unnecessarily.

AohRveTPV’s picture

Is there a way to do this without adding module-specific integration code? Password Policy should not need to know about other modules like "Modal forms (with ctools)". This line is specific to that module:

if (variable_get('modal_forms_login')) {

Such code adds complexity and makes the module difficult to test.

pooja.sarvaiye’s picture

@AohRveTPV, I am also not very happy with the solution. But I could not figure out a better way to solve this. I uploaded patch here so that others can have a look and suggest some better approach. Any suggestions are most welcome.

AohRveTPV’s picture

How do you "Enable modal forms for login form."?

I installed the Modal Forms module on a fresh Drupal site, but I don't see how to do it.

Steps of how to configure Modal Forms to reproduce the problem on a fresh Drupal site would be helpful.

pooja.sarvaiye’s picture

You will have to add a password policy to expire user accounts after some days of inactivity. Then try to login using the expired account. You may alter last login date manually in db, for testing purpose.
The steps are mentioned in the issue description.

AohRveTPV’s picture

"1. Enable modal forms for login form." <-- How do you do this?

pooja.sarvaiye’s picture

You have to turn on Enable for login links option here - admin/config/development/modal_forms

AohRveTPV’s picture

Status: Needs review » Postponed (maintainer needs more info)

Thanks, I am able to reproduce the problem now. I hadn't realized you have to create a link to user/login.

Looks like the problem is Modal Forms relies on a call to modal_forms_login() when the user is returned to user/login after submitting the login form. That function calls Ctools functions that close the modal window and perform the redirection. However, Password Policy calls drupal_goto() before that callback is executed, which attempts the redirection without closing the modal window.

I am thinking it is a problem that should be fixed in Modal Forms. Modal Forms should not assume that another module will not redirect to a different page. That is, Modal Forms should not assume the user will be returned to user/login after submitting the login form.

Again, adding any code like if (<modal_forms enabled>) to Password Policy is very undesirable. Password Policy should not need to know about other contributed modules.

One possible solution is to use hook_drupal_goto_alter() to execute the Ctools calls as does modal_forms_login(). The following seems to work, but I do not know whether it is secure or fully correct. Please consider it a proof of concept.

/**
 * Implements hook_drupal_goto_alter().
 */
function modal_forms_drupal_goto_alter(&$path, $options, &$http_response_code) {
  if (arg(0) == 'modal_forms' && arg(2) == 'login') {
    ctools_include('modal');
    ctools_include('ajax');
    $output = array();
    $output[] = ctools_modal_command_dismiss(t('Login success'));
    $output[] = ctools_ajax_command_redirect($path);
    print ajax_render($output);
    drupal_exit();
  }
}

That could be put in a separate module to avoid hacking changes to Modal Forms or Password Policy.

Would this approach be a solution to the problem?

AohRveTPV’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Please re-open if the solution suggested in #20 is problematic.

pooja.sarvaiye’s picture

@AohRveTPV, modal_forms_drupal_goto_alter solves the problem, thanks.

firewaller’s picture

Just to confirm, the solution in #20 works for me as well.