Ejemplo n.º 1
0
        public string Autenticar(string email, string senha)
        {
            try
            {
                Usuario usuarioExistente = Obter(email, PorEmail.PorEmail);
                if (usuarioExistente == null)
                {
                    throw new Exception(string.Format("O endereço de e-mail '{0}' não foi encontrado em nosso cadastro!", email.ToLower()));
                }
                if (!usuarioExistente.EstaAtivo)
                {
                    throw new Exception(string.Format("O endereço de e-mail '{0}' não está ativo em nosso cadastro!", email.ToLower()));
                }
                if (_criptografiaService.Descriptografar(usuarioExistente.Senha, dados1) != senha)
                {
                    throw new Exception("A senha informada não é válida!");
                }

                //Gerar o token de sessão a ser retornada para o aplicativo cliente
                return(GerarTokenSessao(email));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }