From 2e197e508fc664f5f2174d86e2e7f964181c9ff7 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Sun, 29 Mar 2020 15:40:04 +0200 Subject: [PATCH] Add switch to login form for choosing well-know or given server address --- src/components/LoginPage.js | 12 +++++++++++- src/i18n/de.js | 1 + src/i18n/en.js | 1 + src/synapse/authProvider.js | 20 ++++++++++++++++---- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/components/LoginPage.js b/src/components/LoginPage.js index 19280b3..a720904 100644 --- a/src/components/LoginPage.js +++ b/src/components/LoginPage.js @@ -6,6 +6,7 @@ import { useLocale, useSetLocale, useTranslate, + BooleanInput, } from "react-admin"; import { Field, Form } from "react-final-form"; import { @@ -71,6 +72,7 @@ const LoginPage = ({ theme }) => { const setLocale = useSetLocale(); const translate = useTranslate(); const homeserver = localStorage.getItem("base_url"); + const force_server = localStorage.getItem("force_server"); const renderInput = ({ meta: { touched, error } = {}, @@ -117,7 +119,7 @@ const LoginPage = ({ theme }) => { return (
( @@ -154,6 +156,14 @@ const LoginPage = ({ theme }) => { label={translate("synapseadmin.auth.homeserver")} disabled={loading} /> + +
+
{ return str.endsWith("/") ? str.slice(0, -1) : str; }; +const getBaseUrl = (login_base_url, json_base_url, force_server) => { + if (force_server) { + return ensureHttpsForUrl(login_base_url); + } else { + return json_base_url; + } +} + const authProvider = { // called when the user attempts to log in - login: ({ homeserver, username, password }) => { + login: ({ homeserver, force_server, username, password }) => { console.log("login "); const options = { method: "POST", @@ -34,11 +42,15 @@ const authProvider = { ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login"; return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => { - const normalized_base_url = stripTrailingSlash( - json.well_known["m.homeserver"].base_url - ); + const normalized_base_url = stripTrailingSlash(getBaseUrl( + trimmed_url, + json.well_known["m.homeserver"].base_url, + force_server + )); + localStorage.setItem("base_url", normalized_base_url); localStorage.setItem("home_server_url", json.home_server); + localStorage.setItem("force_server", force_server); localStorage.setItem("user_id", json.user_id); localStorage.setItem("access_token", json.access_token); localStorage.setItem("device_id", json.device_id);