1 user.module | user_login($form, &$form_state) |
Form builder; the main user login form.
Related topics
File
- core/
modules/ user/ user.module, line 1780 - 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) {
backdrop_goto('user/' . $user->uid);
}
backdrop_set_title(t('Log in'));
// Display login form:
$credentials = config_get('system.core', 'user_login_method');
$form['name'] = array('#type' => 'textfield',
'#title' => $credentials === USER_LOGIN_EMAIL_ONLY ? t('Email address') : ($credentials === USER_LOGIN_USERNAME_OR_EMAIL ? t('Username or email address') : t('Username')),
'#maxlength' => $credentials === USER_LOGIN_USERNAME_ONLY ? USERNAME_MAX_LENGTH : EMAIL_MAX_LENGTH,
'#size' => 60,
'#required' => TRUE,
'#attributes' => array(
'autofocus' => 'autofocus',
// Add attributes to field to prevent spell-jacking and unwanted
// automatic changes caused by the browser.
'autocapitalize' => 'none',
'autocorrect' => 'off',
'spellcheck' => 'false',
),
);
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#required' => TRUE,
'#password_toggle' => TRUE,
);
$form['#validate'] = user_login_default_validators();
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
return $form;
}