Merge branch 'settings' of codefirst.iut.uca.fr:IQBall/Application-Web into settings

d_yanis 1 year ago
commit 8ca2dc9892

@ -16,3 +16,12 @@
border: 1px yellow solid;
height: 100%;
}
.content {
color : var(--main-contrast-color);
}
#account-infos {
width: 50%;
padding-left : 5%;
}

@ -1,8 +1,11 @@
import "../style/settings/settings.css"
import 'bootstrap/dist/css/bootstrap.min.css';
import { MainTitle, SecondTitle } from "./component/Title"
import {Header} from './template/Header'
import { useState, ChangeEvent } from "react"
import { User } from "./model/User"
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
export default function Settings({user} : {user : User}){
return (
@ -35,22 +38,38 @@ function AccountSettings({user} : {user : User}){
function ContentAccountSettings({user} : {user : User}) {
// Utilisez useState pour gérer l'état du champ de saisie
const [username, setUsername] = useState(user.name);
// const [username, setUsername] = useState({user.username});
// Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
const handleUsernameChange = (event : ChangeEvent<HTMLInputElement>) => {
setUsername(event.target.value);
};
// // Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
// const handleUsernameChange = (event : ChangeEvent<HTMLInputElement>) => {
// setUsername(event.target.value);
// };
// return (
// <form id="account-content">
// <dl>
// <dt>Nom d'utilisateur</dt>
// {/* Utilisez la valeur de l'état et la fonction onChange */}
// <dd><input type="text" value={username} onChange={handleUsernameChange} /></dd>
// </dl>
// </form>
// );
return (
<form id="account-content">
<dl>
<dt>Nom d'utilisateur</dt>
{/* Utilisez la valeur de l'état et la fonction onChange */}
<dd><input type="text" value={username} id="username" name="username" onChange={handleUsernameChange} /></dd>
</dl>
<input type="submit" value="Update"/>
</form>
<div id="account-infos">
<Form>
<Form.Group className="mb-3" controlId="formUsername">
<Form.Label className="content">Nom d'utilisateur</Form.Label>
<Form.Control size="sm" defaultValue={user.name}/>
</Form.Group>
<Form.Group className="mb-3" controlId="formEmail">
<Form.Label className="content">Adresse mail</Form.Label>
<Form.Control size="sm" defaultValue={user.email} type="email" placeholder="Password" />
</Form.Group>
<Button variant="outline-primary" type="submit">Mettre à jour</Button>
</Form>
</div>
);
}

@ -10,7 +10,9 @@
"@types/node": "^16.18.59",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"bootstrap": "^5.3.2",
"react": "^18.2.0",
"react-bootstrap": "^2.10.0",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"typescript": "^5.2.2",

@ -37,7 +37,8 @@ function getRoutes(): AltoRouter {
$router->map("POST", "/auth", Action::noAuth(fn() => getAuthController()->authorize()));
$router->map("POST", "/tactic/[i:id]/edit/name", Action::auth(fn(int $id, Account $acc) => getTacticController()->updateName($id, $acc)));
$router->map("POST", "/tactic/[i:id]/save", Action::auth(fn(int $id, Account $acc) => getTacticController()->saveContent($id, $acc)));
// $router->map("POST", "/user/username", Action::auth(fn(Account $acc) => getAPIUserController()->changeUsername($acc)));
$router->map("POST", "/update/profil", Action::auth(fn(Account $acc) => getAPIUserController()->updateProfil($acc)));
return $router;
}

@ -85,8 +85,6 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/home", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
$ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
$ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($s)));
$ar->map("POST", "/user/profil", Action::auth(fn(SessionHandle $s) => getUserController()->updateProfil($_POST, $s)));
//tactic-related
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s)));
@ -110,7 +108,6 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->displayEditTeam($idTeam, $s)));
$ar->map("POST", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->editTeam($idTeam, $_POST, $s)));
return $ar;
}

@ -3,29 +3,47 @@
namespace IQBall\Api\Controller;
use IQBall\App\Control;
use IQBall\Core\Model\AuthModel;
use IQBall\Core\Data\Account;
use IQBall\Core\Http\HttpCodes;
use IQBall\Core\Http\HttpRequest;
use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Http\JsonHttpResponse;
use IQBall\Core\Model\AuthModel;
use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\Validator;
use IQBall\Core\Validation\Validators;
/**
* API endpoint related to tactics
*/
class APIUserController {
private AuthModel $model;
/**
* @param AuthModel $model
*/
public function __construct(AuthModel $model) {
$this->model = $model;
}
public function changeUsername(Account $acc) {
/**
* @param Account $account
* @return HttpResponse
*/
public function updateProfil(Account $account): HttpResponse {
return Control::runChecked([
"username" => [Validators::name()]
], function(HttpRequest $request) use ($acc) {
$this->model->changeUsername($acc->getUser()->getId(), $request["username"]);
"username" => [Validators::name()],
"email" => [Validators::email()]
], function (HttpRequest $request) use ($account) {
$failures = $this->model->updateProfil($request["username"], $request["email"], $account->getUser()->getId());
if (!empty($failures)) {
//TODO find a system to handle Unauthorized error codes more easily from failures.
return new JsonHttpResponse($failures, HttpCodes::BAD_REQUEST);
}
return HttpResponse::fromCode(HttpCodes::OK);
});
}
}
?>

@ -13,7 +13,6 @@ class UserController {
private TacticModel $tactics;
private ?TeamModel $teams;
/**
* @param TacticModel $tactics
* @param TeamModel|null $teams
@ -63,9 +62,4 @@ class UserController {
$session->destroy();
return HttpResponse::redirect("/");
}
public function updateProfil(array $request, SessionHandle $s) {
}
}

@ -82,8 +82,8 @@ class AccountGateway {
return new Account($acc["token"], new User($acc["email"], $acc["username"], $acc["id"], $acc["profilePicture"]));
}
public function changeUsername(int $id, string $username) {
$this->con->exec("UPDATE Account SET username = :username WHERE id = :id", [":username" => [$username, PDO::PARAM_STR], ":id" => [$id, PDO::PARAM_INT]]);
public void updateProfil() {
}

@ -6,6 +6,7 @@ use Exception;
use IQBall\Core\Data\Account;
use IQBall\Core\Data\User;
use IQBall\Core\Gateway\AccountGateway;
use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\ValidationFail;
@ -50,6 +51,10 @@ class AuthModel {
return new Account($token, new User($email, $username, $accountId, self::DEFAULT_PROFILE_PICTURE));
}
public function updateProfil(string $username, string $mail, Account $account) {
$gateway->
}
/**
* Generate a random base 64 string
* @return string

Loading…
Cancel
Save