diff --git a/public/site/config/config.php b/public/site/config/config.php
index a33f331..09c260e 100644
--- a/public/site/config/config.php
+++ b/public/site/config/config.php
@@ -29,11 +29,14 @@ return [
],
'routes' => [
require(__DIR__ . '/routes/logout.php'),
+ require(__DIR__ . '/routes/login.php'),
require(__DIR__ . '/routes/toggle-favorite.php'),
require(__DIR__ . '/routes/upload-images.php'),
require(__DIR__ . '/routes/save-page.php'),
require(__DIR__ . '/routes/save-file.php'),
require(__DIR__ . '/routes/remove-file.php'),
+ require(__DIR__ . '/routes/update-password.php'),
+ require(__DIR__ . '/routes/update-email.php'),
require(__DIR__ . '/routes/upload-pdf.php'),
require(__DIR__ . '/routes/validate-brief.php'),
require(__DIR__ . '/routes/request-project-creation.php'),
diff --git a/public/site/config/routes/login.php b/public/site/config/routes/login.php
new file mode 100644
index 0000000..2569ba2
--- /dev/null
+++ b/public/site/config/routes/login.php
@@ -0,0 +1,35 @@
+ "login.json",
+ "method" => "POST",
+ "action" => function () {
+ $json = file_get_contents("php://input");
+ $data = json_decode($json);
+
+ $kirby = kirby();
+
+ $email = $data->email;
+ $password = $data->password;
+
+ if(V::email($email)) {
+ try {
+ $kirby->auth()->login($email, $password);
+ return json_encode([
+ "status" => "success",
+ "role" => (string) $kirby->user()->role()
+ ]);
+ } catch (Exception $e) {
+ return json_encode([
+ "status" => "error",
+ "message" => "Email ou mot de passe invalide.
Contactez l'administrateur pour demander la réinitialisation de vos informations de connexion."
+ ]);
+ }
+ } else {
+ return json_encode([
+ "status" => "error",
+ "message" => "Email invalide."
+ ]);
+ }
+ },
+];
diff --git a/public/site/config/routes/logout.php b/public/site/config/routes/logout.php
index 9f92b94..2f71026 100644
--- a/public/site/config/routes/logout.php
+++ b/public/site/config/routes/logout.php
@@ -10,6 +10,6 @@ return [
session_start();
}
- go(site()->panel()->url());
+ go(site()->url() . '/login');
},
];
diff --git a/public/site/config/routes/update-email.php b/public/site/config/routes/update-email.php
new file mode 100644
index 0000000..aaa9aa7
--- /dev/null
+++ b/public/site/config/routes/update-email.php
@@ -0,0 +1,22 @@
+ '/update-email.json',
+ 'method' => 'POST',
+ 'action' => function() {
+ $json = file_get_contents("php://input");
+ $data = json_decode($json);
+
+ try {
+ kirby()->user()->changeEmail($data->email);
+ return [
+ 'status' => 'success'
+ ];
+ } catch (\Throwable $th) {
+ return [
+ 'status' => 'error',
+ 'message' => 'Impossible de mettre à jour l\'email : ' . $th->getMessage() . ' in file ' . $th->getFile() . ' line ' . $th->getLine()
+ ];
+ }
+ }
+];
\ No newline at end of file
diff --git a/public/site/config/routes/update-password.php b/public/site/config/routes/update-password.php
new file mode 100644
index 0000000..001b0dc
--- /dev/null
+++ b/public/site/config/routes/update-password.php
@@ -0,0 +1,22 @@
+ '/update-password.json',
+ 'method' => 'POST',
+ 'action' => function() {
+ $json = file_get_contents("php://input");
+ $data = json_decode($json);
+
+ try {
+ kirby()->user()->changePassword($data->password);
+ return [
+ 'status' => 'success'
+ ];
+ } catch (\Throwable $th) {
+ return [
+ 'status' => 'error',
+ 'message' => 'Impossible de mettre à jour le mot de passe : ' . $th->getMessage() . ' in file ' . $th->getFile() . ' line ' . $th->getLine()
+ ];
+ }
+ }
+];
\ No newline at end of file
diff --git a/public/site/controllers/site.php b/public/site/controllers/site.php
index 73ff66a..c5a36fb 100644
--- a/public/site/controllers/site.php
+++ b/public/site/controllers/site.php
@@ -1,27 +1,46 @@
user()) {
- go($site->panel()->url());
+ if (!$kirby->user() && $page->uri() !== 'login') {
+ go('/login');
}
+
$data = $page->toArray();
$data['template'] = (string) $page->template();
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
- $userData = [
- "role" => (string) $kirby->user()->role(),
- "uuid" => (string) $kirby->user()->uuid()
- ];
-
- if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
- $userData['client'] = [
- "name" => (string) $kirby->user()->client()->toPage()->title(),
- "uuid" => (string) $kirby->user()->client()->toPage()->uuid()
+ if ($kirby->user()) {
+ $userData = [
+ "name" => (string) $kirby->user()->name()->or(null),
+ "email" => (string) $kirby->user()->email(),
+ "role" => (string) $kirby->user()->role(),
+ "uuid" => (string) $kirby->user()->uuid()
];
+
+ if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
+ $userData['client'] = [
+ "name" => (string) $kirby->user()->client()->toPage()->title(),
+ "uuid" => (string) $kirby->user()->client()->toPage()->uuid()
+ ];
+ if ($kirby->user()->client()->toPage()->logo()->isNotEmpty()) {
+ $userData['client']["logo"] = $kirby->user()->client()->toPage()->logo()->toFile()->url();
+ }
+ }
+
+ if ($kirby->user()->projects()->exists() && $kirby->user()->projects()->isNotEmpty()) {
+ $userData['projects'] = $kirby->user()->projects()->toPages()->map(function ($project) {
+ return [
+ "title" => (string) $project->title(),
+ "uri" => (string) $project->uri(),
+ "step" => (string) $project->getStepLabel(),
+ ];
+ })->data;
+ }
}
+
return [
'genericData' => $data,
- 'userData' => $userData
+ 'userData' => $userData ?? null
];
};
\ No newline at end of file
diff --git a/public/site/templates/account.json.php b/public/site/templates/account.json.php
new file mode 100644
index 0000000..032de0f
--- /dev/null
+++ b/public/site/templates/account.json.php
@@ -0,0 +1,6 @@
+ $genericData,
+ "user" => $userData
+]);
\ No newline at end of file
diff --git a/public/site/templates/account.php b/public/site/templates/account.php
new file mode 100644
index 0000000..4ed6305
--- /dev/null
+++ b/public/site/templates/account.php
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/site/templates/login.json.php b/public/site/templates/login.json.php
new file mode 100644
index 0000000..8c7cbe7
--- /dev/null
+++ b/public/site/templates/login.json.php
@@ -0,0 +1,13 @@
+ $page->exampleField(),
+ "exampleHardData" => 'Example hard value'
+];
+
+$pageData = array_merge($genericData, $specificData);
+
+echo json_encode([
+ "page" => $pageData,
+ "user" => $userData
+]);
\ No newline at end of file
diff --git a/public/site/templates/login.php b/public/site/templates/login.php
new file mode 100644
index 0000000..4ed6305
--- /dev/null
+++ b/public/site/templates/login.php
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/site/templates/projects.json.php b/public/site/templates/projects.json.php
index cabb5c7..ba74b69 100644
--- a/public/site/templates/projects.json.php
+++ b/public/site/templates/projects.json.php
@@ -1,7 +1,15 @@
user()) {
+ return json_encode([
+ 'page' => $genericData,
+ 'user' => []
+ ]);
+}
+
function getProjectData($project)
-{
+{
+
$data = [
'title' => $project->title()->value(),
'url' => $project->url(),
diff --git a/src/App.vue b/src/App.vue
index 2bd1586..c7c1cb3 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,7 +1,7 @@
{{ page.content.title }}
-