diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-01 10:46:31 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-01 10:46:31 +0200 |
| commit | e56d469e9fe865d8b423e1bdf5c3b872ee2319d8 (patch) | |
| tree | 98f8efbc5812971cbac4cc547e47af14c165b6dd /server/src | |
| parent | dc0d24a3c556e633ec86d82730e8f04d2326c436 (diff) | |
| download | greatoffice-e56d469e9fe865d8b423e1bdf5c3b872ee2319d8.tar.xz greatoffice-e56d469e9fe865d8b423e1bdf5c3b872ee2319d8.zip | |
refactor: Minor changes
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/Data/Database/ApiAccessToken.cs | 50 | ||||
| -rw-r--r-- | server/src/Data/Database/Base.cs | 20 | ||||
| -rw-r--r-- | server/src/Data/Database/BaseWithOwner.cs | 20 | ||||
| -rw-r--r-- | server/src/Data/Database/Customer.cs | 5 | ||||
| -rw-r--r-- | server/src/Data/Database/User.cs | 55 | ||||
| -rw-r--r-- | server/src/Services/MailService.cs | 85 | ||||
| -rw-r--r-- | server/src/Utilities/GithubAuthenticationHelpers.cs | 1 |
7 files changed, 116 insertions, 120 deletions
diff --git a/server/src/Data/Database/ApiAccessToken.cs b/server/src/Data/Database/ApiAccessToken.cs index a9cf0bc..9582869 100644 --- a/server/src/Data/Database/ApiAccessToken.cs +++ b/server/src/Data/Database/ApiAccessToken.cs @@ -2,30 +2,30 @@ namespace IOL.GreatOffice.Api.Data.Database; public class ApiAccessToken : Base { - public User User { get; set; } - public DateTime ExpiryDate { get; set; } - public bool AllowRead { get; set; } - public bool AllowCreate { get; set; } - public bool AllowUpdate { get; set; } - public bool AllowDelete { get; set; } - public bool HasExpired => ExpiryDate < AppDateTime.UtcNow; - public ApiAccessTokenDto AsDto => new(this); + public User User { get; set; } + public DateTime ExpiryDate { get; set; } + public bool AllowRead { get; set; } + public bool AllowCreate { get; set; } + public bool AllowUpdate { get; set; } + public bool AllowDelete { get; set; } + public bool HasExpired => ExpiryDate < AppDateTime.UtcNow; + public ApiAccessTokenDto AsDto => new(this); - public class ApiAccessTokenDto - { - public ApiAccessTokenDto(ApiAccessToken source) { - ExpiryDate = source.ExpiryDate; - AllowRead = source.AllowRead; - AllowCreate = source.AllowCreate; - AllowUpdate = source.AllowUpdate; - AllowDelete = source.AllowDelete; - } + public class ApiAccessTokenDto + { + public ApiAccessTokenDto(ApiAccessToken source) { + ExpiryDate = source.ExpiryDate; + AllowRead = source.AllowRead; + AllowCreate = source.AllowCreate; + AllowUpdate = source.AllowUpdate; + AllowDelete = source.AllowDelete; + } - public DateTime ExpiryDate { get; set; } - public bool AllowRead { get; set; } - public bool AllowCreate { get; set; } - public bool AllowUpdate { get; set; } - public bool AllowDelete { get; set; } - public bool HasExpired => ExpiryDate < AppDateTime.UtcNow; - } -} + public DateTime ExpiryDate { get; set; } + public bool AllowRead { get; set; } + public bool AllowCreate { get; set; } + public bool AllowUpdate { get; set; } + public bool AllowDelete { get; set; } + public bool HasExpired => ExpiryDate < AppDateTime.UtcNow; + } +}
\ No newline at end of file diff --git a/server/src/Data/Database/Base.cs b/server/src/Data/Database/Base.cs index 7e8591e..ae9efa2 100644 --- a/server/src/Data/Database/Base.cs +++ b/server/src/Data/Database/Base.cs @@ -2,14 +2,14 @@ namespace IOL.GreatOffice.Api.Data.Database; public class Base { - protected Base() { - Id = Guid.NewGuid(); - CreatedAt = AppDateTime.UtcNow; - } + protected Base() { + Id = Guid.NewGuid(); + CreatedAt = AppDateTime.UtcNow; + } - public Guid Id { get; init; } - public DateTime CreatedAt { get; init; } - public DateTime? ModifiedAt { get; private set; } - public bool Deleted { get; set; } - public void Modified() => ModifiedAt = AppDateTime.UtcNow; -} + public Guid Id { get; init; } + public DateTime CreatedAt { get; init; } + public DateTime? ModifiedAt { get; private set; } + public bool Deleted { get; set; } + public void Modified() => ModifiedAt = AppDateTime.UtcNow; +}
\ No newline at end of file diff --git a/server/src/Data/Database/BaseWithOwner.cs b/server/src/Data/Database/BaseWithOwner.cs index 8c54aa2..1eb99f4 100644 --- a/server/src/Data/Database/BaseWithOwner.cs +++ b/server/src/Data/Database/BaseWithOwner.cs @@ -5,15 +5,15 @@ namespace IOL.GreatOffice.Api.Data.Database; /// </summary> public class BaseWithOwner : Base { - protected BaseWithOwner() { } + protected BaseWithOwner() { } - protected BaseWithOwner(Guid userId) { - UserId = userId; - } + protected BaseWithOwner(Guid userId) { + UserId = userId; + } - public Guid? UserId { get; set; } - public Guid? TenantId { get; init; } - public Guid? ModifiedById { get; init; } - public Guid? CreatedById { get; init; } - public Guid? DeletedById { get; init; } -} + public Guid? UserId { get; set; } + public Guid? TenantId { get; init; } + public Guid? ModifiedById { get; init; } + public Guid? CreatedById { get; init; } + public Guid? DeletedById { get; init; } +}
\ No newline at end of file diff --git a/server/src/Data/Database/Customer.cs b/server/src/Data/Database/Customer.cs index 7e83c00..c6b06a4 100644 --- a/server/src/Data/Database/Customer.cs +++ b/server/src/Data/Database/Customer.cs @@ -2,6 +2,5 @@ namespace IOL.GreatOffice.Api.Data.Database; public class Customer : BaseWithOwner { - public string Name { get; set; } - -} + public string Name { get; set; } +}
\ No newline at end of file diff --git a/server/src/Data/Database/User.cs b/server/src/Data/Database/User.cs index 1ef144c..9db5d35 100644 --- a/server/src/Data/Database/User.cs +++ b/server/src/Data/Database/User.cs @@ -2,37 +2,36 @@ namespace IOL.GreatOffice.Api.Data.Database; public class User : Base { - public User() { } + public User() { } - public User(string username) { - Username = username; - } + public User(string username) { + Username = username; + } - public string FirstName { get; set; } - public string LastName { get; set; } - public string Email { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public ICollection<Tenant> Tenants { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Email { get; set; } + public string Username { get; set; } + public string Password { 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() { - if (FirstName.HasValue() && LastName.HasValue()) return FirstName + " " + LastName; - return FirstName.HasValue() ? FirstName : Email; - } + public void HashAndSetPassword(string password) { + Password = PasswordHelper.HashPassword(password); + } - public void HashAndSetPassword(string password) { - Password = PasswordHelper.HashPassword(password); - } + public bool VerifyPassword(string password) { + return PasswordHelper.Verify(password, Password); + } - public bool VerifyPassword(string password) { - return PasswordHelper.Verify(password, Password); - } - - public IEnumerable<Claim> DefaultClaims() { - return new Claim[] { - new(AppClaims.USER_ID, Id.ToString()), - new(AppClaims.NAME, Username), - }; - } -} + public IEnumerable<Claim> DefaultClaims() { + return new Claim[] { + new(AppClaims.USER_ID, Id.ToString()), + new(AppClaims.NAME, Username), + }; + } +}
\ No newline at end of file diff --git a/server/src/Services/MailService.cs b/server/src/Services/MailService.cs index a64d203..c08cb84 100644 --- a/server/src/Services/MailService.cs +++ b/server/src/Services/MailService.cs @@ -1,50 +1,49 @@ -using Microsoft.Extensions.Options; - namespace IOL.GreatOffice.Api.Services; public class MailService { - private readonly ILogger<MailService> _logger; - private static string _emailHost; - private static int _emailPort; - private static string _emailUser; - private static string _emailPassword; + private readonly ILogger<MailService> _logger; + private static string _emailHost; + private static int _emailPort; + private static string _emailUser; + private static string _emailPassword; - public MailService(VaultService vaultService, ILogger<MailService> logger) { - var configuration = vaultService.GetCurrentAppConfiguration(); - _logger = logger; - _emailHost = configuration.SMTP_HOST; - _emailPort = Convert.ToInt32(configuration.SMTP_PORT); - _emailUser = configuration.SMTP_USER; - _emailPassword = configuration.SMTP_PASSWORD; - } + public MailService(VaultService vaultService, ILogger<MailService> logger) { + var configuration = vaultService.GetCurrentAppConfiguration(); + _logger = logger; + _emailHost = configuration.SMTP_HOST; + _emailPort = Convert.ToInt32(configuration.SMTP_PORT); + _emailUser = configuration.SMTP_USER; + _emailPassword = configuration.SMTP_PASSWORD; + } - /// <summary> - /// Send an email. - /// </summary> - /// <param name="message"></param> - public void SendMail(MailMessage message) { - using var smtpClient = new SmtpClient { - Host = _emailHost, - EnableSsl = _emailPort == 587, - Port = _emailPort, - Credentials = new NetworkCredential { - UserName = _emailUser, - Password = _emailPassword, - } - }; - var configurationString = JsonSerializer.Serialize(new { - Host = smtpClient.Host, - EnableSsl = smtpClient.EnableSsl, - Port = smtpClient.Port, - UserName = _emailUser.HasValue() ? "**REDACTED**" : "**MISSING**", - Password = _emailPassword.HasValue() ? "**REDACTED**" : "**MISSING**", - }, - new JsonSerializerOptions { - WriteIndented = true - }); - _logger.LogDebug("SmtpClient was instansiated with the following configuration\n" + configurationString); + /// <summary> + /// Send an email. + /// </summary> + /// <param name="message"></param> + public void SendMail(MailMessage message) { + using var smtpClient = new SmtpClient { + Host = _emailHost, + EnableSsl = _emailPort == 587, + Port = _emailPort, + Credentials = new NetworkCredential { + UserName = _emailUser, + Password = _emailPassword, + } + }; + var configurationString = JsonSerializer.Serialize(new { + smtpClient.Host, + smtpClient.EnableSsl, + smtpClient.Port, + UserName = _emailUser.HasValue() ? "**REDACTED**" : "**MISSING**", + Password = _emailPassword.HasValue() ? "**REDACTED**" : "**MISSING**", + }, + new JsonSerializerOptions { + WriteIndented = true + }); + + _logger.LogDebug("SmtpClient was instansiated with the following configuration\n" + configurationString); - smtpClient.Send(message); - } -} + smtpClient.Send(message); + } +}
\ No newline at end of file diff --git a/server/src/Utilities/GithubAuthenticationHelpers.cs b/server/src/Utilities/GithubAuthenticationHelpers.cs index f78e1ae..a4461d2 100644 --- a/server/src/Utilities/GithubAuthenticationHelpers.cs +++ b/server/src/Utilities/GithubAuthenticationHelpers.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Authentication.OAuth; -using Microsoft.Extensions.Options; using Npgsql; namespace IOL.GreatOffice.Api.Utilities; |
