Skip to content

Commit

Permalink
Adição de sistema de login.
Browse files Browse the repository at this point in the history
  • Loading branch information
JGSMoreira committed Sep 10, 2018
1 parent 35b8bc6 commit 1001059
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 64 deletions.
44 changes: 44 additions & 0 deletions css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
html,
body {
height: 100%;
}

body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}

.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.form-signin .checkbox {
font-weight: 400;
}
.form-signin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
2 changes: 1 addition & 1 deletion database/connection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//Informações do Banco de Dados
$HOST = "localhost";
$HOST = "localhost:3306";
$USER = "root";
$PASSWORD = "root";
$DATABASE = "school_life";
Expand Down
2 changes: 1 addition & 1 deletion database/delete_professor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
$ALTERAR->bindParam(':id', $id);

$RESULT = $ALTERAR->execute();
header('location:../listar_professor.php');
header('location:../sistema/listar_professor.php');
}
?>
8 changes: 5 additions & 3 deletions database/insert_professor.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
include 'connection.php';

session_start();
//Variáveis recebidas
$nome = $_POST['nome'];
$email = $_POST['email'];
$iduser = $_SESSION['iduser'];

//Insert no Banco de Dados
if (empty($nome) || empty($email)){
echo '<div class="alert alert-danger" role="alert">Os campos não podem ficar vazios.</div>';
}
else{
$SQL = "INSERT INTO professor(nome, email) VALUES(:nome, :email)";
$SQL = "INSERT INTO professor(nome, email, idUserFK) VALUES(:nome, :email, :iduser)";
$INSERIR = $conn->prepare($SQL);
$INSERIR->bindParam(':nome', $nome);
$INSERIR->bindParam(':email', $email);
$INSERIR->bindParam(':iduser', $iduser);
$RESULTADO = $INSERIR->execute();

if (! $RESULTADO){
Expand All @@ -23,7 +25,7 @@
}
else{
echo '<div class="alert alert-primary" role="alert">Pessoa salva com sucesso!</div>';
header('location:../listar_professor.php');
header('location: ../sistema/listar_professor.php');
}
}

Expand Down
5 changes: 2 additions & 3 deletions database/select_professor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
include 'connection.php';

//Select no Banco de Dados
$SQL = "SELECT * FROM professor";
$SQL = 'SELECT * FROM professor WHERE idUserFK = '.$_SESSION['iduser'];
$RESULT = $conn->query($SQL);

//Exibindo os resultados
$ROWS = $RESULT->fetchAll(PDO::FETCH_OBJ);
foreach($ROWS as $VALUE){
echo '<tr>';
echo '<td>'.$VALUE->idProfessor.'</td>';
echo '<td>'.$VALUE->nome.'</td>';
echo '<td>'.$VALUE->email.'</td>';
echo '<td><center><a href="editar_professor.php?id='.$VALUE->idProfessor.'"><img src="../open-iconic/svg/pencil.svg" height="15px"></a>';
echo '&nbsp&nbsp&nbsp<a href="database/delete_professor.php?id='.$VALUE->idProfessor.'"><img src="../open-iconic/svg/trash.svg" height="15px"></a></center></td>';
echo '&nbsp&nbsp&nbsp<a href="../database/delete_professor.php?id='.$VALUE->idProfessor.'"><img src="../open-iconic/svg/trash.svg" height="15px"></a></center></td>';
echo '</tr>';
}

Expand Down
24 changes: 2 additions & 22 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,9 @@
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="index.php">Início <span class="sr-only">(atual)</span></a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Cadastrar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="cadastrar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Listar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="listar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
</div>
</li>
</ul>
</div>
</nav>
Expand All @@ -52,7 +32,7 @@
<br>
<h1 class="display-3">Bem-vindo ao School Life!</h1>
<p>Esta é a versão web do gerenciador de atividades com o mesmo nome.</p>
<p><a class="btn btn-light btn-lg" href="#" role="button">Ver atividades</a></p>
<p><a class="btn btn-light btn-lg" href="logar.php" role="button">Fazer login</a></p>
</div>
</div>

Expand Down
31 changes: 31 additions & 0 deletions logar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>School Life - Fazer login</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/login.css">
</head>

<body class="text-center">
<form class="form-signin" action="login.php" method="post">
<img class="mb-4" src="../../assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Login - School Life</h1>
<label for="user" class="sr-only">Usuário</label>
<input type="texto" name="user" class="form-control" placeholder="Usuário" required autofocus>
<label for="senha" class="sr-only">Senha</label>
<input type="password" name="senha" class="form-control" placeholder="Senha" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Logar</button>
<br>
<?php
if (isset($_GET['erro'])){
echo '<div class="alert alert-danger" role="alert">';
echo $_GET['erro'];
echo '</div>';
}
?>
</form>
</body>
</html>
30 changes: 30 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
session_start();

if (empty($_POST['user']) || empty($_POST['senha'])){
header('location: logar.php?erro=Os campos não podem ficar vazios.');
}
else{
$usuario = $_POST['user'];
$senha = $_POST['senha'];

include 'database/connection.php';
$SQL = 'SELECT * FROM usuario WHERE nickUsuario = :nick and senhaUsuario = :senha';
$RESULT = $conn->prepare($SQL);
$RESULT->bindParam(':nick', $usuario);
$RESULT->bindParam(':senha', $senha);
$RESULT->execute();
$ROWS = $RESULT->fetch(PDO::FETCH_OBJ);

if (($usuario == $ROWS->nickUsuario) && ($senha == $ROWS->senhaUsuario)){
$_SESSION['logado'] = true;
$_SESSION['nome'] = $ROWS->nomeUsuario;
$_SESSION['iduser'] = $ROWS->idUsuario;

header('location: sistema/admin.php');
}
else{
header('location: logar.php?erro=Usuário ou senha inválidos!');
}
}
?>
9 changes: 9 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
session_start();

if ($_SESSION['logado']){
session_unset();
}

header('location: index.php');
?>
83 changes: 83 additions & 0 deletions sistema/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
session_start();
$logado = false;
$mensagem = 'Você não está logado.';

if (isset($_SESSION['logado']) && $_SESSION['logado']){
$logado = true;
$mensagem = 'Bem-vindo, '.$_SESSION['nome'].'.';
}
?>

<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>School Life - Painel</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">
</head>

<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="index.php">School Life</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="../index.php">Início</a>
</li>
<li class="nav-item">
<a class="nav-link current" href="admin.php">Painel</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Cadastrar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="cadastrar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Listar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="listar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Sair</a>
</li>
</ul>
</form>
</div>
</nav>

<main role="main">

<div class="jumbotron jumbotron-fluid" id="elefantebot">
<div class="container">
<br>
<h1 class="display-3"><?= $mensagem ?></h1>
</div>
</div>

</main>

<footer class="container">
<p>School Life | Continuação do projeto de 2017.</p>
</footer>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>function voltar() {window.history.back();}</script>
</body>
</html>
15 changes: 12 additions & 3 deletions cadastrar_professor.php → sistema/cadastrar_professor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php
$titulo = "School Life";

session_start();
$logado = false;
$mensagem = 'Você não está logado.';

if (isset($_SESSION['logado']) && $_SESSION['logado']){
$logado = true;
$mensagem = 'Bem-vindo, '.$_SESSION['nome'].'.';
}
?>

<!doctype html>
Expand All @@ -22,7 +31,7 @@
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Início</a>
<a class="nav-link" href="../index.php">Início</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Cadastrar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
Expand Down Expand Up @@ -57,7 +66,7 @@
<div class="container">
<div class="row">
<div class="col-md">
<form class="" action="database/insert_professor.php" method="post">
<form class="" action="../database/insert_professor.php" method="post">
<div class="form-group">
<label for="nome" class="texto">Nome</label>
<input type="text" class="form-control" name="nome" value="" placeholder="Digite o nome do Professor">
Expand All @@ -83,7 +92,7 @@
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<script>function voltar() {window.history.back();}</script>
</body>
</html>
8 changes: 4 additions & 4 deletions editar_professor.php → sistema/editar_professor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$titulo = "School Life";
include 'database/selectupdate_professor.php';
include '../database/selectupdate_professor.php';
?>

<!doctype html>
Expand All @@ -23,11 +23,11 @@
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Início</a>
<a class="nav-link" href="../index.php">Início</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Cadastrar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="cadastrar_professor.php">Professor</a>
<a class="dropdown-item" href="../cadastrar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
Expand All @@ -36,7 +36,7 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Listar</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="listar_professor.php">Professor</a>
<a class="dropdown-item" href="../listar_professor.php">Professor</a>
<a class="dropdown-item" href="#">Matéria</a>
<a class="dropdown-item" href="#">Tipo de Atividade</a>
<a class="dropdown-item" href="#">Atividade</a>
Expand Down
Loading

0 comments on commit 1001059

Please sign in to comment.