| 1 | 0 | package br.mia.test.view.swingworker; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import javax.swing.JLabel; |
| 7 | |
import javax.swing.JOptionPane; |
| 8 | |
|
| 9 | |
import org.jdesktop.swingworker.SwingWorker; |
| 10 | |
|
| 11 | |
import br.mia.test.controler.ControladorErro; |
| 12 | |
import br.mia.test.model.Projeto; |
| 13 | |
import br.mia.test.model.dao.DAOProject; |
| 14 | |
import br.mia.test.model.dao.DAOUser; |
| 15 | |
import br.mia.test.pessoas.Funcionario; |
| 16 | |
import br.mia.test.util.EncriptarSenha; |
| 17 | |
import br.mia.test.view.Global; |
| 18 | |
import br.mia.test.view.Principal; |
| 19 | |
import br.mia.test.view.progress.ProgressView; |
| 20 | 0 | |
| 21 | 0 | public class AutenticacaoLoad extends SwingWorker<Boolean, Object> |
| 22 | |
{ |
| 23 | |
|
| 24 | |
List<Projeto> projetos; |
| 25 | |
|
| 26 | |
private String login; |
| 27 | |
|
| 28 | |
private String senha; |
| 29 | |
|
| 30 | |
private boolean logado; |
| 31 | |
|
| 32 | 0 | @Override |
| 33 | 0 | protected Boolean doInBackground() throws Exception { |
| 34 | 0 | |
| 35 | 0 | try { |
| 36 | 0 | ProgressView progress = new ProgressView(); |
| 37 | 0 | |
| 38 | 0 | Global global = new Global(); |
| 39 | 0 | |
| 40 | 0 | progress.getContentPane().add( |
| 41 | 0 | new JLabel("Verificando Login e Senha"), |
| 42 | 0 | global.getLayout2()); |
| 43 | 0 | progress.pack(); |
| 44 | 0 | |
| 45 | 0 | if (login.equals("admin") && senha.equals("admin")) { |
| 46 | 0 | DAOProject dao = new DAOProject(); |
| 47 | 0 | |
| 48 | 0 | projetos = dao.selectProjetos(); |
| 49 | 0 | logado = true; |
| 50 | 0 | progress.getContentPane().add( |
| 51 | 0 | new JLabel("Usuario e Senha Administrador"), |
| 52 | 0 | global.getLayout2()); |
| 53 | 0 | |
| 54 | 0 | } else { |
| 55 | 0 | |
| 56 | 0 | DAOUser daoUser = new DAOUser(); |
| 57 | 0 | DAOProject dao = new DAOProject(); |
| 58 | 0 | try { |
| 59 | 0 | progress.getContentPane().add( |
| 60 | 0 | new JLabel("Selecionando dado do banco"), |
| 61 | 0 | global.getLayout2()); |
| 62 | 0 | progress.pack(); |
| 63 | 0 | Funcionario funcionario = daoUser.select(login); |
| 64 | 0 | progress.getContentPane().add(new JLabel("Criptografando"), |
| 65 | 0 | global.getLayout2()); |
| 66 | 0 | progress.pack(); |
| 67 | 0 | |
| 68 | 0 | |
| 69 | 0 | |
| 70 | 0 | |
| 71 | 0 | String senhaCriptografada = EncriptarSenha.encripta(senha); |
| 72 | 0 | |
| 73 | 0 | |
| 74 | 0 | progress.getContentPane().add(new JLabel("Senha Criptografada"), |
| 75 | 0 | global.getLayout2()); |
| 76 | 0 | progress.pack(); |
| 77 | 0 | if ((funcionario.getSenha() != null) |
| 78 | 0 | && (funcionario.getSenha() |
| 79 | 0 | .equals(senhaCriptografada))) { |
| 80 | 0 | progress.getContentPane().add( |
| 81 | 0 | new JLabel("Carregando projetos"), |
| 82 | 0 | global.getLayout2()); |
| 83 | 0 | progress.pack(); |
| 84 | 0 | projetos = dao.selectProjetos(funcionario); |
| 85 | 0 | |
| 86 | 0 | this.logado = true; |
| 87 | 0 | progress.getContentPane().add( |
| 88 | 0 | new JLabel("Usuario e Senha Verificados"), |
| 89 | 0 | global.getLayout2()); |
| 90 | 0 | |
| 91 | 0 | Global.setUsuario(funcionario); |
| 92 | 0 | |
| 93 | |
} |
| 94 | 0 | } catch (Exception e) { |
| 95 | 0 | e.printStackTrace(); |
| 96 | 0 | ControladorErro.trata(e, this); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
} |
| 100 | 0 | |
| 101 | 0 | progress.setVisible(false); |
| 102 | 0 | |
| 103 | 0 | if (isLogado()) { |
| 104 | 0 | Principal principal = new Principal(getProjetos()); |
| 105 | 0 | |
| 106 | 0 | Global.mostraFrame(principal, "Principal"); |
| 107 | 0 | } else { |
| 108 | 0 | JOptionPane.showMessageDialog(null, "Login ou Senha Inv�lidos"); |
| 109 | |
} |
| 110 | 0 | |
| 111 | 0 | return this.logado; |
| 112 | 0 | } catch (Exception e) { |
| 113 | 0 | e.printStackTrace(); |
| 114 | 0 | return false; |
| 115 | 0 | } |
| 116 | 0 | |
| 117 | |
} |
| 118 | 0 | |
| 119 | |
public List<Projeto> getProjetos() { |
| 120 | 0 | return projetos; |
| 121 | 0 | } |
| 122 | 0 | |
| 123 | 0 | public void setProjetos(ArrayList<Projeto> projetos) { |
| 124 | 0 | this.projetos = projetos; |
| 125 | 0 | } |
| 126 | 0 | |
| 127 | |
public String getLogin() { |
| 128 | 0 | return login; |
| 129 | 0 | } |
| 130 | 0 | |
| 131 | 0 | public void setLogin(String login) { |
| 132 | 0 | this.login = login; |
| 133 | 0 | } |
| 134 | |
|
| 135 | |
public String getSenha() { |
| 136 | 0 | return senha; |
| 137 | |
} |
| 138 | |
|
| 139 | |
public void setSenha(String senha) { |
| 140 | 0 | this.senha = senha; |
| 141 | 0 | } |
| 142 | |
|
| 143 | |
public boolean isLogado() { |
| 144 | 0 | return logado; |
| 145 | |
} |
| 146 | |
|
| 147 | |
public void setLogado(boolean logado) { |
| 148 | 0 | this.logado = logado; |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
} |