Work in progress
continuous-integration/drone/push Build is failing Details

d_yanis 1 year ago
parent 8ca2dc9892
commit 7ab9b346b6

@ -2,10 +2,14 @@ import "../style/settings/settings.css"
import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/css/bootstrap.min.css';
import { MainTitle, SecondTitle } from "./component/Title" import { MainTitle, SecondTitle } from "./component/Title"
import {Header} from './template/Header' import {Header} from './template/Header'
import { useState, ChangeEvent } from "react" import { useState, ChangeEvent, useRef } from "react"
import { User } from "./model/User" import { User } from "./model/User"
import Button from 'react-bootstrap/Button'; import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form'; import Form from 'react-bootstrap/Form';
import Image from 'react-bootstrap/Image';
import { updateSourceFile } from "typescript";
import { fetchAPI } from "../Fetcher";
export default function Settings({user} : {user : User}){ export default function Settings({user} : {user : User}){
return ( return (
@ -31,12 +35,12 @@ function AccountSettings({user} : {user : User}){
return ( return (
<div id="account"> <div id="account">
<SecondTitle title="Compte personnel" id={null}/> <SecondTitle title="Compte personnel" id={null}/>
<ContentAccountSettings user={user}/> <ProfilSettings user={user} />
</div> </div>
); );
} }
function ContentAccountSettings({user} : {user : User}) { function ProfilSettings({user} : {user : User}) {
// Utilisez useState pour gérer l'état du champ de saisie // Utilisez useState pour gérer l'état du champ de saisie
// const [username, setUsername] = useState({user.username}); // const [username, setUsername] = useState({user.username});
@ -55,28 +59,42 @@ function ContentAccountSettings({user} : {user : User}) {
// </form> // </form>
// ); // );
const nameRef = useRef<HTMLInputElement>(null);
const emailRef = useRef<HTMLInputElement>(null);
const size = "171x180";
const profilePicture = user.profilePicture + "/" + size;
return ( return (
<div id="account-infos"> <div id="account">
<Form> <div id="profil-picture">
<Form.Group className="mb-3" controlId="formUsername"> <Image src={profilePicture}roundedCircle />
<Form.Label className="content">Nom d'utilisateur</Form.Label> <Button variant="outline-primary">Changer photo de profil</Button>
<Form.Control size="sm" defaultValue={user.name}/> </div>
</Form.Group> <div id="account-infos">
<Form.Group className="mb-3" controlId="formEmail"> <Form>
<Form.Label className="content">Adresse mail</Form.Label> <Form.Group className="mb-3" controlId="formUsername">
<Form.Control size="sm" defaultValue={user.email} type="email" placeholder="Password" /> <Form.Label className="content">Nom d'utilisateur</Form.Label>
</Form.Group> <Form.Control ref={nameRef} size="sm" defaultValue={user.name}/>
<Button variant="outline-primary" type="submit">Mettre à jour</Button> </Form.Group>
</Form> <Form.Group className="mb-3" controlId="formEmail">
<Form.Label className="content">Adresse mail</Form.Label>
<Form.Control ref={emailRef} id="control" size="sm" defaultValue={user.email} type="email" placeholder="Password" />
</Form.Group>
<Button variant="outline-primary" type="button" onClick={() => updateAccountInfos(nameRef.current!.value, emailRef.current!.value)}>Mettre à jour</Button>
</Form>
</div>
</div> </div>
); );
} }
function setVariable({varia} : {varia : any}){
function updateAccountInfos(name : string, email : string) {
fetchAPI("account/update/profile", {
name : name,
email : email
});
} }
// function InputSettings(){ // function InputSettings(){
// return( // return(
// <div className="input-settings"> // <div className="input-settings">

@ -37,7 +37,7 @@ function getRoutes(): AltoRouter {
$router->map("POST", "/auth", Action::noAuth(fn() => getAuthController()->authorize())); $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]/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", "/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))); $router->map("POST", "/account/update/profile", Action::auth(fn(Account $acc) => getAPIUserController()->updateProfile($acc)));
return $router; return $router;
} }

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

@ -30,13 +30,13 @@ class APIUserController {
* @param Account $account * @param Account $account
* @return HttpResponse * @return HttpResponse
*/ */
public function updateProfil(Account $account): HttpResponse { public function updateProfile(Account $account): HttpResponse {
return Control::runChecked([ return Control::runChecked([
"username" => [Validators::name()], "name" => [Validators::name()],
"email" => [Validators::email()] "email" => [Validators::email()]
], function (HttpRequest $request) use ($account) { ], function (HttpRequest $request) use ($account) {
$failures = $this->model->updateProfil($request["username"], $request["email"], $account->getUser()->getId()); $failures = $this->model->updateProfile($request["name"], $request["email"], $account->getUser()->getId());
if (!empty($failures)) { if (!empty($failures)) {
//TODO find a system to handle Unauthorized error codes more easily from failures. //TODO find a system to handle Unauthorized error codes more easily from failures.
@ -45,5 +45,8 @@ class APIUserController {
return HttpResponse::fromCode(HttpCodes::OK); return HttpResponse::fromCode(HttpCodes::OK);
}); });
// error_log("Test");
// return new HttpResponse(HttpCodes::OK, []);
} }
} }

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

@ -51,8 +51,12 @@ class AuthModel {
return new Account($token, new User($email, $username, $accountId, self::DEFAULT_PROFILE_PICTURE)); return new Account($token, new User($email, $username, $accountId, self::DEFAULT_PROFILE_PICTURE));
} }
public function updateProfil(string $username, string $mail, Account $account) { public function updateProfile(string $name, string $email, int $id) : array {
$gateway-> if(!empty($this->gateway->getAccountFromMail($email))) {
return [ValidationFail::unauthorized("Mail already exist")];
}
$this->gateway->updateProfile($name, $email, $id);
return [];
} }
/** /**
@ -78,9 +82,4 @@ class AuthModel {
} }
return $this->gateway->getAccountFromMail($email); return $this->gateway->getAccountFromMail($email);
} }
public function changeUsername(int $id, string $newUsername) {
$this->gateway->changeUsername($id, $newUsername);
}
} }

Loading…
Cancel
Save