public async Task <AuthResult> Handle(AuthCommand command, CancellationToken cancellationToken) { var result = new AuthResult(); var user = await _userRepository.FindAsync(x => x.Email.ToLower().Equals(command.Email.ToLower()) && x.Active); if (user == null) { Notifications.Notifications.Add(new Notification("Credencial invalida.")); return(result); } if (!_passwordHasherService.Check(user.Senha, command.Senha)) { Notifications.Notifications.Add(new Notification("Senha invalida")); return(result); } switch (user.Type) { case EUserType.Administrator: return(await HandleAdmin(user)); case EUserType.Shopper: return(await HandleShopper(user)); default: return(null); } }
public async Task <ClaimsIdentity> GetIdentity(string email, string password) { var user = await _context.User.Include(x => x.UserSecurity) .ThenInclude(x => x.Role) .FirstOrDefaultAsync(x => x.Email == email); if (user?.UserSecurity == null) { throw ExceptionFactory.SoftException(ExceptionEnum.UserNotFound, $"User with email {email} not found"); } if (!_passwordHasherService.Check(user.UserSecurity.Password, password).Verified) { throw ExceptionFactory.SoftException(ExceptionEnum.PasswordIncorrect, "Password is incorrect"); } /*Ignore user not confirmed email because they have role preMember * if (user.UserSecurity.IsConfirmed == false) * throw ExceptionFactory.SoftException(ExceptionEnum.EmailNotConfirmed, $"Please confirm your email. Check spam folder!");*/ var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, user.Id.ToString()), new Claim(ClaimsIdentity.DefaultRoleClaimType, user.UserSecurity.Role.RoleName), }; return(new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType)); }
public bool Authenticate(string passwordStored, string passwordInputed) { return(_passwordService.Check(passwordStored, passwordInputed).Verified); }