public Result <TokenModel> ValidanteAndCreateToken(AuthUser authUser) { var validator = new ValidationAuthUser(); var validatedAuthUser = validator.Validate(authUser); if (!validatedAuthUser.IsValid) { return(Result <TokenModel> .Error(validatedAuthUser)); } var userFromDb = contextJwt.AuthUser.SingleOrDefault(x => x.Email == authUser.Email); if (userFromDb == null) { return(Result <TokenModel> .Error("Usuário não localizado.")); } if (userFromDb.Password != authUser.Password) { return(Result <TokenModel> .Error("Senha inválida.")); } var token = new CreateToken().Create(authUser, signingConfigurations, tokenConfigurations); return(Result <TokenModel> .Sucess(token)); }
public Result <AuthUser> CadastrarUsuario(AuthUser authUser) { var validator = new ValidationAuthUser(); var validatedAuthUser = validator.Validate(authUser); if (!validatedAuthUser.IsValid) { return(Result <AuthUser> .Error(validatedAuthUser)); } if (contextJwt.AuthUser.Any(x => x.Email == authUser.Email)) { return(Result <AuthUser> .Error("Já existe um usuario cadastrado com o E-mail informado")); } CriarUsuario(authUser); return(Result <AuthUser> .Sucess(authUser)); }