/
login.php
115 lines (81 loc) · 2.98 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
header("Content-type: text/html; charset=utf-8");
include_once 'config.php';
// Variables
$msg = [];
$email = '';
$password = '';
if($_POST){
try{
$email = $_POST['email'] ? $_POST['email'] : null;
$password = $_POST['password'] ? $_POST['password'] : null;
if(!preg_match('/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+.([a-zA-Z]{2,4})$/', $email) || !isset($email)){
$msg['error'] = "Email inválido!";
}
if(!isset($password) || strlen($password) < 6){
$msg['error'] = "A senha deve conter ao menos 6 caracteres!";
}
if(!isset($msg['error'])){
$sql = new Sql();
$sql->startTransaction();
$employee = new Employee();
$employee->setEmail($email);
$employee->setPassword($password);
$employeeDao = new EmployeeDao();
$login = $employeeDao->login($employee);
if($login){
header('location: /aluguel');
}else{
$msg['error'] = 'Email/senha incorretos.';
}
$sql->commit();
}
}catch(PDOException $e){
$sql->rollback();
$msg['error'] = "Houve um erro inesperado, contate o desenvolvedor!";
$e->getTrace();
}
}
?>
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BW7 - Aluguel de carros</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
<!-- STYLES -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="./css/style.css">
<body>
<div class="login system-wrapper">
<div class="workspace">
<div class="container">
<h1 class="title">LOGIN</h1>
<div class="m-auto small-fields">
<?php
if($msg){
?>
<span class="my-alert <?= (empty($msg['error'])) ? 'alert-success' : 'alert-danger'; ?>"><?= (empty($msg['error'])) ? $msg['success'] : $msg['error']; ?></span>
<?php
}
?>
<form action="" method="post" name="login">
<label for="email">Email <em>(Obrigatório)</em></label>
<input id="email" type="email" name="email" value="<?= $email; ?>" placeholder="Email" required>
<label for="password">Senha <em>(Obrigatório)</em></label>
<input id="password" type="password" name="password" value="<?= $password; ?>" placeholder="Senha" required>
<button type="submit">LOGIN</button>
<a href="/aluguel/register.php">Criar uma conta</a>
</form>
</div>
</div>
</div>
<?php require_once './footer.php'; ?>