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