-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from douglas-88/dev
Login test
- Loading branch information
Showing
17 changed files
with
271 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
|
||
namespace App\Controller\Admin; | ||
use App\Model\User; | ||
use App\Model\Admin; | ||
use Core\Controller; | ||
use Core\Redirect; | ||
use Core\Validate; | ||
use Core\Login; | ||
|
||
class AdminController extends Controller | ||
{ | ||
public function index(){ | ||
session_destroy(); | ||
var_dump($_SESSION); | ||
$this->view("admin/login"); | ||
} | ||
|
||
public function store(){ | ||
$validate = new Validate(); | ||
$data = $validate->validate([ | ||
"email" => "required:email", | ||
"senha" => "required" | ||
]); | ||
|
||
if($validate->hasErros()){ | ||
foreach($data as $field => $value){ | ||
flash("post_".$field,$data[$field]); | ||
} | ||
back(); | ||
exit; | ||
} | ||
|
||
$login = new Login("admin"); | ||
$loginIn = $login->login($data,new Admin); | ||
|
||
if($loginIn){ | ||
Redirect::redirect("/painel"); | ||
exit; | ||
}else{ | ||
Redirect::redirect("/admin"); | ||
exit; | ||
} | ||
|
||
} | ||
|
||
public function destroy(){ | ||
|
||
$login = new Login("admin"); | ||
$login->logout(); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
|
||
namespace App\Controller\Admin; | ||
|
||
use Core\Controller; | ||
|
||
|
||
class PainelController extends Controller | ||
{ | ||
public function index(){ | ||
|
||
$this->view("admin/painel",["title" => "Painel Admin"]); | ||
} | ||
|
||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
|
||
namespace App\Model; | ||
|
||
use Core\Model; | ||
|
||
|
||
class Admin extends Model | ||
{ | ||
protected $table = "admin"; | ||
|
||
public function user(){ | ||
$id = $_SESSION["id_admin"]; | ||
$user = $this->select()->where("id",$id)->first(); | ||
|
||
return $user; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
|
||
class User extends Model | ||
{ | ||
protected $table = "user"; | ||
protected $table = "users"; | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
return [ | ||
"login" => [ | ||
"admin" => [ | ||
"loggedIn" => "admin_login", | ||
"redirect" => "/admin", | ||
"idLoggedIn" => "id_admin" | ||
], | ||
"user" => [ | ||
"loggedIn" => "user_login", | ||
"redirect" => "/", | ||
"idLoggedIn" => "id_user" | ||
] | ||
] | ||
]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
|
||
namespace Core; | ||
|
||
use Core\Model; | ||
use Core\Password; | ||
|
||
class Login | ||
{ | ||
private $type; | ||
|
||
public function __construct($type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public function login($data,Model $model){ | ||
|
||
$config = (object) Load::file("/config.php")["login"][$this->type]; | ||
$user = $model->select()->where("email",$data["email"])->first(); | ||
|
||
if(!$user){ | ||
return false; | ||
} | ||
if(Password::verify($data["senha"],$user->senha)){ | ||
$_SESSION[$config->loggedIn] = true; | ||
$_SESSION[$config->idLoggedIn] = $user->id; | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
public function logout(){ | ||
session_destroy(); | ||
|
||
Redirect::redirect("/admin"); | ||
exit; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
|
||
namespace Core; | ||
|
||
|
||
class Password | ||
{ | ||
/** | ||
* Retorna a Senha Encriptada | ||
* @param $password | ||
* @return string | ||
*/ | ||
public static function make($password):string{ | ||
|
||
return password_hash($password, PASSWORD_BCRYPT, ["cost" => 12]); | ||
} | ||
|
||
/** | ||
* Verifica a Senha Encriptada | ||
* @param $password | ||
* @return bool | ||
*/ | ||
public static function verify($password,$hash):bool{ | ||
|
||
return password_verify($password,$hash); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends 'master.html' %} | ||
|
||
{% block master %} | ||
<div class="col-6 text-center"> | ||
<form class="form-signin" action="/login" 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</h1> | ||
<label for="inputEmail" class="sr-only">Email</label> | ||
<input type="email" id="inputEmail" class="form-control" name="email" placeholder="Email" value="{{ sent('email') }}"required autofocus> | ||
{{ erros("email") }} | ||
<label for="inputPassword" class="sr-only">Senha</label> | ||
<input type="password" id="inputPassword" class="form-control" name="senha" placeholder="Senha" value="{{ sent('senha') }}"required> | ||
{{ erros("senha") }} | ||
<button class="btn btn-lg btn-primary btn-block" type="submit">ENTRAR</button> | ||
<p class="mt-5 mb-3 text-muted">© Douglas</p> | ||
</form> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.