mirror of
https://github.com/bitwarden/mobile
synced 2025-12-21 10:43:22 +00:00
Split extension up into smaller parts. Process in Loading controller. Response in action controller.
This commit is contained in:
19
src/iOS.Extension/Models/Context.cs
Normal file
19
src/iOS.Extension/Models/Context.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Foundation;
|
||||
|
||||
namespace Bit.iOS.Extension.Models
|
||||
{
|
||||
public class Context
|
||||
{
|
||||
public NSExtensionContext ExtContext { get; set; }
|
||||
public string ProviderType { get; set; }
|
||||
public Uri Url { get; set; }
|
||||
public string SiteTitle { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string OldPassword { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public PasswordGenerationOptions PasswordOptions { get; set; }
|
||||
public PageDetails Details { get; set; }
|
||||
}
|
||||
}
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
46
src/iOS.Extension/Models/PageDetails.cs
Normal file
46
src/iOS.Extension/Models/PageDetails.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.iOS.Extension.Models
|
||||
{
|
||||
public class PageDetails
|
||||
{
|
||||
public string DocumentUUID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string DocumentUrl { get; set; }
|
||||
public string TabUrl { get; set; }
|
||||
public Dictionary<string, Form> Forms { get; set; }
|
||||
public List<Field> Fields { get; set; }
|
||||
public long CollectedTimestamp { get; set; }
|
||||
|
||||
public class Form
|
||||
{
|
||||
public string OpId { get; set; }
|
||||
public string HtmlName { get; set; }
|
||||
public string HtmlId { get; set; }
|
||||
public string HtmlAction { get; set; }
|
||||
public string HtmlMethod { get; set; }
|
||||
}
|
||||
|
||||
public class Field
|
||||
{
|
||||
public string OpId { get; set; }
|
||||
public int ElementNumber { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public bool Viewable { get; set; }
|
||||
public string HtmlId { get; set; }
|
||||
public string HtmlName { get; set; }
|
||||
public string HtmlClass { get; set; }
|
||||
public string LabelRight { get; set; }
|
||||
public string LabelLeft { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Value { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
public bool Readonly { get; set; }
|
||||
public string OnePasswordFieldType { get; set; }
|
||||
public string Form { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
13
src/iOS.Extension/Models/PasswordGenerationOptions.cs
Normal file
13
src/iOS.Extension/Models/PasswordGenerationOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.iOS.Extension.Models
|
||||
{
|
||||
public class PasswordGenerationOptions
|
||||
{
|
||||
public int MinLength { get; set; }
|
||||
public int MaxLength { get; set; }
|
||||
public bool RequireDigits { get; set; }
|
||||
public bool RequireSymbols { get; set; }
|
||||
public string ForbiddenCharacters { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user