Created
July 29, 2019 21:17
-
-
Save parzibyte/b8d44f75cff502ea4b7b5d7dfd4682a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Parzibyte\Controladores; | |
use Parzibyte\Modelos\ModeloUsuarios; | |
use Parzibyte\Redirect; | |
use Parzibyte\Servicios\SesionService; | |
use Parzibyte\Validator; | |
class ControladorLogin | |
{ | |
public static function index() | |
{ | |
if (SesionService::leer("idUsuario")) { | |
Redirect::to("/usuarios")->do(); | |
} | |
return view("login"); | |
} | |
public static function login() | |
{ | |
Validator::validateOrRedirect($_POST, | |
[ | |
"required" => ["correo", "palabraSecreta"], | |
"email" => "correo", | |
], | |
"/login"); | |
$correo = $_POST["correo"]; | |
$palabraSecreta = $_POST["palabraSecreta"]; | |
$respuesta = ModeloUsuarios::login($correo, $palabraSecreta); | |
if ($respuesta) { | |
Redirect::to("/usuarios")->do(); | |
} else { | |
Redirect::to("/login")->with([ | |
"mensaje" => "Datos incorrectos", | |
"tipo" => "warning", | |
]) | |
->do(); | |
} | |
} | |
public static function logout() | |
{ | |
SesionService::destruir(); | |
Redirect::to("/login")->do(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment