コード例 #1
0
        private void ValideToken(string token)
        {
            var spec       = UsuarioSpecifications.ConsulteTokenSenha(token);
            var tokenSenha = _tokenSenhaRepository.AllMatching(spec).SingleOrDefault();

            if (tokenSenha == null)
            {
                throw new AppException("Link inválido ou já utilizado.");
            }

            if (tokenSenha.Data > DateTime.Now.AddDays(2))
            {
                throw new AppException("Este link expirou.");
            }
        }
コード例 #2
0
        public void RedefinirSenhaComToken(string token, string senha, string confirmaSenha)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(token))
                {
                    throw new ArgumentException("Valor não pode ser nulo ou vazio.", "token");
                }

                ValideToken(token);

                if (string.IsNullOrWhiteSpace(senha))
                {
                    throw new AppException("Nova senha não informada.");
                }

                if (string.IsNullOrWhiteSpace(confirmaSenha))
                {
                    throw new AppException("Confirmação da nova senha não informada.");
                }

                if (senha != confirmaSenha)
                {
                    throw new AppException("Nova senha não confere com a confirmação da nova senha.");
                }

                var spec       = UsuarioSpecifications.ConsulteTokenSenha(token);
                var tokenSenha = _tokenSenhaRepository.AllMatching(spec).Single();

                var usuario = _usuarioRepository.Get(tokenSenha.UsuarioId);

                usuario.Senha = Encryption.Encrypt(senha);
                _tokenSenhaRepository.Remove(tokenSenha);

                _tokenSenhaRepository.Commit();
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }