Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ja 117 activation emails #107

Merged
merged 25 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
22086c9
Create SendActivationEmail method
skrawus Jun 6, 2024
0a71588
Create Activation emails
skrawus Jun 6, 2024
c3b9ba2
Make ActivationCode nullable
skrawus Jun 7, 2024
cf19d58
Make ActivateUser method async
skrawus Jun 7, 2024
9c69231
Correct return view and messages in ActivateAccount method
skrawus Jun 7, 2024
ce4d98d
Correct generating URL and change ActivationCode after activation
skrawus Jun 7, 2024
21e66fb
Add IsActive to UserDto and edit LogIn
skrawus Jun 7, 2024
6913c4c
Change Login method so it shows correct messages
skrawus Jun 7, 2024
c76eaa5
Fix IsUserActive method
skrawus Jun 7, 2024
b708ad6
Move sensitive data to userSecrets
skrawus Jun 14, 2024
026eb47
Add ActivationResult model
skrawus Jun 14, 2024
b1a3512
Move link to secrets
skrawus Jun 14, 2024
5d8d35e
Move activationCode generation to Service
skrawus Jun 14, 2024
b02f9e2
Change Activation page view
skrawus Jun 14, 2024
af3d37f
Fix logging in so only active user can log in
skrawus Jun 14, 2024
76dab34
Change repository
skrawus Jun 14, 2024
c88c3a4
Make LogIn method in IUserService not-nullable
skrawus Jun 15, 2024
b919b95
Change Exception in AccountController
skrawus Jun 15, 2024
5642e2f
Delete duplicated class
skrawus Jun 15, 2024
f53ed17
Make IsActive not nullable & update LogIn method
skrawus Jun 15, 2024
dfe0c00
Change the way of saving changes in ActivateUserAsync method
skrawus Jun 16, 2024
0184191
Merge develop into ja-117
skrawus Jun 16, 2024
df071c9
Move ActivateUserAsync method to UserService
skrawus Jun 23, 2024
c51b510
Move data to secrets
skrawus Jun 23, 2024
3ae5360
Merge develop into ja-117
skrawus Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Zjyslav marked this conversation as resolved.
Show resolved Hide resolved
{
_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}";
Zjyslav marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading