login.php
2.89 KB
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
<?php
class Login extends Controller{
function __construct(){
parent::__construct();
}
function render(){
session_start();
if(isset($_SESSION['id_persona'])){
header("Location: ".constant('URL')."home");
}else{
$this->view->render('login/index');
}
}
function viewHome(){
header("Refresh: 0; URL= ".constant('URL')."home");
}
function iniciar(){
$usuario=$_POST["usuario"];
$clave=$_POST["clave"];
//////////////////////////////////////////////////////
if($this->model->getStatus([
'usuario'=> $usuario,
'clave' => $clave,
'estatus' => 'Inactivo'
])){
$mensaje='<div class="alert alert-danger background-danger">
<strong>Ha Ocurrido un Error</strong> Este Usuario está Inactivo. Debe Ingresar con un Usuario Activo en el Sistema.
</div>';
$this->view->mensaje=$mensaje;
$this->render();
exit();
}
if($this->model->getLogin([
'usuario'=> $usuario,
'clave' => $clave,
])){
$this->viewHome();
} else{
$mensaje='<div class="alert alert-danger background-danger">
<strong>Ha Ocurrido un Error</strong> Correo o Clave Incorrecta, Por favor Vuelve a Intentarlo.
</div>';
}
$this->view->mensaje=$mensaje;
$this->render();
}
function logout(){
session_start();
// Destruir todas las variables de sesión.
$_SESSION = array(
$_SESSION["id_persona"],
$_SESSION['correo'],
$_SESSION['primer_nombre'],
$_SESSION['primer_apellido'],
$_SESSION['perfil'],
$_SESSION['usuario'],
$_SESSION['id_perfil']
);
//var_dump($_SESSION);
// Si se desea destruir la sesión completamente, borre también la cookie de sesión.
// Nota: ¡Esto destruirá la sesión, y no la información de la sesión!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finalmente, destruir la sesión.
session_destroy();
session_unset();
if(!headers_sent()) {
echo '<script>
alert("¡Hasta Pronto!");
location.href="'.constant('URL').'main";
</script>';
//header("Location: ".constant('URL')."main");
}
}
}
?>