mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-25 12:05:59 +01:00
handle autofill for pages with no forms, but still has fields
This commit is contained in:
parent
5daeb0ee95
commit
4751cc04fc
@ -16,14 +16,14 @@ namespace Bit.iOS.Extension.Models
|
|||||||
|
|
||||||
DocumentUUID = pageDetails.DocumentUUID;
|
DocumentUUID = pageDetails.DocumentUUID;
|
||||||
|
|
||||||
var passwordFields = pageDetails.Fields.Where(f => f.Type == "password");
|
var passwordFields = pageDetails.Fields.Where(f => f.Type == "password").ToArray();
|
||||||
var passwordForms = pageDetails.Forms.Where(form => passwordFields.Any(f => f.Form == form.Key));
|
var passwordForms = pageDetails.Forms.Where(form => passwordFields.Any(f => f.Form == form.Key)).ToArray();
|
||||||
if(!passwordForms.Any())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PageDetails.Form loginForm = null;
|
PageDetails.Form loginForm = null;
|
||||||
|
PageDetails.Field username = null, password = null;
|
||||||
|
|
||||||
|
if(passwordForms.Any())
|
||||||
|
{
|
||||||
if(passwordForms.Count() > 1)
|
if(passwordForms.Count() > 1)
|
||||||
{
|
{
|
||||||
// More than one form with a password field is on the page.
|
// More than one form with a password field is on the page.
|
||||||
@ -69,29 +69,41 @@ namespace Bit.iOS.Extension.Models
|
|||||||
loginForm = passwordForms.FirstOrDefault().Value;
|
loginForm = passwordForms.FirstOrDefault().Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Script = new List<List<string>>();
|
password = pageDetails.Fields.FirstOrDefault(f =>
|
||||||
|
|
||||||
var password = pageDetails.Fields.FirstOrDefault(f =>
|
|
||||||
f.Form == loginForm.OpId
|
f.Form == loginForm.OpId
|
||||||
&& f.Type == "password");
|
&& f.Type == "password");
|
||||||
|
|
||||||
var username = pageDetails.Fields.LastOrDefault(f =>
|
username = pageDetails.Fields.LastOrDefault(f =>
|
||||||
f.Form == loginForm.OpId
|
f.Form == loginForm.OpId
|
||||||
&& (f.Type == "text" || f.Type == "email")
|
&& (f.Type == "text" || f.Type == "email")
|
||||||
&& f.ElementNumber < password.ElementNumber);
|
&& f.ElementNumber < password.ElementNumber);
|
||||||
|
|
||||||
|
if(loginForm.HtmlAction != null)
|
||||||
|
{
|
||||||
|
AutoSubmit = new Submit { FocusOpId = password.OpId };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(passwordFields.Count() == 1)
|
||||||
|
{
|
||||||
|
password = passwordFields.First();
|
||||||
|
if(password.ElementNumber > 0)
|
||||||
|
{
|
||||||
|
username = pageDetails.Fields[password.ElementNumber - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Script = new List<List<string>>();
|
||||||
|
|
||||||
if(username != null)
|
if(username != null)
|
||||||
{
|
{
|
||||||
Script.Add(new List<string> { "click_on_opid", username.OpId });
|
Script.Add(new List<string> { "click_on_opid", username.OpId });
|
||||||
Script.Add(new List<string> { "fill_by_opid", username.OpId, fillUsername });
|
Script.Add(new List<string> { "fill_by_opid", username.OpId, fillUsername });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(password != null)
|
||||||
|
{
|
||||||
Script.Add(new List<string> { "click_on_opid", password.OpId });
|
Script.Add(new List<string> { "click_on_opid", password.OpId });
|
||||||
Script.Add(new List<string> { "fill_by_opid", password.OpId, fillPassword });
|
Script.Add(new List<string> { "fill_by_opid", password.OpId, fillPassword });
|
||||||
|
|
||||||
if(loginForm.HtmlAction != null)
|
|
||||||
{
|
|
||||||
AutoSubmit = new Submit { FocusOpId = password.OpId };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user