-
- Nom d'utilisateur
-
-
-
- Adresse mail
-
-
-
-
+
+
+
+
+
+
+
+ Nom d'utilisateur
+
+
+
+ Adresse mail
+
+
+
+
+
-
);
}
-function setVariable({varia} : {varia : any}){
+function updateAccountInfos(name : string, email : string) {
+ fetchAPI("account/update/profile", {
+ name : name,
+ email : email
+ });
}
-
// function InputSettings(){
// return(
//
diff --git a/public/api/index.php b/public/api/index.php
index 0331ca8..1b43a3a 100644
--- a/public/api/index.php
+++ b/public/api/index.php
@@ -37,7 +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)));
+ $router->map("POST", "/account/update/profile", Action::auth(fn(Account $acc) => getAPIUserController()->updateProfile($acc)));
return $router;
}
diff --git a/public/index.php b/public/index.php
index beae9b7..5d24e48 100644
--- a/public/index.php
+++ b/public/index.php
@@ -85,7 +85,7 @@ 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)));
-
+
//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)));
diff --git a/src/Api/Controller/APIUserController.php b/src/Api/Controller/APIUserController.php
index a117122..5bf66f1 100644
--- a/src/Api/Controller/APIUserController.php
+++ b/src/Api/Controller/APIUserController.php
@@ -30,13 +30,13 @@ class APIUserController {
* @param Account $account
* @return HttpResponse
*/
- public function updateProfil(Account $account): HttpResponse {
+ public function updateProfile(Account $account): HttpResponse {
return Control::runChecked([
- "username" => [Validators::name()],
+ "name" => [Validators::name()],
"email" => [Validators::email()]
], 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)) {
//TODO find a system to handle Unauthorized error codes more easily from failures.
@@ -45,5 +45,8 @@ class APIUserController {
return HttpResponse::fromCode(HttpCodes::OK);
});
+
+ // error_log("Test");
+ // return new HttpResponse(HttpCodes::OK, []);
}
}
diff --git a/src/Core/Gateway/AccountGateway.php b/src/Core/Gateway/AccountGateway.php
index 02350b1..8d0b944 100644
--- a/src/Core/Gateway/AccountGateway.php
+++ b/src/Core/Gateway/AccountGateway.php
@@ -82,9 +82,16 @@ class AccountGateway {
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]
+ ]);
}
-
}
diff --git a/src/Core/Model/AuthModel.php b/src/Core/Model/AuthModel.php
index 103d4e4..169b292 100644
--- a/src/Core/Model/AuthModel.php
+++ b/src/Core/Model/AuthModel.php
@@ -51,8 +51,12 @@ 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->
+ public function updateProfile(string $name, string $email, int $id) : array {
+ 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);
}
-
- public function changeUsername(int $id, string $newUsername) {
- $this->gateway->changeUsername($id, $newUsername);
- }
-
}