From 8b8c4d533a13257494163f2e281cacbd243fdcb8 Mon Sep 17 00:00:00 2001
From: Noel De Martin <noel@moodle.com>
Date: Tue, 15 Nov 2022 12:14:46 +0100
Subject: [PATCH] MOBILE-4059 login: Treat invalidlogin error

---
 .../features/login/services/login-helper.ts   | 37 ++++++++++++++-----
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts
index 9f6b21e49..c513b3d22 100644
--- a/src/core/features/login/services/login-helper.ts
+++ b/src/core/features/login/services/login-helper.ts
@@ -39,6 +39,7 @@ import { CorePushNotifications } from '@features/pushnotifications/services/push
 import { CoreText } from '@singletons/text';
 import { CorePromisedValue } from '@classes/promised-value';
 import { SafeHtml } from '@angular/platform-browser';
+import { CoreLoginError } from '@classes/errors/loginerror';
 
 const PASSWORD_RESETS_CONFIG_KEY = 'password-resets';
 
@@ -1026,6 +1027,13 @@ export class CoreLoginHelperProvider {
             (!CoreConstants.CONFIG.skipssoconfirmation || String(CoreConstants.CONFIG.skipssoconfirmation) === 'false');
     }
 
+    /**
+     * Show a modal warning that the credentials introduced were not correct.
+     */
+    protected showInvalidLoginModal(error: CoreLoginError): void {
+        CoreDomUtils.showErrorModal(error.errorDetails ?? error.message);
+    }
+
     /**
      * Show a modal warning the user that he should use the Workplace app.
      *
@@ -1167,16 +1175,25 @@ export class CoreLoginHelperProvider {
      * @param password User password.
      */
     treatUserTokenError(siteUrl: string, error: CoreWSError, username?: string, password?: string): void {
-        if (error.errorcode == 'forcepasswordchangenotice') {
-            this.openChangePassword(siteUrl, CoreTextUtils.getErrorMessageFromError(error)!);
-        } else if (error.errorcode == 'usernotconfirmed') {
-            this.showNotConfirmedModal(siteUrl, undefined, username, password);
-        } else if (error.errorcode == 'connecttomoodleapp') {
-            this.showMoodleAppNoticeModal(CoreTextUtils.getErrorMessageFromError(error)!);
-        } else if (error.errorcode == 'connecttoworkplaceapp') {
-            this.showWorkplaceNoticeModal(CoreTextUtils.getErrorMessageFromError(error)!);
-        } else {
-            CoreDomUtils.showErrorModal(error);
+        switch (error.errorcode) {
+            case 'forcepasswordchangenotice':
+                this.openChangePassword(siteUrl, CoreTextUtils.getErrorMessageFromError(error)!);
+                break;
+            case 'usernotconfirmed':
+                this.showNotConfirmedModal(siteUrl, undefined, username, password);
+                break;
+            case 'connecttomoodleapp':
+                this.showMoodleAppNoticeModal(CoreTextUtils.getErrorMessageFromError(error)!);
+                break;
+            case 'connecttoworkplaceapp':
+                this.showWorkplaceNoticeModal(CoreTextUtils.getErrorMessageFromError(error)!);
+                break;
+            case 'invalidlogin':
+                this.showInvalidLoginModal(error);
+                break;
+            default:
+                CoreDomUtils.showErrorModal(error);
+                break;
         }
     }