public IEnumerable <ValidationResult> Validate(AccountCommand command) { AccountByUsernameQuery query = new AccountByUsernameQuery(command.Username); Account account = accountHandler.Handle(query); if (account == null) { return(new List <ValidationResult>() { new ValidationResult(nameof(command.Username), "Could not find account with such username!") }); } PasswordCommand encryptPasswordCommand = new PasswordCommand(command.Password); string encryptedPassword = encryptPasswordHandler.Handle(encryptPasswordCommand); if (encryptedPassword != account.Password) { return(new List <ValidationResult>() { new ValidationResult(nameof(command.Password), "Invalid password!") }); } return(Enumerable.Empty <ValidationResult>()); }
public Account Handle(AccountCommand command) { PasswordCommand encryptPasswordCommand = new PasswordCommand(command.Password); string password = encryptPasswordHandler.Handle(encryptPasswordCommand); Account account = Mapper.Map <Account>(command); account.Balance = DEFAULT_BALANCE; account.Password = password; account.CreatedOn = DateTime.UtcNow; dbContext.GetCollection <Account>().InsertOne(account); return(account); }
public IActionResult ValidatePassword([FromBody] PasswordCommand command) { var isValid = _passwordService.Validate(command.Password); return(isValid ? NoContent() : Conflict(new { Errors = new [] { "INVALID_PASSWORD_FORMAT" } })); }