Subversion Repositories Integrator Subversion

Rev

Rev 218 | Rev 226 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 218 Rev 224
Line 11... Line 11...
11
import br.com.ec.domain.dto.UsuarioDTO;
11
import br.com.ec.domain.dto.UsuarioDTO;
12
import br.com.ec.domain.modal.Usuario;
12
import br.com.ec.domain.modal.Usuario;
13
import br.com.ec.domain.service.UsuarioService;
13
import br.com.ec.domain.service.UsuarioService;
14
import br.com.ec.repository.UsuarioRepository;
14
import br.com.ec.repository.UsuarioRepository;
15
import br.com.ec.shared.CriptografiaMD5;
15
import br.com.ec.shared.CriptografiaMD5;
-
 
16
import br.com.ec.shared.EmailComponente;
-
 
17
import br.com.ec.shared.SharedComponente;
16
18
17
@Service
19
@Service
18
public class UsuarioServiceImpl extends AbstractService<Usuario> implements UsuarioService {
20
public class UsuarioServiceImpl extends AbstractService<Usuario> implements UsuarioService {
19
21
20
        private static final String USUARIO_INFORMADO_NAO_EXISTE = "Usuário informado não existe";
-
 
-
 
22
        private static final String USUARIO_INFORMADO_NAO_EXISTE = "Usuário informado não existe";
21
        private final UsuarioRepository usuarioRepository;
23
        private final UsuarioRepository usuarioRepository;
22
//      private ParametroService parametroService;
24
//      private ParametroService parametroService;
23
25
24
        @Autowired
26
        @Autowired
25
        public UsuarioServiceImpl(/* ParametroService parametroService, */UsuarioRepository usuarioRepository, Validador validador) {
27
        public UsuarioServiceImpl(/* ParametroService parametroService, */UsuarioRepository usuarioRepository, Validador validador) {
Line 40... Line 42...
40
        }
42
        }
41
       
43
       
42
        @Override
44
        @Override
43
        public void alterarSenhaUsuario(String login, String senhaAtual, String novaSenha) {
45
        public void alterarSenhaUsuario(String login, String senhaAtual, String novaSenha) {
44
                verificarSenhas(login, senhaAtual, novaSenha);
46
                verificarSenhas(login, senhaAtual, novaSenha);
45
                usuarioRepository.alterarSenha(login, novaSenha);
-
 
-
 
47
                usuarioRepository.alterarSenha(login, CriptografiaMD5.criptografaSenha(novaSenha));
46
        }
48
        }
47
       
49
       
48
        private void verificarSenhas(String login, String senhaAtual, String novaSenha) {
50
        private void verificarSenhas(String login, String senhaAtual, String novaSenha) {
49
                if (VerificadorUtil.estaNuloOuVazio(novaSenha)) {
51
                if (VerificadorUtil.estaNuloOuVazio(novaSenha)) {
50
                        throw new NegocioException("Senha inválida");
-
 
-
 
52
                        throw new NegocioException("Senha inválida");
51
                }
53
                }
52
                if (novaSenha.length() < 6) {
54
                if (novaSenha.length() < 6) {
53
                        throw new NegocioException("A senha deve ter 6 dígitos, no mínimo");
-
 
-
 
55
                        throw new NegocioException("A senha deve ter 6 dígitos, no mínimo");
54
                }
56
                }
55
               
57
               
56
                try {
58
                try {
57
                        consultarPorLogin(login, senhaAtual);
59
                        consultarPorLogin(login, senhaAtual);
58
                } catch (Exception e) {
60
                } catch (Exception e) {
59
                        throw new NegocioException("Senha atual incorreta");
61
                        throw new NegocioException("Senha atual incorreta");
60
                }
62
                }
61
               
63
               
62
                if (senhaJaExisteEmOutroLogin(login, novaSenha)) {
-
 
63
                        throw new NegocioException("Senha já existente, tente outra");
-
 
-
 
64
                verificarSeSenhaJaExisteEmOutroLogin(login, novaSenha);
-
 
65
        }
-
 
66
       
-
 
67
        private void verificarSeSenhaJaExisteEmOutroLogin(String login, String senha) {
-
 
68
                if (usuarioRepository.obterQuantidadeUsuarioDiferenteComSenhaInformada(login, CriptografiaMD5.criptografaSenha(senha)) > 0) {
-
 
69
                        throw new NegocioException("Senha já existente, tente outra");
64
                }
70
                }
65
        }
71
        }
66
       
72
       
67
        private Boolean senhaJaExisteEmOutroLogin(String login, String senha) {
-
 
68
                return usuarioRepository.obterQuantidadeUsuarioDiferenteComSenhaInformada(login, CriptografiaMD5.criptografaSenha(senha)) > 0 ? true : false;
-
 
-
 
73
        @Override
-
 
74
        public void resetarSenhaUsuario(String login) {
-
 
75
                // BUSCAR EMAIL DO USUÁRIO
-
 
76
                String emailUsuario = usuarioRepository.consultarEmailPorLogin(login);
-
 
77
                if (VerificadorUtil.estaNuloOuVazio(emailUsuario)) {
-
 
78
                        throw new NegocioException("Usuário não possui email, favor entrar em contato com a administração");
-
 
79
                }
-
 
80
               
-
 
81
                // GERAR SENHA PROVISÓRIA
-
 
82
                String senhaProvisoria = new SharedComponente().gerarSenha(8);
-
 
83
               
-
 
84
                // ALTERAR NOVA SENHA DO USUÁRIO
-
 
85
                usuarioRepository.alterarSenha(login, CriptografiaMD5.criptografaSenha(senhaProvisoria));
-
 
86
               
-
 
87
                // ENVIAR EMAIL PARA O USUÁRIO
-
 
88
                new EmailComponente()
-
 
89
                        .comEmailDestino(emailUsuario)
-
 
90
                        .comAssunto("ESPAÇO CASE - REDEFINIÇÃO DE SENHA")
-
 
91
                        .comConteudoHtml("Sua nova senha: " + senhaProvisoria)
-
 
92
                        .enviar();
69
        }
93
        }
70
       
94
       
71
        /*
95
        /*
72
        @Override
96
        @Override
73
        protected void regrasNegocioCadastrar(Usuario usuario) {
97
        protected void regrasNegocioCadastrar(Usuario usuario) {
Line 77... Line 101...
77
       
101
       
78
        @Override
102
        @Override
79
        public Usuario efetuarLogin(Usuario usuario) {
103
        public Usuario efetuarLogin(Usuario usuario) {
80
                if (VerificadorUtil.naoEstaNuloOuVazio(usuario.getSenha())) {
104
                if (VerificadorUtil.naoEstaNuloOuVazio(usuario.getSenha())) {
81
                        if (usuario.getSenha().length() < 6) {
105
                        if (usuario.getSenha().length() < 6) {
82
                                throw new RuntimeException("Senha inválida");
-
 
-
 
106
                                throw new RuntimeException("Senha inv�lida");
83
                        }
107
                        }
84
                } else {
108
                } else {
85
                        throw new RuntimeException("Senha inválida");
-
 
-
 
109
                        throw new RuntimeException("Senha inv�lida");
86
                }
110
                }
87
                try {
111
                try {
88
                        criptografarSenhaUsuarioEmMD5(usuario);
112
                        criptografarSenhaUsuarioEmMD5(usuario);
89
                        Usuario usuarioConsultado = usuarioRepository.consultarPorLogin(usuario);
113
                        Usuario usuarioConsultado = usuarioRepository.consultarPorLogin(usuario);
90
                        if (VerificadorUtil.naoEstaNulo(usuarioConsultado)) {
114
                        if (VerificadorUtil.naoEstaNulo(usuarioConsultado)) {