From 2eda8a1095319b6ca91584fce90996432ff4a8af Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 21 Apr 2020 18:15:46 +0200
Subject: [PATCH] FEAT #13694 TIME 0:30 add msg if bad url custom

---
 .../controllers/AuthenticationController.php  |  6 ++---
 src/frontend/app/login/login.component.ts     | 27 +++++--------------
 src/frontend/css/maarch-material-modal.scss   |  2 ++
 src/frontend/lang/lang-en.ts                  |  2 ++
 src/frontend/lang/lang-fr.ts                  |  2 ++
 src/frontend/lang/lang-nl.ts                  |  2 ++
 .../plugins/modal/alert.component.html        |  2 +-
 7 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php
index 5549c0f411b..11957b260ed 100755
--- a/src/core/controllers/AuthenticationController.php
+++ b/src/core/controllers/AuthenticationController.php
@@ -50,15 +50,15 @@ class AuthenticationController
     public function getValidUrl(Request $request, Response $response)
     {
         if (!is_file('custom/custom.json')) {
-            return $response->withJson(['message' => 'No custom file', 'lang' => '']);
+            return $response->withJson(['message' => 'No custom file', 'lang' => 'noConfiguration']);
         }
 
         $jsonFile = file_get_contents('custom/custom.json');
         $jsonFile = json_decode($jsonFile, true);
         if (count($jsonFile) == 0) {
-            return $response->withJson(['message' => 'No custom', 'lang' => '']);
+            return $response->withJson(['message' => 'No custom', 'lang' => 'noConfiguration']);
         } elseif (count($jsonFile) > 1) {
-            return $response->withJson(['message' => 'There is more than 1 custom', 'lang' => '']);
+            return $response->withJson(['message' => 'There is more than 1 custom', 'lang' => 'moreOneCustom']);
         }
 
         $url = null;
diff --git a/src/frontend/app/login/login.component.ts b/src/frontend/app/login/login.component.ts
index 49bc0aa7dd5..e423216b86d 100644
--- a/src/frontend/app/login/login.component.ts
+++ b/src/frontend/app/login/login.component.ts
@@ -12,6 +12,7 @@ import { of } from 'rxjs/internal/observable/of';
 import { HeaderService } from '../../service/header.service';
 import { FunctionsService } from '../../service/functions.service';
 import { TimeLimitPipe } from '../../plugins/timeLimit.pipe';
+import { AlertComponent } from '../../plugins/modal/alert.component';
 
 @Component({
     templateUrl: 'login.component.html',
@@ -114,33 +115,17 @@ export class LoginComponent implements OnInit {
             catchError((err: any) => {
                 this.http.get('../rest/validUrl').pipe(
                     tap((data: any) => {
-                        if (data.url !== null) {
+                        if (!this.functionsService.empty(data.url)) {
                             window.location.href = data.url;
+                        } else if (data.lang === 'moreOneCustom') {
+                            this.dialog.open(AlertComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.lang.accessNotFound, msg: this.lang.moreOneCustom, hideButton: true } });
+                        } else if (data.lang === 'noConfiguration') {
+                            // TO DO : LAUNCH INSTALLER
                         } else {
                             this.notify.handleSoftErrors(err);
                         }
                     })
                 ).subscribe();
-                // TO DO : CONVERT custom.xml to json
-                /*if (err.error.exception[0].message === 'Argument driver is empty') {
-                    const configs = [{
-                        custom_id : 'cs_recette',
-                        ip : '',
-                        external_domain : '',
-                        path: 'cs_recette'
-                    }];
-                    const firstConfig = configs.map(item => item.custom_id).filter((customId) => !this.functionsService.empty(customId));
-
-                    if (firstConfig.length > 0) {
-                        const url = document.URL;
-                        const splitUrl = url.split('/dist/');
-                        window.location.href = `${splitUrl[0]}/${firstConfig[0]}/dist/${splitUrl[1]}`;
-                    } else {
-                        this.notify.error('Aucun custom ou fichier de configuration trouvé!');
-                    }
-                } else {
-                    this.notify.handleSoftErrors(err);
-                }*/
                 return of(false);
             })
         ).subscribe();
diff --git a/src/frontend/css/maarch-material-modal.scss b/src/frontend/css/maarch-material-modal.scss
index e602f38c319..0daf9d1e254 100644
--- a/src/frontend/css/maarch-material-modal.scss
+++ b/src/frontend/css/maarch-material-modal.scss
@@ -57,6 +57,7 @@
     margin: 0px;
     position: relative;
     padding-top: 10px;
+    padding-bottom: 10px;
   }
 
   .mat-dialog-container {
@@ -110,6 +111,7 @@
     margin: 0px;
     position: relative;
     padding-top: 10px;
+    padding-bottom: 10px;
   }
 
   .mat-dialog-container {
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index 18e877ca135..dd6c758a977 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -1675,4 +1675,6 @@ export const LANG_EN = {
     "modelUsedByResources": "This model is used by resources, you can't delete it.",
     "mustChangePassword": "Please, you must change your password.",
     "linkedResources": "Attachments (linked mails)",
+    "accessNotFound": "Access not found",
+    "moreOneCustom": "This url is not an available instance of this application, please verify your address.",
 };
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 44511215d4d..51a7565f754 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1675,4 +1675,6 @@ export const LANG_FR = {
     "modelUsedByResources": "Le modèle est utilisé par des courriers, vous ne pouvez pas le supprimer.",
     "mustChangePassword": "Vous êtes invité à changer votre mot de passe.",
     "linkedResources": "Pièces jointes (courriers liés)",
+    "accessNotFound": "Accès introuvable",
+    "moreOneCustom": "Cette url ne correspond à aucune instance configurée, veuillez vérifier l'adresse.",
 };
diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts
index 9e9e0708453..506aa45d111 100755
--- a/src/frontend/lang/lang-nl.ts
+++ b/src/frontend/lang/lang-nl.ts
@@ -1659,4 +1659,6 @@ export const LANG_NL = {
     "modelUsedByResources": "This model is used by resources, you can't delete it.", //_TO_TRANSLATE
     "mustChangePassword": "Please, you must change your password.", //_TO_TRANSLATE
     "linkedResources": "Attachments (linked mails)", //_TO_TRANSLATE
+    "accessNotFound": "Access not found", //_TO_TRANSLATE
+    "moreOneCustom": "This url is not an available instance of this application, please verify your address.", //_TO_TRANSLATE
 };
diff --git a/src/frontend/plugins/modal/alert.component.html b/src/frontend/plugins/modal/alert.component.html
index 5e260f3352c..ce322d1a484 100644
--- a/src/frontend/plugins/modal/alert.component.html
+++ b/src/frontend/plugins/modal/alert.component.html
@@ -4,7 +4,7 @@
         <div class="alert-message alert-message-info" [innerHTML]="data.msg"></div>
     </div>
     <span class="divider-modal"></span>
-    <div mat-dialog-actions>
+    <div mat-dialog-actions *ngIf="data.hidebutton">
         <button class="actions" color="primary" mat-raised-button (click)="this.dialogRef.close();">{{lang.ok}}</button>
     </div>
 </div>
\ No newline at end of file
-- 
GitLab