Skip to content

Commit

Permalink
Add AccessCode properties and related functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Dec 9, 2024
1 parent 8acf0de commit c88c06d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Tests/VpnHood.Test/Tests/ClientProfileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions VpnHood.Client.App/ClientProfiles/ClientProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
7 changes: 7 additions & 0 deletions VpnHood.Client.App/ClientProfiles/ClientProfileAccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VpnHood.Client.App.ClientProfiles;

public class ClientProfileAccess
{
public DateTime? Expiration { get; set; }
public int? MaxClient { get; set; }
}
2 changes: 2 additions & 0 deletions VpnHood.Client.App/ClientProfiles/ClientProfileBaseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
3 changes: 2 additions & 1 deletion VpnHood.Client.App/ClientProfiles/ClientProfileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}
}
13 changes: 13 additions & 0 deletions VpnHood.Client.App/ClientProfiles/ClientProfileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client.App/ClientProfiles/ClientProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand Down
7 changes: 4 additions & 3 deletions VpnHood.Common/Tokens/ConnectPlanIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace VpnHood.Common.Tokens;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum ConnectPlanId
{
Normal = 0,
PremiumByTrial = 1,
PremiumByRewardedAd = 2,
Normal,
PremiumByTrial,
PremiumByRewardedAd,
Status
}

0 comments on commit c88c06d

Please sign in to comment.