Hello to Drupal lovers,
I want to show user registration form when the visitors try to get limited/authorization required pages. The Logintoboggan module has this feature but there are two options/tab, login form and registration form. The default view is login form. Can I change to default view as registration form?

I checked below codes but I could not find it..

/**
 * Theme function for unified login page.
 *
 * @ingroup themable
 */
function theme_lt_unified_login_page($variables) {

  $login_form = $variables['login_form'];
  $register_form = $variables['register_form'];
  $active_form = $variables['active_form'];
  $output = '';

  $output .= '<div class="toboggan-unified ' . $active_form . '">';

  // Create the initial message and links that people can click on.
  $output .= '<div id="login-message">' . t('You are not logged in.') . '</div>';
  $output .= '<div id="login-links">';
  $output .= l(t('I have an account'), 'user/login', array('attributes' => array('class' => array('login-link'), 'id' => 'login-link')));
  $output .= ' ';
  $output .= l(t('I want to create an account'), 'user/register', array('attributes' => array('class' => array('login-link'), 'id' => 'register-link')));

  $output .= '</div>';

  // Add the login and registration forms in.
  $output .= '<div id="login-form">' . $login_form . '</div>';
  $output .= '<div id="register-form">' . $register_form . '</div>';

  $output .= '</div>';

  return $output;
}

Comments

yenidem’s picture

up.

scottrouse’s picture

Issue tags: -LoginTobogann

I'm not sure how to accomplish this "the right way" either.

It seems like either line 915 (function logintoboggan_get_authentication_form($active_form = 'login') {) or 746 (function logintoboggan_unified_login_page($active_form = 'login') {) of logintoboggan.module would control the unifiedLoginActiveForm setting called on line 23 of logintoboggan.unifiedlogin.js which would determine which of the two forms is the "active" form.

I've changed both lines 915 and 746 of logintoboggan.module to function logintoboggan_get_authentication_form($active_form = 'register') {) and (function logintoboggan_unified_login_page($active_form = 'register') {, respectively as a temporary hack, but that didn't seem to have an effect.

Any suggestions?

Anonymous’s picture

I have a problem related with this. On a node i' ve put a link to /user/register, so unregistered users can get to register form fast.

Problem is user gets a login form, not a register form (as yenidem mentioned).

Looking the code, i think the "bug" is on line 929 function logintoboggan_denied() { }

It seems by default anonymous users hasn't permission access to /user/register, and also that function calls directly

$output = logintoboggan_get_authentication_form('login');

notice the fixed 'login' parameter.

I hope somebody can work on this?

scottrouse’s picture

@javier.alejandro.castro — Thanks for pointing me in the right direction. Changing line 933 of logintoboggan.module to $output = logintoboggan_get_authentication_form('register'); does, indeed, call up the register form by default. I wish there were a way to change that without hacking the module.

aaronbauman’s picture

The active form is set via a javascript variable:

$login_form['#attached']['js'][] = array(
    'data' => array(
      'LoginToboggan' => array(
        'unifiedLoginActiveForm' => $active_form,
      ),
    ),
    'type' => 'setting',
  );

In your module, you could use hook_js_alter to change this value.

IMO there should be an admin setting to indicate which form should be default.

Shr_Drupal2012’s picture

@aaronbauman,
I am trying to send the user back to the register page if they did not enter certain required fields. But now it takes them back to the login page.
Can you tell me a little more about how can set the active form via java script. You say you "could use hook_js_alter to change this value"
Can you illustrate how I can accomplish that
I am fairly new to the Drupal platform and would appreciate your input

Shr_Drupal2012’s picture

@aaronbauman,
I am trying to send the user back to the register page if they did not enter certain required fields. But now it takes them back to the login page.
Can you tell me a little more about how can set the active form via java script. You say you "could use hook_js_alter to change this value"
Can you illustrate how I can accomplish that
I am fairly new to the Drupal platform and would appreciate your input

yenidem’s picture

Javier,
thank you, I changed line 933 as you explained. the problem solved for me for now. new realases may have this feature in admin panel section.

md2’s picture

Status: Active » Needs review
StatusFileSize
new3.83 KB

The following patch adds options to the 'Present user form on access denied (403)' section. Unfortunately at the moment these options do not effect the unified login form. I will need to do a little further work to get the unified login page to take the setting into account.

I will try and get the unified login default tab stuff done soon.

In the meantime here is the patch that gives default form options for the 403 access denied page when not using the unified login form.

Cheers,
Mark

ACF’s picture

Status: Needs review » Needs work

Hey Mark,

Tested the patch it's looking good. Just a couple of things from the logintoboggan main settings:

@@ -145,11 +146,18 @@ function logintoboggan_main_settings() {
 
   $form['other']['logintoboggan_site_403'] = array(
     '#type' => 'radios',
-    '#title' => t('Present login form on access denied (403)'),
+    '#title' => t('Present user form on access denied (403)'),
     '#options' => $options,
     '#default_value' => $default,
     '#description' => t('Anonymous users will be presented with a login form along with an access denied message.')

I think the title is a bit confusing 'present user form on access denied (403)' sounds like you are presenting the 'user form'. I think it would make more sense to say 'Present the user with a form on access denied (403)'. Also I think that the description needs to change as it doesn't represent accurately the new functionality.

md2’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB

Hi,

Thanks for the review, here is a patch fixing the issues. I've replaced the Title with your suggestion and I'm open to other descriptions if the new one in the following patch doesn't communicate the functionality well enough.

Cheers,
Mark

barraponto’s picture

Here's a sample implementation of hook_js_alter that changes the default form... but it runs on every page for anonymous users :(

/**                                                                                                                                                     
 * Implements hook_js_alter().
 */
function aeconsulta_tweaks_js_alter(&$javascript) {
global $user;
  if (!in_array('authenticated user', $user->roles) && !empty($javascript['settings']['data'])) {
    foreach ($javascript['settings']['data'] as $key => $data) {
      if (array_key_exists('LoginToboggan', $data)) {
        $javascript['settings']['data'][$key]['LoginToboggan']['unifiedLoginActiveForm'] = 'register';
      }
    }
  }
}
barraponto’s picture

Issue summary: View changes

typo.

bdanin’s picture

I've tested the patch in comment #11. This works well. My one recommendation is that instead of nesting this at the end under "other", these options should fall under "Login" underneath "Present a unified login/registration page".

Actually, it might be best if the default state option showed up when you clicked the checkbox to enable "Present a unified login/registration page", and otherwise be hidden.

guypaddock’s picture

This may seem like a silly question, but why would you want to present the password reset form on access denied?

erwangel’s picture

I don't think this is the suitable solution. Why should we have to choose between a login or a register form (or worst, a password form as underlined Guy#14). Admin is not supposed to know user's needs (unless you're called google). the best option should be to have something like
drupal_goto('user', array('query'=>drupal_get_destination()));
inside the logintoboggan_denied() function which should redirect to the standard drupal login/register/password page. Unfortunately this didn't work for me. For an unknown reason it loops on the destination page and never goes to 'http://www.example.com/user'

erwangel’s picture

Without redirecting with drupal_goto as stated at #15, another solution is to call the user_login_block which contains all options giving a logical priority to "login".
$output = drupal_get_form('user_login_block');