Add Application configuration #11
45
ApiDto/Requests/Configuration/EmailRequest.cs
Normal file
45
ApiDto/Requests/Configuration/EmailRequest.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Mirea.Api.Dto.Requests.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to configure email settings.
|
||||
/// </summary>
|
||||
public class EmailRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the server address.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the email address from which emails will be sent.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string From { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password for the email account.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the port number.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether SSL is enabled.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public bool Ssl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string User { get; set; }
|
||||
}
|
@ -214,6 +214,32 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HttpPost("SetEmail")]
|
||||
[TokenAuthentication]
|
||||
[BadRequestResponse]
|
||||
public ActionResult<bool> SetEmail([FromBody] EmailRequest? request)
|
||||
{
|
||||
var settings = (request == null) switch
|
||||
{
|
||||
true => new EmailSettings(),
|
||||
false => new EmailSettings
|
||||
{
|
||||
Server = request.Server,
|
||||
From = request.From,
|
||||
Password = request.Password,
|
||||
Port = request.Port,
|
||||
Ssl = request.Ssl,
|
||||
User = request.User
|
||||
}
|
||||
};
|
||||
|
||||
var general = GeneralConfig;
|
||||
general.EmailSettings = settings;
|
||||
GeneralConfig = general;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user