Created
January 26, 2016 16:53
-
-
Save pedrorvidal/52be9d0be6634da471d0 to your computer and use it in GitHub Desktop.
adapter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function authenticate() { | |
| //Dados de usuário que são necessários | |
| $dadosUser['loginUser'] = $this->username; | |
| $dadosUser['grupo'] = 1; | |
| // $consult = $this->em2->getConnection()->executeQuery("SELECT TX_LOGIN_USUARIO, TX_NOME_USUARIO, TX_TELEFONE_USUARIO, TX_RAMAL_USUARIO, TX_EMAIL_USUARIO, TX_SENHA_USUARIO, TX_ESTADO_USUARIO, DT_INICIO_ESTADO_USUARIO, DT_MUDANCA_ESTADO_USUARIO, " | |
| // . "TX_USUARIO_BLOQUEADO, DT_ULTIMO_ACESSO, TX_USUARIO_CONECTADO, QT_TENTATIVA_CONEXAO, DT_EXPIRACAO_SENHA, TX_SIGLA_SETOR, TX_CLASSE_USUARIO, TX_CNPJ_EMPRESA " | |
| // . "FROM USUARIO " . "WHERE TX_LOGIN_USUARIO = '{$this->username}' AND TX_SENHA_USUARIO = '".sha1($this->password)."' "); | |
| // | |
| // analsl | |
| // die(sha1('123')); | |
| // print_r($consult->fetchAll()); | |
| // die('d'); | |
| // die('teste'); | |
| //conectar no banco | |
| //autenticar | |
| //retorno msg | |
| $consult = $this->em2->getConnection()->executeQuery(" select u.tx_usuario_bloqueado, | |
| u.tx_senha_usuario, u.tx_estado_usuario, u.tx_nome_usuario, | |
| u.tx_sigla_setor, u.tx_cnpj_empresa, | |
| e.tx_nome_empresa, s.tx_nome_setor, gu.tx_descricao_grupo_usuario | |
| from usuario u, setor s, empresa e, grupo_usuario gu | |
| where u.tx_cnpj_empresa = e.tx_cnpj_empresa | |
| and u.tx_cnpj_empresa = s.tx_cnpj_empresa | |
| and u.tx_sigla_setor = s.tx_sigla_setor | |
| and u.tx_login_usuario = '{$this->username}'; "); | |
| $result = $consult->fetchAll(); | |
| if (!empty($result)) { | |
| //fazer validação aqui | |
| $senha = $this->password; | |
| //fazer foreach pra pegar array de funções; | |
| foreach ($result as $value) : | |
| // echo "<div style='display:block'>"; | |
| // echo "<pre>"; | |
| // var_dump($value); | |
| // echo "</pre>"; | |
| // echo "</div>"; | |
| // echo "<hr>"; | |
| $funcoesUser[] = $value['tx_descricao_grupo_usuario']; | |
| $senhaUsuario = $value['tx_senha_usuario']; | |
| $dadosUser['nomeUser'] = $value['tx_nome_usuario']; | |
| ; | |
| endforeach; | |
| $funcoesPermitidas = array( | |
| "Administração do Site", | |
| "Coordenação CSU, Enfermeiros", | |
| "Engenheiros", | |
| "Médicos Examinadores", | |
| "Fonoaudiologia", | |
| "Gestores de Saúde", | |
| "Técnicos SST" | |
| ); | |
| $cont = 0; | |
| foreach ($funcoesUser as $value) : | |
| if (in_array($value, $funcoesPermitidas)) { | |
| $cont = 1; | |
| } | |
| endforeach; | |
| $base64 = base64_encode(sha1($senha, true)); | |
| if ($cont>0 && $senhaUsuario == $base64) { | |
| return new Result(Result::SUCCESS, $dadosUser, array('OK')); | |
| } else { | |
| return new Result(Result::FAILURE, $dadosUser, array('Falha')); | |
| } | |
| //Retorna a autenticação ok | |
| return new Result(Result::SUCCESS, $dadosUser, array('OK')); | |
| } else { | |
| return new Result(Result::FAILURE, $dadosUser, array('Falha')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment