Rev 218 | Rev 226 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 218 | espaco | 1 | package br.com.ec.controller.seguranca; |
| 2 | |||
| 3 | import javax.inject.Inject; |
||
| 4 | |||
| 5 | import org.springframework.stereotype.Controller; |
||
| 6 | |||
| 7 | import br.com.ec.domain.dto.UsuarioDTO; |
||
| 8 | import br.com.ec.domain.service.ContextoSeguranca; |
||
| 9 | import br.com.ec.domain.service.UsuarioService; |
||
| 224 | espaco | 10 | import br.com.ec.shared.EmailComponente; |
| 218 | espaco | 11 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 12 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 13 | import br.com.ec.web.message.LancadorMensagem; |
||
| 14 | |||
| 15 | @Controller |
||
| 16 | public class SegurancaBean { |
||
| 17 | |||
| 18 | private UsuarioDTO usuarioDTO; |
||
| 19 | private String senhaAtual; |
||
| 20 | private String novaSenha; |
||
| 224 | espaco | 21 | |
| 22 | private String loginParaResetarSenha; |
||
| 218 | espaco | 23 | |
| 24 | private ContextoSeguranca contextoSeguranca; |
||
| 25 | private UsuarioService usuarioService; |
||
| 26 | |||
| 27 | @Inject |
||
| 28 | public SegurancaBean(ContextoSeguranca contextoSeguranca, UsuarioService usuarioService/*, PerfilService perfilService*/) { |
||
| 29 | this.contextoSeguranca = contextoSeguranca; |
||
| 30 | this.usuarioService = usuarioService; |
||
| 31 | // this.perfilService = perfilService; |
||
| 32 | } |
||
| 33 | |||
| 34 | public UsuarioDTO getUsuarioDTO() { |
||
| 35 | if (usuarioDTO == null) { |
||
| 36 | setUsuarioDTO(contextoSeguranca.obterUsuario()); |
||
| 37 | } |
||
| 38 | return usuarioDTO; |
||
| 39 | } |
||
| 40 | public void setUsuarioDTO(UsuarioDTO usuarioDTO) { |
||
| 41 | this.usuarioDTO = usuarioDTO; |
||
| 42 | } |
||
| 43 | |||
| 44 | public String getSenhaAtual() { |
||
| 45 | return senhaAtual; |
||
| 46 | } |
||
| 47 | public void setSenhaAtual(String senhaAtual) { |
||
| 48 | this.senhaAtual = senhaAtual; |
||
| 49 | } |
||
| 50 | |||
| 51 | public String getNovaSenha() { |
||
| 52 | return novaSenha; |
||
| 53 | } |
||
| 54 | public void setNovaSenha(String novaSenha) { |
||
| 55 | this.novaSenha = novaSenha; |
||
| 56 | } |
||
| 57 | |||
| 224 | espaco | 58 | public String getLoginParaResetarSenha() { |
| 59 | return loginParaResetarSenha; |
||
| 60 | } |
||
| 61 | public void setLoginParaResetarSenha(String loginParaResetarSenha) { |
||
| 62 | this.loginParaResetarSenha = loginParaResetarSenha; |
||
| 63 | } |
||
| 64 | |||
| 218 | espaco | 65 | /************************************************************************/ |
| 66 | |||
| 67 | public void alterarSenhaUsuario() { |
||
| 68 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 69 | public void execute() { |
||
| 70 | usuarioService.alterarSenhaUsuario(getUsuarioDTO().getLogin(), getSenhaAtual(), getNovaSenha()); |
||
| 71 | setSenhaAtual(""); |
||
| 72 | setNovaSenha(""); |
||
| 73 | LancadorMensagem.lancarSucesso("SENHA ALTERADA COM SUCESSO"); |
||
| 74 | } |
||
| 75 | }); |
||
| 76 | } |
||
| 77 | |||
| 224 | espaco | 78 | public void resetarSenha() { |
| 79 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 80 | public void execute() { |
||
| 81 | usuarioService.resetarSenhaUsuario(getLoginParaResetarSenha()); |
||
| 82 | setLoginParaResetarSenha(""); |
||
| 83 | LancadorMensagem.lancarSucesso("SENHA PROVISÓRIA ENVIADA POR EMAIL"); |
||
| 84 | } |
||
| 85 | }); |
||
| 86 | } |
||
| 87 | |||
| 218 | espaco | 88 | /* |
| 89 | public Boolean temPerfilAdministrador() { |
||
| 90 | return perfilService.temPerfilAdministrador(getUsuario()); |
||
| 91 | } |
||
| 92 | |||
| 93 | public Boolean temPerfilGerenteAdministrativo() { |
||
| 94 | return perfilService.temPerfilGerenteAdministrativo(getUsuario()); |
||
| 95 | } |
||
| 96 | */ |
||
| 97 | /************************************************************************/ |
||
| 98 | |||
| 99 | /* |
||
| 100 | public Boolean temPerfilGerenteFinanceiro() { |
||
| 101 | return perfilService.temPerfilGerenteFinanceiro(getUsuario()); |
||
| 102 | } |
||
| 103 | |||
| 104 | public Boolean temPerfilGerenteComercial() { |
||
| 105 | return perfilService.temPerfilGerenteComercial(getUsuario()); |
||
| 106 | } |
||
| 107 | |||
| 108 | public Boolean temPerfilGerenteDeLojistica() { |
||
| 109 | return perfilService.temPerfilGerenteDeLojistica(getUsuario()); |
||
| 110 | } |
||
| 111 | |||
| 112 | public Boolean temPerfilVendedor() { |
||
| 113 | return perfilService.temPerfilVendedor(getUsuario()); |
||
| 114 | } |
||
| 115 | |||
| 116 | public Boolean temPerfilGerenteDeCompras() { |
||
| 117 | return perfilService.temPerfilGerenteDeCompras(getUsuario()); |
||
| 118 | } |
||
| 119 | |||
| 120 | public Boolean temPerfilGerenteVivo() { |
||
| 121 | return perfilService.temPerfilGerenteVivo(getUsuario()); |
||
| 122 | } |
||
| 123 | |||
| 124 | public Boolean temPerfilTecnico() { |
||
| 125 | return perfilService.temPerfilTecnico(getUsuario()); |
||
| 126 | } |
||
| 127 | |||
| 128 | public Boolean temPerfilRecursosHumanos() { |
||
| 129 | return perfilService.temPerfilRecursosHumanos(getUsuario()); |
||
| 130 | } |
||
| 131 | |||
| 132 | public Boolean temPerfilGerenteDeOperacoes() { |
||
| 133 | return perfilService.temPerfilGerenteDeOperacoes(getUsuario()); |
||
| 134 | } |
||
| 135 | |||
| 136 | public Boolean temPerfilSupervisor() { |
||
| 137 | return perfilService.temPerfilSupervisor(getUsuario()); |
||
| 138 | } |
||
| 139 | |||
| 140 | public Boolean temPerfilTreinamento() { |
||
| 141 | return perfilService.temPerfilTreinamento(getUsuario()); |
||
| 142 | } |
||
| 143 | |||
| 144 | public Boolean temPerfilLoja() { |
||
| 145 | return perfilService.temPerfilLoja(getUsuario()); |
||
| 146 | } |
||
| 147 | |||
| 148 | public Boolean temAcessoLoja(Long sequencialLoja) { |
||
| 149 | return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), sequencialLoja); |
||
| 150 | } |
||
| 151 | |||
| 152 | public Boolean temAcessoLojaVivo() { |
||
| 153 | return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4); |
||
| 154 | } |
||
| 155 | |||
| 156 | public Boolean temAcessoLojaCasaDasCapas() { |
||
| 157 | return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || (verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor()); |
||
| 158 | } |
||
| 159 | |||
| 160 | public Boolean naoTemAcessoLojaCasaDasCapas() { |
||
| 161 | return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || !(verificarAcessoLoja(getUsuario(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor()); |
||
| 162 | } |
||
| 163 | |||
| 164 | private Boolean verificarAcessoLoja(Usuario usuario, Long sequencialLoja) { |
||
| 165 | for (UsuarioLoja usuarioLoja : usuario.getLojas()) { |
||
| 166 | if (usuarioLoja.getLoja().getSequencial().equals(sequencialLoja)) { |
||
| 167 | return true; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | return false; |
||
| 171 | } |
||
| 172 | |||
| 173 | public void restaurarTelaPDV(Loja loja) throws IOException { |
||
| 174 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 175 | } |
||
| 176 | |||
| 177 | public void restaurarTelaPDVVivo(Loja loja) throws IOException { |
||
| 178 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv_vivo.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 179 | } |
||
| 180 | |||
| 181 | public void restaurarTelaPDVFarma(Loja loja) throws IOException { |
||
| 182 | FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial()); |
||
| 183 | } |
||
| 184 | |||
| 185 | public void invalidarSessao() { |
||
| 186 | FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); |
||
| 187 | } |
||
| 188 | |||
| 189 | public Integer getTempoEstoqueMinimoParaComprasEmDias() { |
||
| 190 | Parametro parametro = new Parametro(); |
||
| 191 | parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_MINIMO_PARA_COMPRAS); |
||
| 192 | parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro)); |
||
| 193 | return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 15; |
||
| 194 | } |
||
| 195 | |||
| 196 | public Integer getTempoEstoqueParaReporEmDias() { |
||
| 197 | Parametro parametro = new Parametro(); |
||
| 198 | parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_REPOSICAO_PARA_COMPRAS); |
||
| 199 | parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro)); |
||
| 200 | return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 60; |
||
| 201 | } |
||
| 202 | |||
| 203 | public TipoAno[] getTiposAno() { |
||
| 204 | return TipoAno.values(); |
||
| 205 | } |
||
| 206 | |||
| 207 | public TipoMes[] getTiposMes() { |
||
| 208 | return TipoMes.values(); |
||
| 209 | } |
||
| 210 | |||
| 211 | public String textoSobreCorMargem() { |
||
| 212 | return ConstantesSEC.Textos.TEXTO_COR_MARGEM; |
||
| 213 | } |
||
| 214 | */ |
||
| 215 | } |