fix myaccountview

php
Anthony RICHARD 2 years ago
parent 3d6455ed57
commit d5c5e10742

@ -104,9 +104,9 @@ class AdminController extends UserController
public function addGroup(): void { public function addGroup(): void {
try { try {
$num = Validation::filter_int($_GET['num'] ?? null); $num = Validation::filter_int($_POST['num'] ?? null);
$year = Validation::filter_int($_GET['year'] ?? null); $year = Validation::filter_int($_POST['year'] ?? null);
$sector = Validation::filter_str_simple($_GET['sector'] ?? null); $sector = Validation::filter_str_simple($_POST['sector'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$groupID = $model->addGroup($num, $year, $sector); $groupID = $model->addGroup($num, $year, $sector);

@ -7,6 +7,7 @@ use Exception;
use gateway\TranslationGateway; use gateway\TranslationGateway;
use gateway\VocabularyListGateway; use gateway\VocabularyListGateway;
use model\MdlStudent; use model\MdlStudent;
use model\MdlUser;
use model\VocabularyList; use model\VocabularyList;
use model\Translation; use model\Translation;
@ -21,32 +22,29 @@ class UserController extends VisitorController
public function modifyPassword(): void { public function modifyPassword(): void {
try { try {
$userID = $_GET['user']; global $user;
$currentPassword = Validation::val_password($_GET['currentPassword'] ?? null); $currentPassword = Validation::val_password($_POST['currentPassword'] ?? null);
$newPassword = Validation::val_password($_GET['newPassword'] ?? null); $newPassword = Validation::val_password($_POST['newPassword'] ?? null);
$confirmNewPassword = Validation::val_password($_GET['confirmNewPassword'] ?? null); $confirmNewPassword = Validation::val_password($_POST['confirmNewPassword'] ?? null);
$mdl = new MdlStudent();
$user = $mdl->getUser($userID);
if ($user->getPassword() != $currentPassword || $newPassword != $confirmNewPassword) if (!password_verify($currentPassword, $user->getPassword()) || $newPassword != $confirmNewPassword)
throw new Exception(""); throw new Exception("");
$mdl->ModifyPassword($userID, $newPassword); $mdl = new MdlUser();
$_GET['user'] = $userID; $mdl->ModifyPassword($user->getId(), password_hash($newPassword, null));
$this->showAccountInfos(); $this->showAccountInfos();
} }
catch (Exception $e){ catch (Exception $e){
throw new Exception("invalid entries"); throw new Exception("invalid entries".$e->getLine());
} }
} }
public function modifyNickname(): void { public function modifyNickname(): void {
try { try {
$userID = Validation::filter_int($_GET['user'] ?? null); global $user;
$newNickname = Validation::filter_str_nospecialchar($_GET['newNickname'] ?? null); $newNickname = Validation::filter_str_nospecialchar($_POST['newNickname'] ?? null);
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$mdl->modifyNickname($userID, $newNickname); $mdl->modifyNickname($user->getId(), $newNickname);
$_GET['user'] = $userID;
$this->showAccountInfos(); $this->showAccountInfos();
} }
catch (Exception $e){ catch (Exception $e){

@ -6,6 +6,7 @@ use config\Validation;
use gateway\TranslationGateway; use gateway\TranslationGateway;
use gateway\VocabularyListGateway; use gateway\VocabularyListGateway;
use model\MdlUser; use model\MdlUser;
use Exception;
class VisitorController class VisitorController
{ {

@ -6,16 +6,6 @@ use gateway\UserGateway;
abstract class AbsModel abstract class AbsModel
{ {
private string $role;
/**
* @param string $role
*/
public function __construct(string $role)
{
$this->role = $role;
}
public function connection(string $login, string $password){ public function connection(string $login, string $password){
$gtw = new UserGateway(); $gtw = new UserGateway();
$hash = $gtw->login($login) ?? null; $hash = $gtw->login($login) ?? null;

@ -7,10 +7,6 @@ use gateway\UserGateway;
class MdlAdmin extends MdlUser class MdlAdmin extends MdlUser
{ {
public function __construct()
{
parent::__construct("admin");
}
public function getAllUsers(): array { public function getAllUsers(): array {
$gtw = new UserGateway(); $gtw = new UserGateway();

@ -8,12 +8,6 @@ use gateway\VocabularyListGateway;
class MdlStudent extends MdlUser class MdlStudent extends MdlUser
{ {
public function __construct()
{
parent::__construct("student");
}
public function getAll():array{ public function getAll():array{
$gtw = new VocabularyListGateway(); $gtw = new VocabularyListGateway();
return $gtw->findAll(); return $gtw->findAll();

@ -9,12 +9,6 @@ use gateway\VocabularyListGateway;
class MdlTeacher extends MdlUser class MdlTeacher extends MdlUser
{ {
public function __construct()
{
parent::__construct("teacher");
}
public function getAll():array{ public function getAll():array{
$gtw = new VocabularyListGateway(); $gtw = new VocabularyListGateway();
return $gtw->findAll(); return $gtw->findAll();

@ -34,7 +34,7 @@
<ul class="navbar-nav ms-auto"> <ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#game">Game</a></li> <li class="nav-item"><a class="nav-link" href="#game">Game</a></li>
<li class="nav-item"><a class="nav-link" href="#download">Download</a></li> <li class="nav-item"><a class="nav-link" href="#download">Download</a></li>
<li class="nav-item"><a class="nav-link" href="{{base}}/user/login">My account</a></li> <li class="nav-item"><a class="nav-link" href="{{base}}/visitor/login">My account</a></li>
</ul> </ul>
</div> </div>
</div> </div>

@ -24,7 +24,7 @@
<div class="center-wrap"> <div class="center-wrap">
<div class="section text-center"> <div class="section text-center">
<h4 class="mb-4 pb-3">Log In</h4> <h4 class="mb-4 pb-3">Log In</h4>
<form action="{{base}}/user/confirmLogin" method="POST"> <form action="{{base}}/visitor/confirmLogin" method="POST">
<div class="form-group"> <div class="form-group">
<input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off"> <input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off">
<i class="input-icon uil uil-at"></i> <i class="input-icon uil uil-at"></i>

@ -1,5 +1,4 @@
<form action="{{base}}/user/modifyPassword" method="GET"> <form action="{{base}}/{{ userRole[0] }}/{{userID}}/modifyPassword" method="POST">
<input type="hidden" name="user" value={{user.id}}>
<input type="text" name="currentPassword" placeholder="current password" required> <input type="text" name="currentPassword" placeholder="current password" required>
<input type="text" name="newPassword" placeholder="new password" required> <input type="text" name="newPassword" placeholder="new password" required>
<input type="text" name="confirmNewPassword" placeholder="confirm new password" required> <input type="text" name="confirmNewPassword" placeholder="confirm new password" required>

@ -15,7 +15,7 @@
href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
rel="stylesheet" /> rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)--> <!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" /> <link href="{{base}}/css/styles.css" rel="stylesheet" />
</head> </head>
<style> <style>
section { section {
@ -24,6 +24,8 @@
} }
</style> </style>
<body> <body>
{% include 'navbar.twig' %}
<div class="content">
<section> <section>
<h1>My account</h1> <h1>My account</h1>
{% if user is defined %} {% if user is defined %}
@ -32,8 +34,7 @@
<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>
<form action="{{base}}/user/modifyNickname" method="GET"> <form action="{{base}}/{{ userRole[0] }}/{{userID}}/modifyNickname" method="POST">
<input type="hidden" name="user" value={{user.id}}>
<input name="newNickname" type="text" placeholder="new nickname" required> <input name="newNickname" type="text" placeholder="new nickname" required>
<input type="submit" value="Modify your nickname"> <input type="submit" value="Modify your nickname">
</form> </form>
@ -56,5 +57,6 @@
{% include 'modifyPasswordForm.twig' %} {% include 'modifyPasswordForm.twig' %}
</section> </section>
{% endif %} {% endif %}
</div>
</body> </body>
</html> </html>
Loading…
Cancel
Save