1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-20 02:03:49 +00:00

view updates

This commit is contained in:
Kyle Spearrin
2019-04-16 07:43:56 -04:00
parent 40598721f1
commit 7d6ec46ebe
5 changed files with 185 additions and 12 deletions

View File

@@ -1,10 +1,28 @@
using Bit.Core.Enums;
using Bit.Core.Models.Domain;
using Bit.Core.Utilities;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Bit.Core.Models.View
{
public class LoginUriView : View
{
private HashSet<string> _canLaunchWhitelist = new HashSet<string>
{
"https://",
"http://",
"ssh://",
"ftp://",
"sftp://",
"irc://",
"vnc://",
"chrome://",
"iosapp://",
"androidapp://",
};
private string _uri;
private string _domain;
private string _hostname;
@@ -29,6 +47,63 @@ namespace Bit.Core.Models.View
}
}
// TODO
public string Domain
{
get
{
if(_domain == null && Uri != null)
{
_domain = CoreHelpers.GetDomain(Uri);
if(_domain == string.Empty)
{
_domain = null;
}
}
return _domain;
}
}
public string Hostname
{
get
{
if(_hostname == null && Uri != null)
{
_hostname = CoreHelpers.GetHostname(Uri);
if(_hostname == string.Empty)
{
_hostname = null;
}
}
return _hostname;
}
}
public string HostnameOrUri => Hostname ?? Uri;
public bool IsWebsite => Uri != null && (Uri.StartsWith("http://") || Uri.StartsWith("https://") ||
(Uri.Contains("://") && Regex.IsMatch(Uri, CoreHelpers.TldEndingRegex)));
public bool CanLaunch
{
get
{
if(_canLaunch != null)
{
return _canLaunch.Value;
}
if(Uri != null && Match != UriMatchType.RegularExpression)
{
var uri = LaunchUri;
_canLaunch = _canLaunchWhitelist.Any(prefix => uri.StartsWith(prefix));
return _canLaunch.Value;
}
_canLaunch = false;
return _canLaunch.Value;
}
}
public string LaunchUri => !Uri.Contains("://") && Regex.IsMatch(Uri, CoreHelpers.TldEndingRegex) ?
string.Concat("http://", Uri) : Uri;
}
}