From 6b9657ac53c353f10f60c592cd63eaa96e55d4ab Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sat, 11 Nov 2023 14:13:20 +0100 Subject: [PATCH] =?UTF-8?q?impl=C3=A9mentation=20des=20actions=20de=20la?= =?UTF-8?q?=20page=20my=20account=20(show=20+=20modify=20password=20+=20mo?= =?UTF-8?q?dify=20nickname)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/controller/FrontController.php | 3 + Project/php/controller/StudentController.php | 72 ++++++++++++++++---- Project/php/model/MdlStudent.php | 15 +++- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 6b6e793..066fb1a 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -23,6 +23,9 @@ class FrontController ); private array $studentActions = array( + 'showAccountInfos', + 'modifyNickname', + 'modifyPassword' ); public function __construct() diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index d37169b..fc6dfe7 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -21,6 +21,17 @@ class StudentController $this->getByName($_REQUEST['nom']); break; + case 'showAccountInfos': + $this->showAccountInfos(); + break; + + case 'modifyNickname': + $this->modifyNickname(); + break; + + case 'modifyPassword': + $this->modifyPassword(); + break; case null: echo $twig->render('home.html'); @@ -38,14 +49,14 @@ class StudentController } } - public function affAllVocab(): void - { - global $twig; - $mdl = new MdlStudent(); - $student = $mdl->getAll(); - echo $twig->render('usersView.html', ['users' => $student]); + public function affAllVocab(): void + { + global $twig; + $mdl = new MdlStudent(); + $student = $mdl->getAll(); + echo $twig->render('usersView.html', ['users' => $student]); - } + } public function affAllStudent(): void { @@ -56,15 +67,46 @@ class StudentController } - public function getByName($name): void - { - global $twig; - $mdl = new MdlStudent(); - $vocab = $mdl->getVocabByName($name); - echo $twig->render('usersView.html', ['users' => $vocab]); - } + public function getByName($name): void + { + global $twig; + $mdl = new MdlStudent(); + $vocab = $mdl->getVocabByName($name); + echo $twig->render('usersView.html', ['users' => $vocab]); + } + + public function showAccountInfos(): void { + global $twig; + $userID = $_GET['user']; + $mdl = new MdlStudent(); + $user = $mdl->getUser($userID); + echo $twig->render('myAccountView.html', ['user' => $user]); + } + public function modifyNickname(): void { + global $twig; + $userID = $_GET['user']; + $newNickname = $_GET['newNickname']; + $mdl = new MdlStudent(); + $mdl->modifyNickname($userID, $newNickname); + $_GET['user'] = $userID; + $this->showAccountInfos(); + } + public function modifyPassword(): void { + global $twig; + $userID = $_GET['user']; + $currentPassword = $_GET['currentPassword']; + $newPassword = $_GET['newPassword']; + $confirmNewPassword = $_GET['confirmNewPassword']; + $mdl = new MdlStudent(); + $user = $mdl->getUser($userID); - } + if ($user->getPassword() == $currentPassword && $newPassword == $confirmNewPassword) + $mdl->ModifyPassword($userID, $newPassword); + $_GET['user'] = $userID; + $_REQUEST['action'] = 'showAccountInfos'; + $this->showAccountInfos(); + } +} \ No newline at end of file diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php index 9aadf85..6da2afe 100755 --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -45,10 +45,19 @@ class MdlStudent extends AbsModel return $res; } + public function getUser(int $id): User{ + $gtw = new UserGateway(); + return $gtw->findById($id); + } + public function modifyNickname(int $id, string $newNickname): void{ + $gtw = new UserGateway(); + $gtw->modifyNickname($id, $newNickname); + } - - - + public function ModifyPassword(int $id, string $newPassword): void { + $gtw = new UserGateway(); + $gtw->modifyPassword($id, $newPassword); + } }