-
-
Save dcomartin/ab608bda28f42cc04251989ca48ad7fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public record NewUser(Guid RequestedByUserId); | |
| public record ResetPassword(Guid RequestedByUserId); | |
| public class User | |
| { | |
| public Guid UserId { get; private set; } | |
| public string Pasword { get; private set; } | |
| public void ResetPassword(Guid requestedUserId) | |
| { | |
| if (UserId != requestedUserId) | |
| { | |
| throw new UnauthorizedAccessException("You are not allowed to reset another users password."); | |
| } | |
| Pasword = PasswordGenerator.Temp(); | |
| } | |
| } | |
| public class RestPasswordHandler | |
| { | |
| private readonly DbContext _dbContext; | |
| public RestPasswordHandler(DbContext dbContext) | |
| { | |
| _dbContext = dbContext; | |
| } | |
| public void Handle(ResetPassword request) | |
| { | |
| var user = _dbContext.GetUser(request.RequestedByUserId); | |
| user.ResetPassword(request.RequestedByUserId); | |
| _dbContext.Save(user); | |
| } | |
| } | |
| public class NewUserHandler | |
| { | |
| private readonly DbContext _dbContext; | |
| public NewUserHandler(DbContext dbContext) | |
| { | |
| _dbContext = dbContext; | |
| } | |
| public void Handle(NewUser request) | |
| { | |
| var user = new User(); | |
| user.ResetPassword(request.RequestedByUserId); | |
| _dbContext.Save(user); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment