aboutsummaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-12-13 16:52:06 +0100
committerivarlovlie <git@ivarlovlie.no>2022-12-13 16:52:06 +0100
commit0557de9f069dc620539409aced67e2ad61d25395 (patch)
treefa87f771a33dfadefa257d12ad8bbd8b1cc72a1b /code
parent4657b9af95277c4a2d33a67415658819701ab694 (diff)
downloadgreatoffice-0557de9f069dc620539409aced67e2ad61d25395.tar.xz
greatoffice-0557de9f069dc620539409aced67e2ad61d25395.zip
feat: Misc localising
Diffstat (limited to 'code')
-rw-r--r--code/api/src/Models/Database/Internal/User.cs6
-rw-r--r--code/api/src/Resources/SharedResources.nb.Designer.cs6
-rw-r--r--code/api/src/Resources/SharedResources.nb.resx23
-rw-r--r--code/api/src/Services/PasswordResetService.cs19
-rw-r--r--code/api/src/Services/UserService.cs2
5 files changed, 44 insertions, 12 deletions
diff --git a/code/api/src/Models/Database/Internal/User.cs b/code/api/src/Models/Database/Internal/User.cs
index b046974..09e0202 100644
--- a/code/api/src/Models/Database/Internal/User.cs
+++ b/code/api/src/Models/Database/Internal/User.cs
@@ -16,9 +16,9 @@ public class User : Base
public DateTime EmailLastValidated { get; set; }
public ICollection<Tenant> Tenants { get; set; }
- public string DisplayName() {
- if (FirstName.HasValue() && LastName.HasValue()) return FirstName + " " + LastName;
- return FirstName.HasValue() ? FirstName : Email;
+ public string DisplayName(bool isForGreeting = false) {
+ if (!isForGreeting && FirstName.HasValue() && LastName.HasValue()) return FirstName + " " + LastName;
+ return FirstName.HasValue() ? FirstName : Username ?? Email;
}
public void HashAndSetPassword(string password) {
diff --git a/code/api/src/Resources/SharedResources.nb.Designer.cs b/code/api/src/Resources/SharedResources.nb.Designer.cs
index 2613026..7190c56 100644
--- a/code/api/src/Resources/SharedResources.nb.Designer.cs
+++ b/code/api/src/Resources/SharedResources.nb.Designer.cs
@@ -86,5 +86,11 @@ namespace IOL.GreatOffice.Api.Resources {
return ResourceManager.GetString("Greatoffice Email Validation", resourceCulture);
}
}
+
+ internal static string Reset_password___Greatoffice {
+ get {
+ return ResourceManager.GetString("Reset password - Greatoffice", resourceCulture);
+ }
+ }
}
}
diff --git a/code/api/src/Resources/SharedResources.nb.resx b/code/api/src/Resources/SharedResources.nb.resx
index ac31409..902e47d 100644
--- a/code/api/src/Resources/SharedResources.nb.resx
+++ b/code/api/src/Resources/SharedResources.nb.resx
@@ -59,4 +59,27 @@ Bekreft din e-postadresse ved å åpne denne lenken i en nettleser {1}</value>
<value>Greatoffice e-postaddresse bekreftelse</value>
<comment>Greatoffice Email Validation</comment>
</data>
+ <data name="Hi {0},&#xA;&#xA;Go to the following link to set a new password.&#xA;&#xA;{1}/reset-password/{2}&#xA;&#xA;The link expires at {3}.&#xA;If you did not request a password reset, no action is required."
+ xml:space="preserve">
+ <value>Hei {0},
+
+Åpne denne lenken i en nettleser for å sette nytt passord.
+
+{1}/reset-password/{2}
+
+Lenken utgår {3}.
+Hvis du ikke vet hva dette gjelder, kan du se bort i fra mailen.</value>
+ <comment>Hi {0},
+
+ Go to the following link to set a new password.
+
+ {1}/reset-password/{2}
+
+ The link expires at {3}.
+ If you did not request a password reset, no action is required.</comment>
+ </data>
+ <data name="Reset password - Greatoffice" xml:space="preserve">
+ <value>Sett nytt passord - Greatoffice</value>
+ <comment>Reset password - Greatoffice</comment>
+ </data>
</root> \ No newline at end of file
diff --git a/code/api/src/Services/PasswordResetService.cs b/code/api/src/Services/PasswordResetService.cs
index 8c8e32b..1897d44 100644
--- a/code/api/src/Services/PasswordResetService.cs
+++ b/code/api/src/Services/PasswordResetService.cs
@@ -1,3 +1,5 @@
+using Microsoft.Extensions.Localization;
+
namespace IOL.GreatOffice.Api.Services;
public class PasswordResetService
@@ -6,17 +8,18 @@ public class PasswordResetService
private readonly MailService _mailService;
private readonly AppConfiguration _configuration;
private readonly ILogger<PasswordResetService> _logger;
+ private readonly IStringLocalizer<SharedResources> _localizer;
public PasswordResetService(
MainAppDatabase database,
VaultService vaultService,
ILogger<PasswordResetService> logger,
- MailService mailService
- ) {
+ MailService mailService, IStringLocalizer<SharedResources> localizer) {
_database = database;
_configuration = vaultService.GetCurrentAppConfiguration();
_logger = logger;
_mailService = mailService;
+ _localizer = localizer;
}
public async Task<PasswordResetRequest> GetRequestAsync(Guid id, CancellationToken cancellationToken = default) {
@@ -52,17 +55,17 @@ public class PasswordResetService
var zonedExpirationDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(request.ExpirationDate, requestTz.Id);
var message = new MailService.PostmarkEmail() {
To = request.User.Username,
- Subject = "Reset password - Greatoffice",
- TextBody = @$"
-Hi {user.Username}
+ Subject = _localizer["Reset password - Greatoffice"],
+ TextBody = _localizer["""
+Hi {0},
Go to the following link to set a new password.
-{_configuration.CANONICAL_FRONTEND_URL}/reset-password/{request.Id}
+{1}/reset-password/{2}
-The link expires at {zonedExpirationDate:yyyy-MM-dd hh:mm}.
+The link expires at {3}.
If you did not request a password reset, no action is required.
-"
+""", user.DisplayName(true), _configuration.CANONICAL_FRONTEND_URL, request.Id, zonedExpirationDate.ToString("yyyy-MM-dd hh:mm")]
};
#pragma warning disable 4014
diff --git a/code/api/src/Services/UserService.cs b/code/api/src/Services/UserService.cs
index 4c632be..4fd2aa4 100644
--- a/code/api/src/Services/UserService.cs
+++ b/code/api/src/Services/UserService.cs
@@ -90,7 +90,7 @@ public class UserService
Hello, {0}.
Validate your email address by opening this link in a browser {1}
-""", user.DisplayName(), EmailValidationUrl + "?id=" + queueItem.Id]
+""", user.DisplayName(true), EmailValidationUrl + "?id=" + queueItem.Id]
};
await _mailService.SendMail(email);
queueItem.EmailSentAt = DateTime.UtcNow;