WIP
continuous-integration/drone/push Build is failing Details

DahmaneYanis 1 year ago
parent ad94eef630
commit 7a3774cb81

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

@ -1,55 +1,75 @@
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({username} : {username : string}){
export default function Settings({user} : {user : User}){
return (
<div id="main">
<Header username={username} />
<Body/>
<Header username={user.name} />
<Body user={user}/>
</div>
)
}
function Body() {
function Body({user} : {user : User}) {
return (
<div id="body">
<div id="content">
<MainTitle title="Paramètres" id={null}/>
<AccountSettings/>
<AccountSettings user={user} />
</div>
</div>
)
}
function AccountSettings(){
function AccountSettings({user} : {user : User}){
return (
<div id="account">
<SecondTitle title="Compte personnel" id={null}/>
<ContentAccountSettings/>
<ContentAccountSettings user={user}/>
</div>
);
}
function ContentAccountSettings({user} : {user : User}) {
// Utilisez useState pour gérer l'état du champ de saisie
const [username, setUsername] = useState({user.username});
// 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} onChange={handleUsernameChange} /></dd>
</dl>
</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",

@ -8,6 +8,7 @@ require "../../src/index-utils.php";
use IQBall\Api\API;
use IQBall\Api\Controller\APIAuthController;
use IQBall\Api\Controller\APITacticController;
use IQBall\Api\Controller\APIUserController;
use IQBall\App\Session\PhpSessionHandle;
use IQBall\Core\Action;
use IQBall\Core\Connection;
@ -25,6 +26,10 @@ function getAuthController(): APIAuthController {
return new APIAuthController(new AuthModel(new AccountGateway(new Connection(get_database()))));
}
function getAPIUserController(): APIUserController {
return new APIUserController(new AuthModel(new AccountGateway(new Connection(get_database()))));
}
function getRoutes(): AltoRouter {
$router = new AltoRouter();
$router->setBasePath(get_public_path(__DIR__));
@ -32,6 +37,7 @@ 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", "/update/profil", Action::auth(fn(Account $acc) => getAPIUserController()->updateProfil($acc)));
return $router;
}

@ -86,7 +86,6 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
$ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($s)));
//tactic-related
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s)));
$ar->map("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->openEditor($id, $s)));
@ -109,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;
}

@ -0,0 +1,49 @@
<?php
namespace IQBall\Api\Controller;
use IQBall\App\Control;
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;
}
/**
* @param Account $account
* @return HttpResponse
*/
public function updateProfil(Account $account): HttpResponse {
return Control::runChecked([
"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
@ -54,12 +53,13 @@ class UserController {
* @return ViewHttpResponse account settings page
*/
public function settings(SessionHandle $session): ViewHttpResponse {
return ViewHttpResponse::react("views/Settings.tsx", []);
return ViewHttpResponse::react("views/Settings.tsx", [
"user" => $session->getAccount()->getUser()
]);
}
public function disconnect(MutableSessionHandle $session): HttpResponse {
$session->destroy();
return HttpResponse::redirect("/");
}
}

@ -82,5 +82,9 @@ class AccountGateway {
return new Account($acc["token"], new User($acc["email"], $acc["username"], $acc["id"], $acc["profilePicture"]));
}
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