From bfd28301587a20cb07fd0e09d545eb10d87f90d2 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 4 Sep 2020 16:26:03 +0300 Subject: [PATCH] Redirect User to CO dashboard in member of only one CO --- CHANGELOG.md | 1 + app/Controller/UsersController.php | 10 +++++++++- app/webroot/auth/login/index.php | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca1014e62..243909879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Changed the way we load plugins from config. This extention will allow plugins to inject bootstrapping and routes - Increased CO Localization text field capacity. - Improved user's graphical interaction during Enrollment Flow +- Redirect User to CO dashboard if member in only one CO. ### Fixed - Prevent users from submitting multiple registration requests diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 187b373e1..e98fca128 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -301,7 +301,15 @@ public function login() { // Note we're performing CO specific work here, even though we're not in a CO context yet. $this->OrgIdentitySource->syncByIdentifier($u); - + + if(count($cos) === 1 && $this->Auth->redirectUrl() === '/') { + $args = array(); + $args['plugin'] = null; + $args['controller'] = 'co_dashboards'; + $args['action'] = 'dashboard'; + $args['co'] = $co["co_id"]; + $this->redirect($args); + } $this->redirect($this->Auth->redirectUrl()); } else { // This is an API user. We don't do anything special at the moment, other diff --git a/app/webroot/auth/login/index.php b/app/webroot/auth/login/index.php index eb3541ff1..77e65fb2b 100644 --- a/app/webroot/auth/login/index.php +++ b/app/webroot/auth/login/index.php @@ -41,6 +41,13 @@ exit; } +// XXX if we define no redirect path, e.g. to an internal path: co_dashboards/configuration/co:2 then CAKEPHP thinks that should come back here +// XXX as a result adds to the SESSION auth/login as the redirect path after login. This causes the login to happen twice for the case we are +// XXX visiting the COmanage homepage +if(empty($_SESSION["Auth"]["redirect"])) { + $_SESSION["Auth"]["redirect"] = '/'; +} + ?>