diff --git a/README.md b/README.md index 4c95704..af44195 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ This project is built using [react-admin](https://marmelab.com/react-admin/). * [Changes](#changes) * [Development](#development) * [Configuration](#configuration) + * [Prefilling login form](#prefilling-login-form) * [Restricting available homeserver](#restricting-available-homeserver) * [Protecting appservice managed users](#protecting-appservice-managed-users) * [Adding custom menu items](#adding-custom-menu-items) @@ -92,6 +93,7 @@ with a proper manifest.json generation on build) * [Add option to set user's rate limits](https://github.com/etkecc/synapse-admin/pull/125) * [Support configuration via /.well-known/matrix/client](https://github.com/etkecc/synapse-admin/pull/126) * [Prevent accidental user overwrites](https://github.com/etkecc/synapse-admin/pull/139) +* [Allow providing login form details via GET params](https://github.com/etkecc/synapse-admin/pull/140) _the list will be updated as new changes are added_ @@ -129,6 +131,17 @@ services: ... ``` +### Prefilling login form + +You can prefill `username` and `homeserver` fields on the login page using GET parameters, example: + +``` +https://matrix.example.com/synapse-admin/?username=admin&server=matrix.example.com +``` + +That way `username` and `homeserver` fields will be pre-filled with `admin` and `https://matrix.example.com` respectively. + + ### Restricting available homeserver You can restrict the homeserver(s), so that the user can no longer define it himself. @@ -137,7 +150,7 @@ Edit `config.json` to restrict either to a single homeserver: ```json { - "restrictBaseUrl": "https://your-matrixs-erver.example.com" + "restrictBaseUrl": "https://matrix.example.com" } ``` @@ -146,7 +159,7 @@ similar for `/.well-known/matrix/client`: ```json { "cc.etke.synapse-admin": { - "restrictBaseUrl": "https://your-matrixs-erver.example.com" + "restrictBaseUrl": "https://matrix.example.com" } } ``` diff --git a/src/index.tsx b/src/index.tsx index 38a892f..0f2e105 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,7 +8,12 @@ import { AppContext } from "./AppContext"; import storage from "./storage"; // load config.json -let props: Config = {}; +let props: Config = { + restrictBaseUrl: [], + asManagedUsers: [], + supportURL: "", + menu: [], +}; try { const resp = await fetch("config.json"); const configJSON = await resp.json(); diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index cadb8fb..64838f9 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -96,6 +96,9 @@ const LoginPage = () => { const handleSubmit = auth => { setLoading(true); + const cleanUrl = window.location.href.replace(window.location.search, ""); + window.history.replaceState({}, "", cleanUrl); + login(auth).catch(error => { setLoading(false); notify( @@ -166,6 +169,22 @@ const LoginPage = () => { .catch(() => setSSOBaseUrl("")); }, [formData.base_url, form]); + useEffect(() => { + const params = new URLSearchParams(window.location.search); + const username = params.get("username"); + let serverURL = params.get("server"); + if (username) { + form.setValue("username", username); + } + if (serverURL) { + const isFullUrl = serverURL.match(/^(http|https):\/\//); + if (!isFullUrl) { + serverURL = `https://${serverURL}`; + } + form.setValue("base_url", serverURL); + } + }, [window.location.search]); + return ( <> { source="username" label="ra.auth.username" autoComplete="username" - disabled={loading || !supportPassAuth} onBlur={handleUsernameChange} resettable validate={required()} + {...(loading || !supportPassAuth ? { disabled: true } : {})} /> @@ -198,7 +217,7 @@ const LoginPage = () => { label="ra.auth.password" type="password" autoComplete="current-password" - disabled={loading || !supportPassAuth} + {...(loading || !supportPassAuth ? { disabled: true } : {})} resettable validate={required()} /> @@ -209,7 +228,7 @@ const LoginPage = () => { @@ -221,7 +240,7 @@ const LoginPage = () => { label="synapseadmin.auth.base_url" select={allowMultipleBaseUrls} autoComplete="url" - disabled={loading} + {...(loading ? { disabled: true } : {})} readOnly={allowSingleBaseUrl} resettable={allowAnyBaseUrl} validate={[required(), validateBaseUrl]}