95 lines
3.4 KiB
C#
95 lines
3.4 KiB
C#
using System.Linq;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xIdentityModels.Configurations;
|
|
using xIds.Constants;
|
|
using xIds.Interfaces;
|
|
|
|
namespace xIds.Providers
|
|
{
|
|
public class XIdentityMessageProvider : IXIdentityMessageProvider
|
|
{
|
|
//
|
|
public string InviteMsg { get; set; }
|
|
public string RegistrationApproveMsg { get; set; }
|
|
public string RegisteredMsg { get; set; }
|
|
public string VerificationCodeMsg { get; set; }
|
|
public string ChangePasswordMsg { get; set; }
|
|
public string PasswordChangedMsg { get; set; }
|
|
public string NewDeviceLoggedInMsg { get; set; }
|
|
|
|
private readonly ILogger<IXIdentityMessageProvider> logger;
|
|
private readonly XIdentityConfiguration identityConfiguration;
|
|
|
|
public XIdentityMessageProvider(
|
|
ILogger<IXIdentityMessageProvider> logger,
|
|
XIdentityConfiguration identityConfiguration
|
|
)
|
|
{
|
|
this.logger = logger;
|
|
this.identityConfiguration = identityConfiguration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determine All things is Ready or Not
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsReady()
|
|
{
|
|
return !InviteMsg.IsNullOrEmpty() &&
|
|
!RegistrationApproveMsg.IsNullOrEmpty() &&
|
|
!RegisteredMsg.IsNullOrEmpty() &&
|
|
!VerificationCodeMsg.IsNullOrEmpty() &&
|
|
!ChangePasswordMsg.IsNullOrEmpty() &&
|
|
!PasswordChangedMsg.IsNullOrEmpty() &&
|
|
!NewDeviceLoggedInMsg.IsNullOrEmpty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve a Translated Value Based on Given Lang
|
|
/// </summary>
|
|
/// <param name="resourceTitle"></param>
|
|
/// <param name="lang"></param>
|
|
/// <returns></returns>
|
|
private string GetStringResource(string resourceTitle, string lang)
|
|
{
|
|
//
|
|
var item = identityConfiguration.IdentityMessages
|
|
.FirstOrDefault(sr =>
|
|
sr.Language.ToNormalString() == lang.ToNormalString() &&
|
|
sr.ResourceTitle.ToNormalString() == resourceTitle.ToNormalString());
|
|
//
|
|
if (item == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
//
|
|
return item.TranslatedValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prepare Helper Class and Fill Messages
|
|
/// with Specific Language
|
|
/// </summary>
|
|
/// <param name="lang"></param>
|
|
public void PrepareMessages(string lang)
|
|
{
|
|
//
|
|
InviteMsg = GetStringResource(IdentityMessagesKeys.InviteMsg, lang);
|
|
RegisteredMsg = GetStringResource(IdentityMessagesKeys.RegisteredMsg, lang);
|
|
ChangePasswordMsg = GetStringResource(IdentityMessagesKeys.ChangePasswordMsg, lang);
|
|
PasswordChangedMsg = GetStringResource(IdentityMessagesKeys.PasswordChangedMsg, lang);
|
|
VerificationCodeMsg = GetStringResource(IdentityMessagesKeys.VerificationCodeMsg, lang);
|
|
NewDeviceLoggedInMsg = GetStringResource(IdentityMessagesKeys.NewDeviceLoggedInMsg, lang);
|
|
RegistrationApproveMsg = GetStringResource(IdentityMessagesKeys.RegistrationApproveMsg, lang);
|
|
|
|
//
|
|
if (!IsReady())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
}
|
|
}
|
|
} |