Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarefa php. #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions exemplo_alunos/code/db/banco.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ INSERT INTO `tb_curso` (`id`, `nome`, `descricao`, `carga_horaria`, `data_inicio
(1, 'Tec. Teste', 'Curso para teste do CursoDao', 200, '2000-01-30', '2000-03-30'),
(2, 'Tec. Info', 'Técnico em Informática (Teste 1)', 1000, '2011-01-01', '2012-01-01');

DROP TABLE IF EXISTS `tb_turma`;
CREATE TABLE `tb_turma` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(100) NOT NULL,
`id_curso` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `id_curso` (`id_curso`),
CONSTRAINT `tb_turma_ibfk_1` FOREIGN KEY (`id_curso`) REFERENCES `tb_curso` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `tb_turma` (`id`, `nome`, `id_curso`) VALUES
(1, 'Turma 2009', 1),
(2, 'Turma de 2010', 2),
(3, '2a', 2);


DROP TABLE IF EXISTS `tb_matricula`;
CREATE TABLE `tb_matricula` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -49,17 +65,15 @@ INSERT INTO `tb_matricula` (`id`, `id_aluno`, `id_turma`, `data_matricula`) VALU
(1, 3, 2, '2020-01-01'),
(2, 2, 1, '2023-05-01');

DROP TABLE IF EXISTS `tb_turma`;
CREATE TABLE `tb_turma` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(100) NOT NULL,
`id_curso` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `id_curso` (`id_curso`),
CONSTRAINT `tb_turma_ibfk_1` FOREIGN KEY (`id_curso`) REFERENCES `tb_curso` (`id`)

DROP TABLE IF EXISTS `tb_usuario`;
CREATE TABLE `tb_usuario` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`nome` varchar(15) NOT NULL,
`senha` varchar(8) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `tb_turma` (`id`, `nome`, `id_curso`) VALUES
(1, 'Turma 2009', 1),
(2, 'Turma de 2010', 2),
(3, '2a', 2);
INSERT INTO `tb_usuario` (`id`, `nome`, `senha`) VALUES
(1, 'duda', '123');

5 changes: 3 additions & 2 deletions exemplo_alunos/code/model/aluno_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
require_once '../db/conexao.php';
require_once 'aluno.php';

class AlunoDao implements IDao
class AlunoDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
3 changes: 2 additions & 1 deletion exemplo_alunos/code/model/curso_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class CursoDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
3 changes: 2 additions & 1 deletion exemplo_alunos/code/model/matricula_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class MatriculaDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
3 changes: 2 additions & 1 deletion exemplo_alunos/code/model/turma_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class TurmaDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
25 changes: 25 additions & 0 deletions exemplo_alunos/code/model/usuario.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class Usuario
{
private $id;
private $nome;
private $senha;

public function __construct($id, $nome, $senha)
{
$this->id = $id;
$this->nome = $nome;
$this->senha = $senha;
}

public function __get($atributo)
{
return $this->$atributo;
}

public function __set($atributo, $valor)
{
$this->$atributo = $valor;
}
}
29 changes: 29 additions & 0 deletions exemplo_alunos/code/model/usuario_dao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require_once '../db/conexao.php';
require_once 'usuario.php';

class UsuarioDao
{
private $conexao;

public function __construct()
{
$conexao = new Conexao();

$this->conexao = $conexao->conectar();
}

public function autenticar(Usuario $usuario)
{
$sql = "SELECT * FROM tb_usuario WHERE nome = :nome AND senha = :senha";
$stmt = $this->conexao->prepare($sql);
$stmt->bindValue(':nome', $usuario->nome);
$stmt->bindValue(':senha', $usuario->senha);
$stmt->execute();

$resultado = $stmt->fetch(PDO::PARAM_BOOL);
return $resultado;
}

}
25 changes: 9 additions & 16 deletions exemplo_alunos/code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@

<body>
<h1>Bem vindo</h1>
<form method="POST" action="trauma.php">
<h3>LOGINNN</h3>
Usuario:<br>
<input type="text" name="nome" id='nome' ><br>
Senha:<br>
<input type="password" name="senha" id='senha' ><br>

<h3>Controle de Alunos</h3>
<a href="cadastrar_aluno.html">Cadastro de aluno</a> <br>
<a href="listar_alunos.php">Listar alunos</a> <br><br>

<h3>Controle de Curso</h3>
<a href="cadastrar_curso.html">Cadastro de curso</a> <br>
<a href="listar_cursos.php">Listar cursos</a> <br><br>

<h3>Controle de Turma</h3>
<a href="cadastrar_turma.php">Cadastro de turma</a> <br>
<a href="listar_turmas.php">Listar turmas</a> <br><br>

<h3>Controle de Matrícula</h3>
<a href="cadastrar_matricula.php">Realizar matrícula</a> <br>
<a href="listar_matriculas.php">Listar matrículas</a> <br><br>
<input type="submit" value="entrar"><br>
</form>
<h3>Nao possui um login? <a href="indexNlogado.html">Clique aqui</a> <br></h3>
</body>

</html>
27 changes: 27 additions & 0 deletions exemplo_alunos/code/public/indexNlogado.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<h1>Ola</h1>

<h3>listagem de Alunos</h3>
<a href="listar_alunos.php">Listar alunos</a> <br><br>

<h3>listagem de Curso</h3>
<a href="listar_cursos.php">Listar cursos</a> <br><br>

<h3>listagem de Turma</h3>
<a href="listar_turmas.php">Listar turmas</a> <br><br>

<h3>Listagem de Matrícula</h3>
<a href="listar_matriculas.php">Listar matrículas</a> <br><br>
</body>

</html>
42 changes: 42 additions & 0 deletions exemplo_alunos/code/public/indexlogado.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
session_start();

if (!isset($_SESSION["logado"])){
header("Location: index.html");
}
?>

<h1>Ola, <?=$_SESSION["usuario"]?></h1>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>

<h3>Controle de Alunos</h3>
<a href="cadastrar_aluno.html">Cadastro de aluno</a> <br>
<a href="listar_alunos.php">Listar alunos</a> <br><br>

<h3>Controle de Curso</h3>
<a href="cadastrar_curso.html">Cadastro de curso</a> <br>
<a href="listar_cursos.php">Listar cursos</a> <br><br>

<h3>Controle de Turma</h3>
<a href="cadastrar_turma.php">Cadastro de turma</a> <br>
<a href="listar_turmas.php">Listar turmas</a> <br><br>

<h3>Controle de Matrícula</h3>
<a href="cadastrar_matricula.php">Realizar matrícula</a> <br>
<a href="listar_matriculas.php">Listar matrículas</a> <br><br>

<h2><a href="sair.php">Sair</a></h2>
</body>

</html>
6 changes: 6 additions & 0 deletions exemplo_alunos/code/public/sair.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
session_start();
session_destroy();

header("Location: index.html");
?>
24 changes: 24 additions & 0 deletions exemplo_alunos/code/public/trauma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

require_once '../model/usuario.php';
require_once '../model/usuario_dao.php';

$nome = $_POST['nome'];
$senha = $_POST['senha'];

$usuario = new Usuario(0, $nome, $senha);
$conexao = new Conexao();

$usuarioDao = new UsuarioDao($conexao);

$usuarioAutenticado = $usuarioDao->autenticar($usuario);

if($usuarioAutenticado){
session_start();
$_SESSION["logado"] = true;
$_SESSION["usuario"] = $nome;

header('Location: indexlogado.php');
} else {
header('Location: index.html');
}