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