package br.com.ec.controller.seguranca;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.context.annotation.Scope;
import br.com.ec.domain.dto.UsuarioDTO;
import br.com.ec.domain.model.tipos.TipoAno;
import br.com.ec.domain.model.tipos.TipoMes;
import br.com.ec.domain.service.ContextoSeguranca;
import br.com.ec.domain.service.PerfilService;
import br.com.ec.domain.service.UsuarioService;
import br.com.ec.web.exception.VerificadorLancamentoException;
import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean;
import br.com.ec.web.message.LancadorMensagem;
@Named
@Scope
("view")
public class SegurancaBean
{
private UsuarioDTO usuarioDTO
;
private String senhaAtual
;
private String novaSenha
;
private String loginParaResetarSenha
;
private String cpfParaResetarSenha
;
private ContextoSeguranca contextoSeguranca
;
private UsuarioService usuarioService
;
private PerfilService perfilService
;
@Inject
public SegurancaBean
(ContextoSeguranca contextoSeguranca, UsuarioService usuarioService, PerfilService perfilService
) {
this.
contextoSeguranca = contextoSeguranca
;
this.
usuarioService = usuarioService
;
this.
perfilService = perfilService
;
}
public UsuarioDTO getUsuarioDTO
() {
if (usuarioDTO ==
null) {
setUsuarioDTO
(contextoSeguranca.
obterUsuario());
}
return usuarioDTO
;
}
public void setUsuarioDTO
(UsuarioDTO usuarioDTO
) {
this.
usuarioDTO = usuarioDTO
;
}
public String getSenhaAtual
() {
return senhaAtual
;
}
public void setSenhaAtual
(String senhaAtual
) {
this.
senhaAtual = senhaAtual
;
}
public String getNovaSenha
() {
return novaSenha
;
}
public void setNovaSenha
(String novaSenha
) {
this.
novaSenha = novaSenha
;
}
public String getLoginParaResetarSenha
() {
return loginParaResetarSenha
;
}
public void setLoginParaResetarSenha
(String loginParaResetarSenha
) {
this.
loginParaResetarSenha = loginParaResetarSenha
;
}
public String getCpfParaResetarSenha
() {
return cpfParaResetarSenha
;
}
public void setCpfParaResetarSenha
(String cpfParaResetarSenha
) {
this.
cpfParaResetarSenha = cpfParaResetarSenha
;
}
/************************************************************************/
public void alterarSenhaUsuario
() {
new VerificadorLancamentoException
().
tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean
() {
public void execute
() {
usuarioService.
alterarSenhaUsuario(getUsuarioDTO
().
getLogin(), getSenhaAtual
(), getNovaSenha
());
setSenhaAtual
("");
setNovaSenha
("");
LancadorMensagem.
lancarSucesso("SENHA ALTERADA COM SUCESSO");
}
});
}
public void resetarSenha
() {
new VerificadorLancamentoException
().
tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean
() {
public void execute
() {
String emailEnviado = usuarioService.
resetarSenhaUsuarioRetornandoEmail(getLoginParaResetarSenha
(), getCpfParaResetarSenha
());
setLoginParaResetarSenha
("");
setCpfParaResetarSenha
("");
LancadorMensagem.
lancarSucesso("SENHA PROVISÓRIA ENVIADA PARA O EMAIL: " + emailEnviado
);
}
});
}
public Boolean temPerfilAdministrador
() {
return perfilService.
temPerfilAdministrador(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteAdministrativo
() {
return perfilService.
temPerfilGerenteAdministrativo(getUsuarioDTO
().
getPerfis());
}
/************************************************************************/
public Boolean temPerfilGerenteFinanceiro
() {
return perfilService.
temPerfilGerenteFinanceiro(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteComercial
() {
return perfilService.
temPerfilGerenteComercial(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteDeLojistica
() {
return perfilService.
temPerfilGerenteDeLojistica(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilVendedor
() {
return perfilService.
temPerfilVendedor(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteDeCompras
() {
return perfilService.
temPerfilGerenteDeCompras(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteVivo
() {
return perfilService.
temPerfilGerenteVivo(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilTecnico
() {
return perfilService.
temPerfilTecnico(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilRecursosHumanos
() {
return perfilService.
temPerfilRecursosHumanos(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilGerenteDeOperacoes
() {
return perfilService.
temPerfilGerenteDeOperacoes(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilSupervisor
() {
return perfilService.
temPerfilSupervisor(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilTreinamento
() {
return perfilService.
temPerfilTreinamento(getUsuarioDTO
().
getPerfis());
}
public Boolean temPerfilLoja
() {
return perfilService.
temPerfilLoja(getUsuarioDTO
().
getPerfis());
}
public TipoAno
[] getTiposAno
() {
return TipoAno.
values();
}
public TipoMes
[] getTiposMes
() {
return TipoMes.
values();
}
/*
public Boolean temAcessoLoja(Long sequencialLoja) {
return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuarioDTO().getPerfis(), sequencialLoja);
}
public Boolean temAcessoLojaVivo() {
return temPerfilGerenteAdministrativo() || verificarAcessoLoja(getUsuarioDTO().getPerfis(), ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4);
}
public Boolean temAcessoLojaCasaDasCapas() {
return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || (verificarAcessoLoja(getUsuarioDTO().getPerfis(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor());
}
public Boolean naoTemAcessoLojaCasaDasCapas() {
return temPerfilGerenteDeCompras() || temPerfilGerenteComercial() || !(verificarAcessoLoja(getUsuarioDTO().getPerfis(), ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17) && temPerfilVendedor());
}
*/
/*
private Boolean verificarAcessoLoja(Usuario usuario, Long sequencialLoja) {
for (UsuarioLoja usuarioLoja : usuario.getLojas()) {
if (usuarioLoja.getLoja().getSequencial().equals(sequencialLoja)) {
return true;
}
}
return false;
}
public void restaurarTelaPDV(Loja loja) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial());
}
public void restaurarTelaPDVVivo(Loja loja) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv_vivo.xhtml?sequencialLoja=" + loja.getSequencial());
}
public void restaurarTelaPDVFarma(Loja loja) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/sistema/pdv.xhtml?sequencialLoja=" + loja.getSequencial());
}
public void invalidarSessao() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
}
public Integer getTempoEstoqueMinimoParaComprasEmDias() {
Parametro parametro = new Parametro();
parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_MINIMO_PARA_COMPRAS);
parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro));
return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 15;
}
public Integer getTempoEstoqueParaReporEmDias() {
Parametro parametro = new Parametro();
parametro.setCodigo(ConstantesSEC.Parametro.CODIGO_PARAMETRO_TEMPO_ESTOQUE_REPOSICAO_PARA_COMPRAS);
parametro = getUsuario().getParametros().get(getUsuario().getParametros().indexOf(parametro));
return VerificadorUtil.naoEstaNulo(parametro)? new Integer(parametro.getValor()) : 60;
}
public String textoSobreCorMargem() {
return ConstantesSEC.Textos.TEXTO_COR_MARGEM;
}
*/
}