From b3585047be30edf7288e5443af0a9143c0cbd507 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=B2=20P?= <nicolo.paraciani@cnr.it>
Date: Tue, 29 Oct 2024 15:04:44 +0100
Subject: [PATCH] Add profile page + disable Turbo

---
 assets/controllers.json              |  2 +-
 src/Controller/ProfileController.php | 18 +++++++
 src/Entity/User.php                  |  8 +++
 templates/profile/index.html.twig    | 80 ++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 src/Controller/ProfileController.php
 create mode 100644 templates/profile/index.html.twig

diff --git a/assets/controllers.json b/assets/controllers.json
index 29ea244..2230c71 100644
--- a/assets/controllers.json
+++ b/assets/controllers.json
@@ -2,7 +2,7 @@
     "controllers": {
         "@symfony/ux-turbo": {
             "turbo-core": {
-                "enabled": true,
+                "enabled": false,
                 "fetch": "eager"
             },
             "mercure-turbo-stream": {
diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php
new file mode 100644
index 0000000..8099f1f
--- /dev/null
+++ b/src/Controller/ProfileController.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\Attribute\Route;
+
+class ProfileController extends AbstractController
+{
+    #[Route('/profile', name: 'app_profile')]
+    public function index(): Response
+    {
+        return $this->render('profile/index.html.twig', [
+            'controller_name' => 'ProfileController',
+        ]);
+    }
+}
diff --git a/src/Entity/User.php b/src/Entity/User.php
index 2bef50d..8541dec 100644
--- a/src/Entity/User.php
+++ b/src/Entity/User.php
@@ -37,6 +37,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\Column(length: 40, nullable: true)]
     private ?string $lastname = null;
 
+    #[ORM\Column(length: 100, nullable: true)]
+    private ?string $email = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -103,6 +106,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
         return $this;
     }
 
+    public function getEmail(): ?string
+    {
+        return $this->email;
+    }
+
     /**
      * @see UserInterface
      */
diff --git a/templates/profile/index.html.twig b/templates/profile/index.html.twig
new file mode 100644
index 0000000..1dbea9d
--- /dev/null
+++ b/templates/profile/index.html.twig
@@ -0,0 +1,80 @@
+{% extends 'data_entry.html.twig' %}
+
+{% block title %}Profile | ArCOA{% endblock %}
+
+{% block rightpanel %}
+    <h1 class="is-size-1 mb-2 has-text-centered">User profile</h1>
+
+    <div class="ml-6 pl-6 container">
+        <div class="card ml-6">
+            <div class="card-content">
+                <div class="media">
+                    <div class="media-left">
+                        <span class="icon is-large">
+                            <i class="fa fa-user-circle fa-2x"></i>
+                        </span>
+                    </div>
+                    <div class="media-content">
+                        <p class="title is-4">{{ app.user.firstname }} {{ app.user.lastname }}</p>
+                        <p class="subtitle is-6">
+                            <span class="icon is-small">
+                                <i class="fa fa-envelope"></i>
+                            </span>
+                            {{ app.user.email }}
+                        </p>
+                    </div>
+                </div>
+                <div class="content">
+                    <p class="is-size-4 pl-3">
+                        <strong>ArCOA Role:</strong>
+                        {% if 'ROLE_ADMIN' in app.user.roles %}
+                        Administrator
+                        {% elseif 'ROLE_REVISOR' in app.user.roles %}
+                        Revisor
+                        {% else %}
+                        Reader
+                        {% endif %}
+                        <span class="icon is-small is-size-5 pl-3 has-text-link">
+                            <i class="fa fa-question-circle"></i>
+                        </span>
+                    </p>
+                </div>
+            </div>
+        </div>
+
+        <div class="card ml-6 content">
+            <form class="card-content" id="change-password">
+                <div class="field">
+                    <h3 class="is-size-4 has-text-centered">Change password</h3> 
+                </div>
+                <div class="field">
+                    <label class="label">Current password</label>
+                    <p class="control">
+                        <input class="input" name="_current_pass" required type="password" placeholder="Current password">
+                    </p>
+                </div>
+                <div class="field">
+                    <label class="label">New password</label>
+                    <p class="control">
+                        <input class="input" name="_new_pass" required type="password" placeholder="New password">
+                    </p>
+                </div>
+                <div class="field">
+                    <label class="label">Confirm password</label>
+                    <p class="control">
+                        <input class="input" name="_confirm_pass" required type="password" placeholder="Confirm password">
+                    </p>
+                </div>
+                <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
+                <div class="field mt-5">
+                    <p class="control" id="submit">
+                        <button class="button is-link is-fullwidth" type="submit">
+                            Submit
+                        </button>
+                    </p>
+                </div>
+            </form>
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file