public AuthDto Login(AuthCommand command) { var user = _userRepository.GetByLogin(command.Login); if (user == null) { _notificationProvider.AddValidationError("User", "Usuário ou senha inválido"); return(null); } if (!_encrypterService.Compare(command.Password, user.Salt, user.HashPassword)) { _notificationProvider.AddValidationError("User", "Usuário ou senha inválido"); return(null); } if (user.IsDeleted) { _notificationProvider.AddValidationError("User", "Usuário inválido"); return(null); } var jwtToken = _jwt.Create(user.Login, user.Name); return(new AuthDto(jwtToken.Token)); }
public override async Task <UserDto> PostAsync(UserCreateCommand command) { if (!CheckRules <UserRegisterCommandValidation, UserCreateCommand>(command)) { return(null); } //criar metodo repository de buscar por login if (_userRepository.GetByLogin(command.Login) != null) { _notificationProvider.AddValidationError("Login", "Já existe um usuário com este login"); } if (_notificationProvider.HasErrors()) { return(null); } //valida os dados //encriptar password var user = new User(command.Login, command.Name, command.Email) .CreatePassword(command.Password, _encrypterService); if (CheckRules <UserValidation, User>(user)) { await _repository.InsertAsync(user); } await CommitAsync(); return(_mapper.Map <UserDto>(user)); }
public virtual async Task <TDto> GetAsync(TId id) { var entity = _repository.Get(id); if (entity == null) { _notificationProvider.AddValidationError("User", "Usuário não encontrado"); } return(_mapper.Map <T, TDto>(entity)); }