From 7d52c488192fb45b7b952f8dd36f757aa4b2004f Mon Sep 17 00:00:00 2001 From: giumar Date: Sat, 22 Apr 2023 07:55:13 +0200 Subject: [PATCH 1/3] Creazione dell'area profilo utente --- config/routes.php | 14 +++- src/Controller/User/ProfileController.php | 43 ++++++++++ templates/User/Profile/index.php | 28 +++++++ templates/element/mainmenu.php | 5 ++ .../Controller/User/ProfileControllerTest.php | 81 +++++++++++++++++++ 5 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 src/Controller/User/ProfileController.php create mode 100644 templates/User/Profile/index.php create mode 100644 tests/TestCase/Controller/User/ProfileControllerTest.php diff --git a/config/routes.php b/config/routes.php index 1c3e4dd..bc68755 100644 --- a/config/routes.php +++ b/config/routes.php @@ -1,4 +1,5 @@ setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { - + $builder->connect('/', ['controller' => 'Home', 'action' => 'index']); $builder->connect('/events', ['controller' => 'Events']); @@ -54,6 +54,16 @@ */ $builder->connect('/pages/*', 'Pages::display'); + $builder->prefix('User', function (RouteBuilder $routes) { + // All routes here will be prefixed with `/admin`, and + // have the `'prefix' => 'Admin'` route element added that + // will be required when generating URLs for these routes + + $routes->connect('/', ['controller' => 'Profile', 'action' => 'index']); + + $routes->fallbacks(DashedRoute::class); + }); + /* * Connect catchall routes for all controllers. * diff --git a/src/Controller/User/ProfileController.php b/src/Controller/User/ProfileController.php new file mode 100644 index 0000000..4f97340 --- /dev/null +++ b/src/Controller/User/ProfileController.php @@ -0,0 +1,43 @@ +loadModel('Users'); + } + /** + * + * @param \Cake\Event\EventInterface $event + * @property \Authentication\Controller\Component\AuthenticationComponent + */ + public function beforeFilter(\Cake\Event\EventInterface $event) + { + parent::beforeFilter($event); + + $this->Authentication->allowUnauthenticated([]); + } + + + /** + * Index method + * + * @return \Cake\Http\Response|null|void Renders view + */ + public function index() + { + $session = $this->getRequest()->getSession(); + $user = $this->Users->get($session->read('Auth.id')); + $this->set('user', $user); + } +} diff --git a/templates/User/Profile/index.php b/templates/User/Profile/index.php new file mode 100644 index 0000000..9ebc56a --- /dev/null +++ b/templates/User/Profile/index.php @@ -0,0 +1,28 @@ + +

Utente: request->getSession()->read('Auth.email'); ?>

+

Utente dal: request->getSession()->read('Auth.created'); ?>

diff --git a/templates/element/mainmenu.php b/templates/element/mainmenu.php index 4d95ea0..65d2e50 100644 --- a/templates/element/mainmenu.php +++ b/templates/element/mainmenu.php @@ -40,6 +40,11 @@ +