Skip to content

Commit

Permalink
Add ActivationResult model
Browse files Browse the repository at this point in the history
  • Loading branch information
skrawus committed Jun 14, 2024
1 parent b708ad6 commit 026eb47
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions TutorLizard.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private string GenerateActivationCode()
[HttpGet]
public async Task<IActionResult> ActivateAccount(string activationCode)
{
bool isActivated = await _userAuthenticationService.ActivateUserAsync(activationCode);
var result = await _userAuthenticationService.ActivateUserAsync(activationCode);

if (isActivated)
if (result.IsActivated)
{
_uiMessagesService.ShowSuccessMessage("Atywacja udana.");
return View("ActivateAccount");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TutorLizard.BusinessLogic.Enums;
using TutorLizard.Web.Models;

namespace TutorLizard.BusinessLogic.Interfaces.Services;

Expand All @@ -9,7 +10,7 @@ public interface IUserAuthenticationService
public Task<bool> LogInAsync(string username, string password);
public Task LogOutAsync();
public Task<bool> RegisterUser(string username, UserType type, string email, string password, string activationCode);
Task<bool> ActivateUserAsync(string activationCode);
Task<ActivationResult> ActivateUserAsync(string activationCode);
Task<bool> IsUserActive(string userName);
void SendActivationEmail(string email, string activationCode);
}
8 changes: 8 additions & 0 deletions TutorLizard.Web/Models/ActivationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TutorLizard.Web.Models
{
public class ActivationResult
{
public bool IsActivated { get; set; }
public string ActivationCode { get; set; }
}
}
14 changes: 11 additions & 3 deletions TutorLizard.Web/Services/UserAuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void SendActivationEmail(string userEmail, string activationCode)
}
}

public async Task<bool> ActivateUserAsync(string activationCode)
public async Task<ActivationResult> ActivateUserAsync(string activationCode)
{
var user = await _dbContext.Users
.FirstOrDefaultAsync(u => u.ActivationCode == activationCode && u.IsActive == false);
Expand All @@ -136,9 +136,17 @@ public async Task<bool> ActivateUserAsync(string activationCode)
user.IsActive = true;
user.ActivationCode = "DEACTIVATED";
await _dbContext.SaveChangesAsync();
return true;
return new ActivationResult
{
IsActivated = true,
ActivationCode = activationCode
};
}
return false;
return new ActivationResult
{
IsActivated = false,
ActivationCode = activationCode
};
}


Expand Down

0 comments on commit 026eb47

Please sign in to comment.