Merge pull request #132 from keepassxreboot/username_fields

Improve detection of username fields
This commit is contained in:
Janek Bevendorff 2018-05-08 21:13:49 +02:00 committed by GitHub
commit a3f08293d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -496,7 +496,7 @@ cipForm.init = function(form, credentialFields) {
// TODO: could be called multiple times --> update credentialFields
// not already initialized && password-field is not null
if (!form.data('cipForm-initialized') && credentialFields.password) {
if (!form.data('cipForm-initialized') && (credentialFields.password || credentialFields.username)) {
form.data('cipForm-initialized', true);
cipForm.setInputFields(form, credentialFields);
form.submit(cipForm.onSubmit);
@ -896,6 +896,15 @@ cipFields.getAllCombinations = function(inputs) {
}
}
// If only username field found, add it to the array
if (fields.length === 0 && uField) {
const combination = {
username: uField[0].getAttribute('data-cip-id'),
password: null
};
fields.push(combination);
}
return fields;
};
@ -1040,7 +1049,7 @@ cipFields.getPasswordField = function(usernameId, checkDisabled) {
// search all inputs on this one form
if (form) {
passwordField = jQuery('input[type=\'password\']:first', form);
if (passwordField.length < 1) {
if (passwordField && passwordField.length < 1) {
passwordField = null;
}
@ -1243,6 +1252,11 @@ cip.initCredentialFields = function(forceCall) {
cip.url = document.location.origin;
cip.submitUrl = cip.getFormActionUrl(cipFields.combinations[0]);
// Get submitUrl for a single input
if (!cip.submitUrl && cipFields.combinations.length === 1 && inputs.length === 1) {
cip.submitUrl = cip.getFormActionUrlFromSingleInput(inputs[0]);
}
if (cip.settings.autoRetrieveCredentials && _called.retrieveCredentials === false && (cip.url && cip.submitUrl)) {
browser.runtime.sendMessage({
action: 'retrieve_credentials',
@ -1365,7 +1379,9 @@ cip.preparePageForMultipleCredentials = function(credentials) {
cipAutocomplete.init(_f(i.username));
}
} else if (_detectedFields == 1) {
// If only password field is the visible one
if (_f(i.username)) {
cipAutocomplete.init(_f(i.username));
}
if (_f(i.password)) {
cipAutocomplete.init(_f(i.password));
}
@ -1399,6 +1415,20 @@ cip.getFormActionUrl = function(combination) {
return action;
};
cip.getFormActionUrlFromSingleInput = function(field) {
if (!field) {
return null;
}
let action = field.formAction;
if (typeof(action) !== 'string' || action === '') {
action = document.location.origin + document.location.pathname;
}
return action;
};
cip.fillInCredentials = function(combination, onlyPassword, suppressWarnings) {
const action = cip.getFormActionUrl(combination);