Enhance AuthService: add application settings dependency and improve password reset email content

This commit is contained in:
a.beging@eas-solutions.de
2026-04-23 09:49:41 +02:00
parent 46d5bcd00d
commit 8ad6a143de

View File

@@ -2,11 +2,13 @@ using FoodsharingSiegen.Contracts;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Contracts.Helper;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Data;
using FoodsharingSiegen.Server.Service;
using FoodsharingSiegen.Shared.Helper;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace FoodsharingSiegen.Server.Auth
{
@@ -55,6 +57,11 @@ namespace FoodsharingSiegen.Server.Auth
/// </summary>
private readonly IMailService _mailService;
/// <summary>
/// The application settings
/// </summary>
private readonly AppSettings _appSettings;
#endregion
#region Setup/Teardown
@@ -70,12 +77,14 @@ namespace FoodsharingSiegen.Server.Auth
FsContext context,
LocalStorageService localStorageService,
AuthenticationStateProvider authenticationStateProvider,
IMailService mailService)
IMailService mailService,
IOptions<AppSettings> appSettings)
{
Context = context;
_localStorageService = localStorageService;
_authenticationStateProvider = authenticationStateProvider;
_mailService = mailService;
_appSettings = appSettings.Value;
}
#endregion
@@ -211,7 +220,17 @@ namespace FoodsharingSiegen.Server.Auth
await Context.SaveChangesAsync();
var resetLink = $"{baseUri.TrimEnd('/')}/reset-password/{resetToken}";
var mailBody = $"Hallo {user.Name},<br><br>Um dein Passwort zurückzusetzen, klicke bitte auf den folgenden Link (dieser ist 30 Minuten gültig):<br><a href='{resetLink}'>{resetLink}</a><br><br>Viele Grüße<br>Dein Foodsharing Team";
var mailBody = $"""
Hallo {user.Name},<br>
<br>
für dein Konto wurde eine Anfrage zum Zurücksetzen des Passworts gestellt. <br>
Wenn du diese Anfrage nicht gestellt hast, kannst du diese E-Mail ignorieren und dein Passwort bleibt unverändert.<br>
<br>
Um dein Passwort zurückzusetzen, klicke bitte auf den folgenden Link (dieser ist 30 Minuten gültig):<br>
<a href='{resetLink}'>{resetLink}</a><br>
<br>
Viele Grüße<br>Dein Team {_appSettings.Terms.Title}
""";
await _mailService.SendEmailAsync(user.Mail, "Passwort zurücksetzen", mailBody);
}