mirror of
https://github.com/Stone-Red-Software/StoneRed.NetificationApi.git
synced 2026-09-04 00:36:05 +02:00
Fix inconsistencies and fix Identify method not sending all data to the server
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace StoneRed.NetificationApi.Server.IdentifyUser;
|
||||
|
||||
@@ -8,12 +7,6 @@ namespace StoneRed.NetificationApi.Server.IdentifyUser;
|
||||
/// </summary>
|
||||
public class IdentifyUserData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user ID.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public required string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the email address of the user.
|
||||
/// </summary>
|
||||
@@ -34,21 +27,4 @@ public class IdentifyUserData
|
||||
/// Gets or sets the list of web push tokens for the user.
|
||||
/// </summary>
|
||||
public List<NotificationWebPushToken>? WebPushTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IdentifyUserData"/> class with the specified user ID.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user ID.</param>
|
||||
[SetsRequiredMembers]
|
||||
public IdentifyUserData(string userId)
|
||||
{
|
||||
UserId = userId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IdentifyUserData"/> class.
|
||||
/// </summary>
|
||||
public IdentifyUserData()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -76,31 +76,26 @@ public class NotificationApiServer
|
||||
/// <summary>
|
||||
/// Identifies a user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The ID of the user.</param>
|
||||
/// <param name="identifyUserData">The data for identifying the user.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public async Task<HttpResponseMessage> Identify(IdentifyUserData identifyUserData)
|
||||
public async Task<HttpResponseMessage> Identify(string userId, IdentifyUserData identifyUserData)
|
||||
{
|
||||
string authToken;
|
||||
|
||||
if (secureMode)
|
||||
{
|
||||
string hashedUserId = UserIdHasher.Hash(identifyUserData.UserId, clientSecret);
|
||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{identifyUserData.UserId}:{hashedUserId}"));
|
||||
string hashedUserId = UserIdHasher.Hash(userId, clientSecret);
|
||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{userId}:{hashedUserId}"));
|
||||
}
|
||||
else
|
||||
{
|
||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{identifyUserData.UserId}"));
|
||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{userId}"));
|
||||
}
|
||||
|
||||
var requestData = new
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"users/{userId}")
|
||||
{
|
||||
email = identifyUserData.Email,
|
||||
number = identifyUserData.TelephoneNumber,
|
||||
};
|
||||
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"users/{identifyUserData.UserId}")
|
||||
{
|
||||
Content = JsonContent.Create(requestData, options: Configuration.JsonSerializerOptions),
|
||||
Content = JsonContent.Create(identifyUserData, options: Configuration.JsonSerializerOptions),
|
||||
};
|
||||
|
||||
request.Headers.Add("Authorization", $"Basic {authToken}");
|
||||
@@ -111,10 +106,11 @@ public class NotificationApiServer
|
||||
/// <summary>
|
||||
/// Sets user preferences.
|
||||
/// </summary>
|
||||
/// <param name="userId">The ID of the user.</param>
|
||||
/// <param name="setUserPreferencesData">The data for setting user preferences.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public async Task<HttpResponseMessage> SetUserPreferences(SetUserPreferencesData setUserPreferencesData)
|
||||
public async Task<HttpResponseMessage> SetUserPreferences(string userId, SetUserPreferencesData setUserPreferencesData)
|
||||
{
|
||||
return await httpClient.PostAsJsonAsync($"user_preferences/{setUserPreferencesData.UserId}", setUserPreferencesData, Configuration.JsonSerializerOptions);
|
||||
return await httpClient.PostAsJsonAsync($"user_preferences/{userId}", setUserPreferencesData, Configuration.JsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace StoneRed.NetificationApi.Server.SetUserPreferences;
|
||||
|
||||
@@ -8,12 +7,6 @@ namespace StoneRed.NetificationApi.Server.SetUserPreferences;
|
||||
/// </summary>
|
||||
public class SetUserPreferencesData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user ID.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public required string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of notification preferences.
|
||||
/// </summary>
|
||||
@@ -22,12 +15,10 @@ public class SetUserPreferencesData
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetUserPreferencesData"/> class.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user ID.</param>
|
||||
/// <param name="preferences">The list of notification preferences.</param>
|
||||
[SetsRequiredMembers]
|
||||
public SetUserPreferencesData(string userId, List<NotificationPreference> preferences)
|
||||
public SetUserPreferencesData(List<NotificationPreference> preferences)
|
||||
{
|
||||
UserId = userId;
|
||||
Preferences = preferences;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user