public AuthOutputDto Register(UsersInputDto user) { User userToRegister = new User(); foreach (PropertyInfo propertyInfo in user.GetType().GetProperties()) { string propertyName = propertyInfo.Name; string value = (string)user.GetType().GetProperty(propertyName).GetValue(user, null); if (value == "" || value == null) { ErrorAction error = new ErrorAction(1, Messages.Messages.CampoObrigatorio.Replace("{0}", propertyName)); throw error; } userToRegister.GetType().GetProperty(propertyName).SetValue(userToRegister, value); } userToRegister.Password = _cryptyService.GenerateHashKey(user.Password); User userData = _authRepository.Register(userToRegister); AuthInputDto login = new AuthInputDto { Email = userData.Email, Password = user.Password }; return(this.Login(login)); }
public ActionResult <AuthOutputDto> Login(AuthInputDto login) { try { AuthOutputDto tokenAcesso = _authAppService.Login(login); return(Ok(tokenAcesso)); } catch (ErrorAction error) { var err = BadRequest(new { error.Text, error.Status }); return(err); } }
public AuthOutputDto Login(AuthInputDto login) { string passwordHashed = _cryptyService.GenerateHashKey(login.Password); User userLoged = _authRepository.FindByUserOrEmail(login.Email); if (userLoged == null || !passwordHashed.Equals(userLoged.Password)) { ErrorAction error = new ErrorAction(1, Messages.Messages.UsuarioNaoEncontrado.Replace("{0}", login.Email)); throw error; } string token = _dataAgent.GenerateToken(userLoged); EnterpriseOutputDto userOutput = _mapper.Map <EnterpriseOutputDto>(userLoged); AuthOutputDto authOutput = new AuthOutputDto { Token = token, User = userOutput }; return(_mapper.Map <AuthOutputDto>(authOutput)); }