From c88c06de72e50c94e74830900b29be2954c5b151 Mon Sep 17 00:00:00 2001 From: Trudy Date: Mon, 9 Dec 2024 01:05:56 -0800 Subject: [PATCH] Add AccessCode properties and related functionality --- Tests/VpnHood.Test/Tests/ClientProfileTest.cs | 5 ++++- VpnHood.Client.App/ClientProfiles/ClientProfile.cs | 2 ++ .../ClientProfiles/ClientProfileAccess.cs | 7 +++++++ .../ClientProfiles/ClientProfileBaseInfo.cs | 2 ++ .../ClientProfiles/ClientProfileExtensions.cs | 3 ++- .../ClientProfiles/ClientProfileInfo.cs | 13 +++++++++++++ .../ClientProfiles/ClientProfileService.cs | 2 +- VpnHood.Common/Tokens/ConnectPlanIds.cs | 7 ++++--- 8 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 VpnHood.Client.App/ClientProfiles/ClientProfileAccess.cs diff --git a/Tests/VpnHood.Test/Tests/ClientProfileTest.cs b/Tests/VpnHood.Test/Tests/ClientProfileTest.cs index 41f2a5e7d..e8863e5eb 100644 --- a/Tests/VpnHood.Test/Tests/ClientProfileTest.cs +++ b/Tests/VpnHood.Test/Tests/ClientProfileTest.cs @@ -214,7 +214,8 @@ public async Task Crud() IsFavorite = true, CustomData = Guid.NewGuid().ToString(), IsPremiumLocationSelected = true, - SelectedLocation = "us/california" + SelectedLocation = "us/california", + AccessCode = "12345678" }; app.ClientProfileService.Update(clientProfile.ClientProfileId, updateParams); clientProfile = app.ClientProfileService.Get(clientProfile.ClientProfileId); @@ -223,6 +224,8 @@ public async Task Crud() Assert.AreEqual(updateParams.CustomData.Value, clientProfile.CustomData); Assert.AreEqual(updateParams.IsPremiumLocationSelected.Value, clientProfile.IsPremiumLocationSelected); Assert.AreEqual(updateParams.SelectedLocation.Value, clientProfile.SelectedLocation); + Assert.AreEqual(updateParams.AccessCode.Value, clientProfile.AccessCode); + Assert.AreEqual("****5678", clientProfile.ToInfo().AccessCode); // ************ // *** TEST ***: RemoveClientProfile diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfile.cs b/VpnHood.Client.App/ClientProfiles/ClientProfile.cs index 5303a0641..7a9ddb000 100644 --- a/VpnHood.Client.App/ClientProfiles/ClientProfile.cs +++ b/VpnHood.Client.App/ClientProfiles/ClientProfile.cs @@ -13,4 +13,6 @@ public class ClientProfile public string? SelectedLocation{ get; set; } public bool IsForAccount { get; set; } public bool IsBuiltIn { get; set; } + public string? AccessCode { get; set; } + public ClientProfileAccess? Access { get; set; } } \ No newline at end of file diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfileAccess.cs b/VpnHood.Client.App/ClientProfiles/ClientProfileAccess.cs new file mode 100644 index 000000000..038533782 --- /dev/null +++ b/VpnHood.Client.App/ClientProfiles/ClientProfileAccess.cs @@ -0,0 +1,7 @@ +namespace VpnHood.Client.App.ClientProfiles; + +public class ClientProfileAccess +{ + public DateTime? Expiration { get; set; } + public int? MaxClient { get; set; } +} \ No newline at end of file diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfileBaseInfo.cs b/VpnHood.Client.App/ClientProfiles/ClientProfileBaseInfo.cs index 85ba85a57..4d0444a04 100644 --- a/VpnHood.Client.App/ClientProfiles/ClientProfileBaseInfo.cs +++ b/VpnHood.Client.App/ClientProfiles/ClientProfileBaseInfo.cs @@ -9,4 +9,6 @@ public class ClientProfileBaseInfo public required bool IsPremiumLocationSelected { get; init; } public required bool IsPremiumAccount { get; init; } public required ClientServerLocationInfo? SelectedLocationInfo { get; init; } + public required bool HasAccessCode { get; set; } + } \ No newline at end of file diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfileExtensions.cs b/VpnHood.Client.App/ClientProfiles/ClientProfileExtensions.cs index 33fc60898..6d8adbb86 100644 --- a/VpnHood.Client.App/ClientProfiles/ClientProfileExtensions.cs +++ b/VpnHood.Client.App/ClientProfiles/ClientProfileExtensions.cs @@ -16,7 +16,8 @@ public static ClientProfileBaseInfo ToBaseInfo(this ClientProfileInfo clientProf CustomData = clientProfileInfo.CustomData, IsPremiumLocationSelected = clientProfileInfo.IsPremiumLocationSelected, IsPremiumAccount = clientProfileInfo.IsPremiumAccount, - SelectedLocationInfo = clientProfileInfo.SelectedLocationInfo + SelectedLocationInfo = clientProfileInfo.SelectedLocationInfo, + HasAccessCode = !string.IsNullOrEmpty(clientProfileInfo.AccessCode) }; } } \ No newline at end of file diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfileInfo.cs b/VpnHood.Client.App/ClientProfiles/ClientProfileInfo.cs index 1afc69e88..20ec8bf1a 100644 --- a/VpnHood.Client.App/ClientProfiles/ClientProfileInfo.cs +++ b/VpnHood.Client.App/ClientProfiles/ClientProfileInfo.cs @@ -16,6 +16,7 @@ public class ClientProfileInfo(ClientProfile clientProfile) public bool IsValidHostName => clientProfile.Token.ServerToken.IsValidHostName; public bool IsBuiltIn => clientProfile.IsBuiltIn; public bool IsForAccount => clientProfile.IsForAccount; + public string? AccessCode => FormantAccessCode(clientProfile.AccessCode); public ClientServerLocationInfo[] LocationInfos => ClientServerLocationInfo.CreateFromToken(clientProfile.Token); public ClientServerLocationInfo? SelectedLocationInfo { @@ -29,6 +30,18 @@ public ClientServerLocationInfo? SelectedLocationInfo { } } + private static string? FormantAccessCode(string? accessCode) + { + if (string.IsNullOrWhiteSpace(accessCode)) + return null; + + if (accessCode.Length <= 4) + return "***"; + + // replace all but last 4 characters with '*' + return new string('*', accessCode.Length - 4) + accessCode[^4..]; + } + private string GetTitle() { var token = clientProfile.Token; diff --git a/VpnHood.Client.App/ClientProfiles/ClientProfileService.cs b/VpnHood.Client.App/ClientProfiles/ClientProfileService.cs index 8b09c364b..3010b5852 100644 --- a/VpnHood.Client.App/ClientProfiles/ClientProfileService.cs +++ b/VpnHood.Client.App/ClientProfiles/ClientProfileService.cs @@ -118,7 +118,7 @@ public ClientProfile Update(Guid clientProfileId, ClientProfileUpdateParams upda item.SelectedLocation = updateParams.SelectedLocation; if (updateParams.AccessCode != null) - item.SelectedLocation = updateParams.AccessCode; + item.AccessCode = updateParams.AccessCode; diff --git a/VpnHood.Common/Tokens/ConnectPlanIds.cs b/VpnHood.Common/Tokens/ConnectPlanIds.cs index 6b95c4937..b5abf73df 100644 --- a/VpnHood.Common/Tokens/ConnectPlanIds.cs +++ b/VpnHood.Common/Tokens/ConnectPlanIds.cs @@ -5,7 +5,8 @@ namespace VpnHood.Common.Tokens; [JsonConverter(typeof(JsonStringEnumConverter))] public enum ConnectPlanId { - Normal = 0, - PremiumByTrial = 1, - PremiumByRewardedAd = 2, + Normal, + PremiumByTrial, + PremiumByRewardedAd, + Status } \ No newline at end of file