public async Task HandleAsync(SendPasswordResetCommand command) { var user = await _userRepository.GetAsync(command.Email); if (user is null) { return; } var token = _authTokenService.Create(user.Id, user.PasswordHash); var link = _linkGenerator.GenerateResetPasswordLink(user.Id, token); var message = BuildMessage(user, link); await _mailService.SendAsync(message); }
public async Task HandleAsync(SignInCommand command) { var user = await _userRepository.GetAsync(command.Email) ?? throw new InvalidCredentialsException(); if (!user.IsVerified) { throw new InvalidCredentialsException(); } var result = _passwordHasher.VerifyHashedPassword(user, user.PasswordHash, command.Password); if (result == PasswordVerificationResult.Failed) { throw new InvalidCredentialsException(); } var authDto = _authTokenService.Create(user.Id); _tokensCache.Set(user.Email, authDto); }