This repository has been archived on 2023-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
gswi-server/gswi/Controllers/GUIController.cs
2022-02-20 19:04:11 +01:00

93 lines
3.0 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using gswi.Configuration;
using gswi.Model.DTOs;
using gswi.SMTP.Interface;
using gswi.SMTP.Model;
namespace gswi.Controllers
{
[Route("api/gui")]
[ApiController]
public class GUIController : ControllerBase
{
private APISettings _apiSettings;
private DatabaseSettings _databaseSettings;
private AuthentificationSettings _authSettings;
private EMailSettings _mailSettings;
private FrontendSettings _frontendSettings;
private IHostEnvironment _env;
private readonly ISMTPClient _smtpClient;
public GUIController(
APISettings apiSettings,
DatabaseSettings databaseSettings,
AuthentificationSettings authSettings,
EMailSettings mailSettings,
FrontendSettings frontendSettings,
IHostEnvironment env,
ISMTPClient smtpClient
)
{
this._apiSettings = apiSettings;
this._databaseSettings = databaseSettings;
this._authSettings = authSettings;
this._mailSettings = mailSettings;
this._frontendSettings = frontendSettings;
this._env = env;
this._smtpClient = smtpClient;
}
// GET /api/gui/api-version
[HttpGet("api-version")]
public ApiVersionDTO GetApiVersion()
{
return new ApiVersionDTO()
{
Major = this._apiSettings.ApiVersion.Major,
Minor = this._apiSettings.ApiVersion.Minor,
Micro = this._apiSettings.ApiVersion.Micro
};
}
// GET /api/gui/settings
[HttpGet("settings")]
[Authorize]
public SettingsDTO GetSettingsDTO()
{
return new SettingsDTO()
{
ApiVersion = this._apiSettings.ApiVersion.ToString(),
ConfigPath = this._env.ContentRootPath,
WebBaseURL = this._frontendSettings.URL,
ApiBaseURL = "",
TokenExpireTime = this._authSettings.TokenExpireTime,
RefreshTokenExpireTime = this._authSettings.RefreshTokenExpireTime,
MailUser = this._mailSettings.Username,
MailPort = this._mailSettings.MailServerPort,
MailHost = this._mailSettings.MailServerAddress,
MailTransceiver = this._mailSettings.FromName,
MailTransceiverAddress = this._mailSettings.FromAddress
};
}
// POST /api/gui/send-test-mail/<email>
[HttpPost("send-test-mail/{email}")]
[Authorize]
public async Task SendTestMail(string email)
{
await _smtpClient.SendEmailAsync(new EMail()
{
Receiver = email,
Subject = $"Login counter Test E-Mail",
Message = $"Login counter Test E-Mail"
});
}
}
}