validation myaccountview et ses actions

php
Anthony RICHARD 1 year ago
parent 967aabb3e4
commit 093ccefa98

@ -107,7 +107,7 @@ class AdminController
public function removeUser(): void { public function removeUser(): void {
try { try {
$id = Validation::filter_int($_GET['id']); $id = Validation::filter_int($_GET['id'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeUser($id); $model->removeUser($id);
$this->showAllUsers(); $this->showAllUsers();
@ -142,7 +142,7 @@ class AdminController
public function removeUserFromGroup(): void { public function removeUserFromGroup(): void {
try { try {
$id = Validation::filter_int($_GET['id']); $id = Validation::filter_int($_GET['id'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeUserFromGroup($id); $model->removeUserFromGroup($id);
$this->showGroupDetails(); $this->showGroupDetails();
@ -154,7 +154,7 @@ class AdminController
public function removeGroup(): void { public function removeGroup(): void {
try { try {
$selectedGroup = Validation::filter_int($_GET['selectedGroup']); $selectedGroup = Validation::filter_int($_GET['selectedGroup'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeGroup($selectedGroup); $model->removeGroup($selectedGroup);
$this->showAllGroups(); $this->showAllGroups();
@ -166,9 +166,9 @@ class AdminController
public function addGroup(): void { public function addGroup(): void {
try { try {
$num = Validation::filter_int($_GET['num']); $num = Validation::filter_int($_GET['num'] ?? null);
$year = Validation::filter_int($_GET['year']); $year = Validation::filter_int($_GET['year'] ?? null);
$sector = Validation::filter_str_simple($_GET['sector']); $sector = Validation::filter_str_simple($_GET['sector'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$groupID = $model->addGroup($num, $year, $sector); $groupID = $model->addGroup($num, $year, $sector);
@ -182,8 +182,8 @@ class AdminController
public function addUserToGroup(): void { public function addUserToGroup(): void {
try { try {
$user = Validation::filter_int($_GET['userID']); $user = Validation::filter_int($_GET['userID'] ?? null);
$group = Validation::filter_int($_GET['groupID']); $group = Validation::filter_int($_GET['groupID'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->addUserToGroup($user, $group); $model->addUserToGroup($user, $group);
$_GET['selectedGroup'] = $group; $_GET['selectedGroup'] = $group;

@ -1,6 +1,7 @@
<?php <?php
namespace controller; namespace controller;
use config\Validation;
use model\MdlStudent; use model\MdlStudent;
use Exception; use Exception;
@ -76,37 +77,50 @@ class StudentController
} }
public function showAccountInfos(): void { public function showAccountInfos(): void {
global $twig; try {
$userID = $_GET['user']; global $twig;
$mdl = new MdlStudent(); $userID = Validation::filter_int($_GET['user'] ?? null);
$user = $mdl->getUser($userID); $mdl = new MdlStudent();
echo $twig->render('myAccountView.html', ['user' => $user]); $user = $mdl->getUser($userID);
echo $twig->render('myAccountView.html', ['user' => $user]);
}
catch (Exception $e){
throw new Exception("invalid user ID");
}
} }
public function modifyNickname(): void { public function modifyNickname(): void {
global $twig; try {
$userID = $_GET['user']; $userID = Validation::filter_int($_GET['user']);
$newNickname = $_GET['newNickname']; $newNickname = Validation::filter_str_nospecialchar($_GET['newNickname'] ?? null);
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$mdl->modifyNickname($userID, $newNickname); $mdl->modifyNickname($userID, $newNickname);
$_GET['user'] = $userID; $_GET['user'] = $userID;
$this->showAccountInfos(); $this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
} }
public function modifyPassword(): void { public function modifyPassword(): void {
global $twig; try {
$userID = $_GET['user']; $userID = $_GET['user'];
$currentPassword = $_GET['currentPassword']; $currentPassword = Validation::val_password($_GET['currentPassword'] ?? null);
$newPassword = $_GET['newPassword']; $newPassword = Validation::val_password($_GET['newPassword'] ?? null);
$confirmNewPassword = $_GET['confirmNewPassword']; $confirmNewPassword = Validation::val_password($_GET['confirmNewPassword'] ?? null);
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$user = $mdl->getUser($userID); $user = $mdl->getUser($userID);
if ($user->getPassword() == $currentPassword && $newPassword == $confirmNewPassword) if ($user->getPassword() != $currentPassword || $newPassword != $confirmNewPassword)
$mdl->ModifyPassword($userID, $newPassword); throw new Exception("");
$_GET['user'] = $userID; $mdl->ModifyPassword($userID, $newPassword);
$_REQUEST['action'] = 'showAccountInfos'; $_GET['user'] = $userID;
$this->showAccountInfos(); $this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
} }
} }

@ -28,7 +28,7 @@
<h1>My account</h1> <h1>My account</h1>
{% if user is defined %} {% if user is defined %}
<table> <table>
<tr><td>Image : </td><td>{{user.image}}</td></tr> //modifier todo <tr><td>Image : </td><td>{{user.image}}</td></tr>
<tr><td>ID : </td><td>{{user.id}}</td></tr> <tr><td>ID : </td><td>{{user.id}}</td></tr>
<tr><td>Nickname : </td><td>{{user.nickname}}</td> <tr><td>Nickname : </td><td>{{user.nickname}}</td>
<td> <td>

Loading…
Cancel
Save