| 5 user.module | user_login() |
| 6 user.module | user_login(&$form_state) |
| 7 user.module | user_login($form, &$form_state) |
| 8 user.module | user_login($form, &$form_state) |
Form builder; the main user login form.
Related topics
7 string references to 'user_login'
File
- modules/
user/ user.module, line 2033 - Enables the user registration and login system.
Code
function user_login($form, &$form_state) {
global $user;
// If we are already logged on, go to the user page instead.
if ($user->uid) {
drupal_goto('user/' . $user->uid);
}
// Display login form:
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#size' => 60,
'#maxlength' => USERNAME_MAX_LENGTH,
'#required' => TRUE,
);
$form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#description' => t('Enter the password that accompanies your username.'),
'#required' => TRUE,
);
$form['#validate'] = user_login_default_validators();
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Log in'),
);
return $form;
}
Login or register to post comments
Comments
Adding a back-door drupal login, when overriding login page
While creating an external login module, I wanted to modify the login block and page to provide the external login link and disable the Drupal username and password fields. However, I needed to create a different path that will still allow the superadmin user to login with his/her Drupal account.
I added this menu callback:
$items['backdoor'] = array('title' => 'Admin Login',
'description' => 'Use when can\'t login externally',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_login'),
'access arguments' => array('access content'),
);
Then in the form_alter, I've disabled the username and password, except for the backdoor page:
function yourmodule_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_login':
case 'user_login_block':
// only allow for Drupal login fields if this is the /backdoor page
if (strcmp(current_path(),"backdoor")!=0) {
$form['name']['#access'] = FALSE;
$form['pass']['#access'] = FALSE;
$form['#submit'][] = 'yourmodule_external_submit';
unset($form['#validate']);
$form['#validate'][] = 'yourmodule_external_validate';
}
break;
...