Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
3.1 kB
2
Indexable
performLogout: function () {
			const isSso = localStorage.getItem("SSO") === "true";
			if (!navigator.onLine) {
				sap.m.MessageBox.information(this.getI18nText("Logout-No-Internet-Text"));
				return;
			}

			document.removeEventListener("backbutton",this.androidBackButtonMethod,false);
			document.removeEventListener("swiped-right",this.androidBackButtonMethod,false);

			sap.ui.getCore().applyTheme("sap_horizon");
			this.getView().removeStyleClass('darkTheme');
			document.querySelector('meta[name="theme-color"]').setAttribute("content", "#f5f6f7");
			document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]').setAttribute("content", "#f5f6f7");

			// Get persona data to see if persona should be included in logout URL
			window.db.get("persona-0").then(persona => {
				const theme = localStorage.getItem("theme");
				this.customLogger.info('Logged out user');
				this.customLogger.clearUser();
				OfflineStore.reset();
				localStorage.clear();
				localStorage.setItem("theme", theme);

				const baseUrl = window.location.href.slice(0, window.location.href.indexOf("index.html#"));
				const isHttps = baseUrl.includes("https");
				let logoutUri;
				let loginUri;
				if (persona.FromURL) {
					console.log("From URL, setting logout URI with persona");
					const personaParameter = `?Persona=${encodeURIComponent(persona.PersonaName)}`;
					logoutUri = isHttps ? `${baseUrl}do/logout${personaParameter}` : `${baseUrl}sap/public/bc/icf/logoff`;
					loginUri = `${baseUrl}index.html#/login${personaParameter}`;
				} else {
					logoutUri = isHttps ? `${baseUrl}do/logout` : `${baseUrl}sap/public/bc/icf/logoff`;
					loginUri = `${baseUrl}index.html#/login`
				}

				if (isSso) {
					// unregister service worker before redirecting to logout
					// so IDP redirect will happen after (otherwise files will
					// be served from the service worker cache)
					if (navigator.serviceWorker.controller) { //confirm service worker is registered first
						navigator.serviceWorker.getRegistration()
						.then(registration => {
							registration.unregister()
							.then(() => {
								window.location.replace(logoutUri);
							}).catch(error => console.error("Service worker unregister failed:", error));
						}).catch(error => console.error("Could not find service worker registration:", error));
					} else {
						window.location.replace(logoutUri);
					}
				} else {
					// keep SSO as false after reset, so SSO authentication is only attempted
					// once in the Login controller (when you first enter the app) if the app
					// is not using SSO
					localStorage.setItem("SSO", false);

					if (isHttps) {
						window.location.replace(logoutUri);
					} else {
						$.get({
						  url: logoutUri,
						  cache: false,
						  success: function () {
								window.location.replace(loginUri);
						  }.bind(this),
						  error: function (error) {
								console.error("Logout error:", error);
								sap.m.MessageBox.error(this.getI18nText("Logout-Error-Text"));
						  }.bind(this)
						});
					}
				}
			});
		  },
Leave a Comment