Skip to content

Commit

Permalink
Move sensitive data to userSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
skrawus committed Jun 14, 2024
1 parent c76eaa5 commit b708ad6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion TutorLizard.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public async Task<IActionResult> ActivateAccount(string activationCode)
}
}


public IActionResult AccessDenied()
{
return View();
Expand Down
13 changes: 13 additions & 0 deletions TutorLizard.Web/Models/EmailSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TutorLizard.Web.Models
{
public class EmailSettings
{
public string MailAddress { get; set; }
public string Password { get; set; }
public string SmtpHost { get; set; }
public int SmtpPort { get; set; }
public string FromAddress { get; set; }
public string FromPassword { get; set; }
}

}
3 changes: 3 additions & 0 deletions TutorLizard.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TutorLizard.BusinessLogic.Options;
using TutorLizard.BusinessLogic.Services;
using TutorLizard.Web.Interfaces.Services;
using TutorLizard.Web.Models;
using TutorLizard.Web.Services;

var builder = WebApplication.CreateBuilder(args);
Expand Down Expand Up @@ -43,7 +44,9 @@
.LogTo(Console.WriteLine, LogLevel.Information);
});


builder.Services.AddTutorLizardDbRepositories<JaszczurContext>();
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));

var app = builder.Build();

Expand Down
12 changes: 9 additions & 3 deletions TutorLizard.Web/Services/UserAuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using TutorLizard.BusinessLogic.Interfaces.Services;
using TutorLizard.BusinessLogic.Interfaces.Data.Repositories;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using TutorLizard.Web.Models;
using Microsoft.Extensions.Options;

namespace TutorLizard.BusinessLogic.Services;

Expand All @@ -16,12 +19,14 @@ public class UserAuthenticationService : IUserAuthenticationService
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUserService _userService;
private readonly JaszczurContext _dbContext;
private readonly EmailSettings _emailSettings;

public UserAuthenticationService(IHttpContextAccessor httpContextAccessor, IUserService userService, JaszczurContext dbContext)
public UserAuthenticationService(IHttpContextAccessor httpContextAccessor, IUserService userService, JaszczurContext dbContext, IOptions<EmailSettings> emailSettings)
{
_httpContextAccessor = httpContextAccessor;
_userService = userService;
_dbContext = dbContext;
_emailSettings = emailSettings.Value;
}

public async Task<bool> LogInAsync(string username, string password)
Expand Down Expand Up @@ -95,9 +100,10 @@ public Task<bool> RegisterUser(string username, UserType type, string email, str

public void SendActivationEmail(string userEmail, string activationCode)
{
var fromAddress = new MailAddress("[email protected]", "Tutor Lizard");
var fromAddress = new MailAddress(_emailSettings.FromAddress, "Tutor Lizard");
var toAddress = new MailAddress(userEmail);
const string fromPassword = "pvez johg nzwc enjg";
var fromPassword = _emailSettings.FromPassword;

string subject = "Aktywacja konta";
string body = $"Cześć tu zespół Tutor Lizard, \naby aktywować swoje konto, kliknij poniższy link: \nhttp://localhost:7092/Account/ActivateAccount?activationCode={activationCode}";

Expand Down

0 comments on commit b708ad6

Please sign in to comment.