-
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 #55 from mathias73/dev
PR dev into master #3
- Loading branch information
Showing
11 changed files
with
327 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Model\Twig; | ||
use App\Model\User; | ||
use App\Model\UserManager; | ||
|
||
class SigninController extends Twig | ||
{ | ||
public function show($filter = null) : void | ||
{ | ||
$this->twig('signin.html.twig',['erreur'=>''.$filter.'']); | ||
} | ||
|
||
public function signIn() : void | ||
{ | ||
$user = new User([ | ||
'pseudo' => $_POST['pseudo'], | ||
'password' => $_POST['password'] | ||
]); | ||
$userManager = new UserManager(); | ||
if (empty($_POST["password"]) || empty($_POST["pseudo"])){ | ||
$this->show('Veuillez remplir tout les champs'); | ||
} | ||
elseif (!$userManager->checkIfPseudoExist($user)){ | ||
$this->show('Pseudo incorrect'); | ||
} | ||
elseif (!$userManager->checkPasswordHash($user)){ | ||
$this->show('Mauvais mot de passe'); | ||
} | ||
else{ | ||
$userManager->connectUser($user); | ||
$home = new HomeController(); | ||
$home->show(); | ||
} | ||
} | ||
|
||
public function disconnect(){ | ||
$userManager = new UserManager(); | ||
$userManager->userDisconnect(); | ||
$home = new HomeController(); | ||
$home->show(); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace App\Model\Repository; | ||
|
||
use App\Model\DbManager; | ||
use App\Model\User; | ||
use App\Model\UserManager; | ||
|
||
class UserRepository extends DbManager | ||
{ | ||
public function __construct() | ||
{ | ||
$this->dbConnect(); | ||
} | ||
|
||
public function addUser(User $user): void | ||
{ | ||
$userManager = new UserManager(); | ||
if ($userManager->isNotEmpty($user) && $userManager->checkPasswordLength() && $userManager->checkPseudo($user) && $userManager->checkEmail($user)) { | ||
|
||
$addUser = $this->dbConnect()->prepare( | ||
'INSERT INTO User (firstname, lastname, email, pseudo, password, type, createdAt) | ||
VALUES (:firstname, :lastname, :email, :pseudo, :password, :type, :createdAt)' | ||
); | ||
|
||
$addUser->bindValue(':firstname', $user->getFirstname(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':lastname', $user->getLastname(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':email', $user->getEmail(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':pseudo', $user->getPseudo(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':password', $user->getPassword(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':type', $user->getType(), \PDO::PARAM_STR); | ||
$addUser->bindValue(':createdAt', $user->getCreatedAt(), \PDO::PARAM_STR); | ||
|
||
$addUser->execute(); | ||
} | ||
} | ||
|
||
public function getUserByPseudo($pseudo) | ||
{ | ||
$userPseudo = $this->dbConnect()->prepare("SELECT * FROM User WHERE pseudo = :pseudo"); | ||
$userPseudo->bindValue(':pseudo', $pseudo); | ||
$userPseudo->execute(); | ||
$userPseudo->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\Model\User'); | ||
return $userPseudo->fetch(); | ||
} | ||
|
||
public function getUserByEmail($email) | ||
{ | ||
$userEmail = $this->dbConnect()->prepare("SELECT * FROM User WHERE email = :email"); | ||
$userEmail->bindValue(':email', $email); | ||
$userEmail->execute(); | ||
$userEmail->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\Model\User'); | ||
return $userEmail->fetch(); | ||
} | ||
|
||
public function getUserById($id) | ||
{ | ||
$userId = $this->dbConnect()->prepare("SELECT * FROM User WHERE id = :id"); | ||
$userId->bindValue(':id', $id); | ||
$userId->execute(); | ||
$userId->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\Model\User'); | ||
return $userId->fetch(); | ||
} | ||
|
||
public function getPasswordHash($user) | ||
{ | ||
$userHash = $this->dbConnect()->prepare("SELECT password FROM User WHERE pseudo = :pseudo"); | ||
$userHash->bindValue(':pseudo', $user->getPseudo()); | ||
$userHash->execute(); | ||
$userHash->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\Model\User'); | ||
$rslt = $userHash->fetch(); | ||
return $rslt["password"] ?? null; | ||
} | ||
} |
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 App\Model; | ||
|
||
use Twig\Environment; | ||
use Twig\Loader\FilesystemLoader; | ||
|
||
class Twig | ||
{ | ||
public function twig(string $view, array $filter) : void | ||
{ | ||
$loader = new FilesystemLoader('src/View'); | ||
$twig = new Environment($loader, [ | ||
'cache' => false//'src/tmp', | ||
]); | ||
|
||
if(!isset($_SESSION)) | ||
{ | ||
session_start(); | ||
} | ||
$userManager = new UserManager(); | ||
$userManager->getRememberMe(); | ||
|
||
$twig->addGlobal('session', $_SESSION ?? $userManager); | ||
|
||
echo $twig->render($view, $filter); | ||
} | ||
} |
Oops, something went wrong.