Skip to content

Commit

Permalink
Cadastro funcionando e outros fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guaycuru committed Apr 14, 2017
1 parent efc6cce commit 5491fae
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ RewriteRule ^visoes/Sala\.php$ %{ENV:BASE}sala/ [R=302,L,QSA]
RewriteRule ^visoes/Sobre\.php$ %{ENV:BASE}sobre/ [R=302,L,QSA]
RewriteRule ^visoes/Termos\.php$ %{ENV:BASE}termos/ [R=302,L,QSA]
RewriteRule ^visoes/ValidaEmail\.php$ %{ENV:BASE}validar-email/ [R=302,L,QSA]
RewriteRule ^visoes/VisaoCadastro\.php$ %{ENV:BASE}cadastro/ [R=302,L,QSA]
RewriteRule ^visoes/VisaoLogin\.php$ %{ENV:BASE}login/ [R=302,L,QSA]
126 changes: 126 additions & 0 deletions ajax/cadastro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace GDE;

define('NO_LOGIN_CHECK', true);
define('JSON', true);
require_once('../common/common.inc.php');

if(isset($_POST['alterar'])) {
$_SESSION['trocar_senha'] = true;
exit();
}

if(isset($_POST['enviar'])) {
list($resultado, $identificador, $tipo) = DAC::Validar_Token($_POST['token']);
$campo = null;
if($tipo == 'A')
$campo = 'ra';
elseif($tipo == 'D')
$campo = 'matricula';
else
Base::Error_JSON("Tipo inv&aacute;lido!");
if($resultado === false)
Base::Error_JSON("TOKEN inv&aacute;lido!");
elseif($_POST['senha'] != $_POST['conf_senha'])
Base::Error_JSON("As senhas n&atilde;o conferem!");
elseif(isset($_POST['trocar_senha'])) {
$Usuario = Usuario::Por_Unique($identificador, $campo);
if($Usuario === null)
Base::Error_JSON("Usu&aacute;rio n&atilde;o encontrado!");
$Usuario->setSenha($_POST['senha']);
unset($_SESSION['trocar_senha']);
if($Usuario->Save(true) !== false)
Base::OK_JSON($_POST['token']);
else
Base::Error_JSON("Um erro ocorreu. Por favor, tente novamente mais tarde.");
} else {
if(Usuario::Por_Unique($identificador, $campo, true) !== null)
Base::OK_JSON($_POST['token']);
else {
$Ja_tem = Usuario::Por_Unique($identificador, $campo);
if($Ja_tem === null)
$Usuario = new Usuario();
else
$Usuario = $Ja_tem;
if($Ja_tem === null)
$Usuario->setLogin($_POST['login']);
if(strlen($_POST['senha']) < 3)
Base::Error_JSON("A senha precisa ter no m&iacute;nimo 3 caracteres.");
if((empty($_POST['email'])) || (Util::Validar_Email($_POST['email']) === false))
Base::Error_JSON("Favor informar um email v&aacute;lido.");
elseif(Usuario::Por_Unique($_POST['email'], 'email') !== null)
Base::Error_JSON("J&aacute; existe um usu&aacute;rio cadastrado com o email informado.");
$Usuario->setSenha($_POST['senha']);
$Usuario->setEmail($_POST['email']);
$Usuario->setNome($_POST['nome']);
$Usuario->setSobrenome($_POST['sobrenome']);
if(!empty($_POST['ingresso']))
$Usuario->setIngresso(intval($_POST['ingresso']));
if(($tipo == 'A') && (!empty($_POST['curso']))) {
$Curso = Curso::Por_Numero($_POST['curso']);
if($Curso === null)
Base::Error_JSON('Curso de gradua&ccedil;&atilde;o n&atilde;o encontrado!');
$Usuario->setCurso($Curso);
if(!empty($_POST['catalogo']))
$Usuario->setCatalogo(intval($_POST['catalogo']));
if(!empty($_POST['modalidade']))
$Modalidade = Modalidade::Por_Curso_Sigla_Catalogo($Curso->getNumero(false), $_POST['modalidade'], array('G', 'T'), $_POST['catalogo']);
else
$Modalidade = null;
$Usuario->setModalidade($Modalidade);
}
if($Ja_tem === null)
$Usuario->setData_Cadastro();
$Usuario->setAtivo(true);
if($tipo == 'A') {
$Aluno = Aluno::Por_RA($identificador);
if($Aluno === null) {
$Aluno = new Aluno();
$Aluno->setRA($identificador);
$Aluno->setNome($Usuario->getNome_Completo(false));
$Aluno->setNivel((!empty($_POST['nivel'])) ? $_POST['nivel'][0] : null);
$Aluno->setCurso($Usuario->getCurso(false));
if($Usuario->getModalidade(false) !== null)
$Aluno->setModalidade($Usuario->getModalidade(true)->getSigla(false));
if(!empty($_POST['curso_pos'])) {
$Curso_Pos = Curso::Por_Numero($_POST['curso_pos'], Curso::NIVEIS_POS);
if($Curso_Pos === null)
Base::Error_JSON('Curso de p&oacute;s-gradua&ccedil;&atilde;o n&atilde;o encontrado!');
$Aluno->setCurso_Pos($Curso_Pos);
$Aluno->setNivel_Pos((!empty($_POST['nivel_pos'])) ? $_POST['nivel_pos'][0] : null);
$Aluno->setModalidade_Pos(($_POST['modalidade_pos'] == "") ? null : strtoupper(substr($_POST['modalidade_pos'], 0, 2)));
}
$Aluno->Save(false);
}
$Usuario->setAluno($Aluno);
} elseif($tipo == 'D') {
$Professor = Professor::Por_Matricula($identificador);
if($Professor === null) {
if(!empty($_POST['id_professor'])) {
$Professor = Professor::Load($_POST['id_professor']);
$Professor->setMatricula($identificador);
} else {
$ST = Professor::Nome_Unico($_POST['professor']);
if($ST !== false) {
$Professor = $ST;
$Professor->setMatricula($identificador);
} else {
$Professor = new Professor();
$Professor->setMatricula($identificador);
$Professor->setNome($_POST['professor']);
}
}
$Professor->Save(false);
}
$Usuario->setProfessor($Professor);
}
$Usuario->Enviar_Email_Validar();
if($Usuario->Save(true) !== false)
Base::OK_JSON($_POST['token']);
else
Base::Error_JSON("Um erro ocorreu. Por favor, tente novamente mais tarde.");
//echo "$.guaycuru.confirmacao(\"Seu cadastro foi efetuado com sucesso!<br />Agora voc&ecirc; pode usar o GDE!\", \"../visoes/VisaoLogin.php?token=".$_POST['token']."\");";
}
}
}
7 changes: 6 additions & 1 deletion ajax/editar.php → ajax/editar-perfil.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
if(($_POST['senha'] != null) && ($_POST['senha'] != $_POST['conf_senha'])) {
Base::Error_JSON('As senhas n&atilde;o conferem!');
}
if((empty($_POST['email'])) || (Util::Validar_Email($_POST['email']) === false))
Base::Error_JSON("Favor informar um email v&aacute;lido.");
if($_Usuario->getEmail() != $_POST['email'])
$_Usuario->setEmail_Validado(false);
$_Usuario->setEmail($_POST['email']);
if($_POST['senha'] != null)
if(!empty($_POST['senha'])) {
if(strlen($_POST['senha']) < 3)
Base::Error_JSON("A senha precisa ter no m&iacute;nimo 3 caracteres.");
$_Usuario->setSenha($_POST['senha']);
}
$_Usuario->setNome($_POST['nome']);
$_Usuario->setSobrenome($_POST['sobrenome']);
$Curso = Curso::Por_Numero($_POST['curso']);
Expand Down
File renamed without changes.
12 changes: 9 additions & 3 deletions ajax/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
else
$_Usuario = Usuario::Verificar_Login($_POST['login'], $_POST['senha'], false, $erro);

if($_Usuario->getID() != null) { // Login OK
if((is_object($_Usuario)) && ($_Usuario->getID() != null)) { // Login OK
Base::OK_JSON();
} else { // Login falhou
$extra = array('destino' => '');
switch($erro) {
case Usuario::ERRO_LOGIN_NAO_ENCONTRADO:
$erro = 'Login não encontrado.';
if(!empty($_POST['token'])) {
$erro = 'Login não encontrado. Por favor, efetue seu cadastro.';
$extra['destino'] = CONFIG_URL . 'cadastro/?token=' . urlencode($_POST['token']);
} else {
$erro = 'Login não encontrado.';
}
break;
case Usuario::ERRO_LOGIN_SENHA_INCORRETA:
$erro = 'Login ou senha incorretos.';
Expand All @@ -40,5 +46,5 @@
$erro = 'Erro desconhecido.';
break;
}
Base::Error_JSON($erro);
Base::Error_JSON($erro, 200, $extra);
}
10 changes: 10 additions & 0 deletions classes/GDE/Aluno.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class Aluno extends Base {
/**
* @var string
*
* Nao podemos utilizar uma Relation com Modalidade pois Aluno nao tem Catalogo
*
* @ORM\Column(type="string", length=16, nullable=true)
*/
protected $modalidade_pos;
Expand Down Expand Up @@ -158,6 +160,14 @@ public static function Listar_Niveis_Pos() {
return self::$_niveis_pos;
}

/**
* @param $ra
* @return Aluno|null|false
*/
public static function Por_RA($ra) {
return self::FindOneBy(array('ra' => $ra));
}

/**
* Consultar
*
Expand Down
2 changes: 1 addition & 1 deletion classes/GDE/Base.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static function FindBy($params = array(), array $order = null, $limit = n
* Searches the DB for only one object
*
* @param array $params Search parameters
* @return mixed Object found, null if not found or false on query error
* @return object|null|false Object found, null if not found or false on query error
*/
public static function FindOneBy($params) {
return self::_EM()->getRepository(get_called_class())->findOneBy($params);
Expand Down
10 changes: 8 additions & 2 deletions classes/GDE/Curso.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@ class Curso extends Base {
*/
protected $nome;

const NIVEIS_GRAD = array('G', 'T');
const NIVEIS_POS = array('M', 'D');

/**
* Listar
*
* @param array $niveis
* @param bool $sem_especial
* @return ArrayCollection
*/
public static function Listar($niveis = array()) {
public static function Listar($niveis = array(), $sem_especial = false) {
$dql = 'SELECT C FROM GDE\\Curso C ';
if(count($niveis) > 0)
$dql .= 'WHERE C.nivel IN (?1) ';
if($sem_especial)
$dql .= 'AND C.numero != 99 ';
$dql .= 'ORDER BY C.nome ASC';
$query = self::_EM()->createQuery($dql);
if(count($niveis) > 0)
Expand All @@ -66,7 +72,7 @@ public static function Listar($niveis = array()) {
* @param array $niveis
* @return self|null
*/
public static function Por_Numero($numero, $niveis = array('G', 'T')) {
public static function Por_Numero($numero, $niveis = self::NIVEIS_GRAD) {
$dql = 'SELECT C FROM GDE\\Curso C WHERE C.numero = ?1';
if(count($niveis) > 0)
$dql .= ' AND C.nivel IN (?2)';
Expand Down
46 changes: 46 additions & 0 deletions classes/GDE/Professor.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ class Professor extends Base {
public static $ordens_nome = array('Relev&acirc;ncia', 'Nome');
public static $ordens_inte = array('rank', 'P.nome');

/**
* @param $matricula
* @return Professor|null|false
*/
public static function Por_Matricula($matricula) {
return self::FindOneBy(array('matricula' => $matricula));
}

/**
* @param $nome
* @return Professor|false
*/
public static function Nome_Unico($nome) {
$Professores = self::Por_Nome($nome);
if(count($Professores) != 1)
return false;
return $Professores->first();
}

/**
* @param null|string $periodo
* @param bool $formatado
Expand Down Expand Up @@ -130,6 +149,33 @@ public function Monta_Horario($periodo = null) {
return $Lista;
}

/**
* Por_Nome
*
* @param $nome
* @param null $ordem
* @param null $total
* @param int $limit
* @param int $start
* @return ArrayCollection|Professor[]
*/
public static function Por_Nome($nome, $ordem = null, &$total = null, $limit = -1, $start = -1) {
$param = array(1 => "%".str_replace(' ', '%', $nome)."%");
if($total !== null) {
$dqlt = "SELECT COUNT(DISTINCT P.id_professor) FROM ".get_class()." AS P WHERE P.nome LIKE ?1";
$total = self::_EM()->createQuery($dqlt)->setParameters($param)->getSingleScalarResult();
}
$dql = "SELECT DISTINCT P FROM ".get_class()." AS P WHERE P.nome LIKE ?1";
if($ordem != null)
$dql .= " ORDER BY ".$ordem;
$query = self::_EM()->createQuery($dql)->setParameters($param);
if($limit > 0)
$query->setMaxResults($limit);
if($start > -1)
$query->setFirstResult($start);
return $query->getResult();
}

/**
* @param $q
* @param null $ordem
Expand Down
Loading

0 comments on commit 5491fae

Please sign in to comment.