mirror of
https://github.com/bitwarden/mobile
synced 2025-12-18 01:03:24 +00:00
Split extension up into smaller parts. Process in Loading controller. Response in action controller.
This commit is contained in:
71
src/iOS.Extension/Models/FillScript.cs
Normal file
71
src/iOS.Extension/Models/FillScript.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.iOS.Extension.Models
|
||||
{
|
||||
public class FillScript
|
||||
{
|
||||
public FillScript(PageDetails pageDetails)
|
||||
{
|
||||
if(pageDetails == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DocumentUUID = pageDetails.DocumentUUID;
|
||||
|
||||
var loginForm = pageDetails.Forms.FirstOrDefault(form => pageDetails.Fields.Any(f => f.Form == form.Key && f.Type == "password")).Value;
|
||||
if(loginForm == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Script = new List<List<string>>();
|
||||
|
||||
var password = pageDetails.Fields.FirstOrDefault(f =>
|
||||
f.Form == loginForm.OpId
|
||||
&& f.Type == "password");
|
||||
|
||||
var username = pageDetails.Fields.LastOrDefault(f =>
|
||||
f.Form == loginForm.OpId
|
||||
&& (f.Type == "text" || f.Type == "email")
|
||||
&& f.ElementNumber < password.ElementNumber);
|
||||
|
||||
if(username != null)
|
||||
{
|
||||
Script.Add(new List<string> { "click_on_opid", username.OpId });
|
||||
Script.Add(new List<string> { "fill_by_opid", username.OpId, "me@example.com" });
|
||||
}
|
||||
|
||||
Script.Add(new List<string> { "click_on_opid", password.OpId });
|
||||
Script.Add(new List<string> { "fill_by_opid", password.OpId, "mypassword" });
|
||||
|
||||
if(loginForm.HtmlAction != null)
|
||||
{
|
||||
AutoSubmit = new Submit { FocusOpId = password.OpId };
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "script")]
|
||||
public List<List<string>> Script { get; set; }
|
||||
[JsonProperty(PropertyName = "autosubmit")]
|
||||
public Submit AutoSubmit { get; set; }
|
||||
[JsonProperty(PropertyName = "documentUUID")]
|
||||
public object DocumentUUID { get; set; }
|
||||
[JsonProperty(PropertyName = "properties")]
|
||||
public object Properties { get; set; } = new object();
|
||||
[JsonProperty(PropertyName = "options")]
|
||||
public object Options { get; set; } = new object();
|
||||
[JsonProperty(PropertyName = "metadata")]
|
||||
public object MetaData { get; set; } = new object();
|
||||
|
||||
public class Submit
|
||||
{
|
||||
[JsonProperty(PropertyName = "focusOpid")]
|
||||
public string FocusOpId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user