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