Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_

Expand Down Expand Up @@ -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.
Expand All @@ -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"
}
```

Expand All @@ -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"
}
}
```
Expand Down
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 23 additions & 4 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 (
<>
<Tabs
Expand All @@ -186,10 +205,10 @@ const LoginPage = () => {
source="username"
label="ra.auth.username"
autoComplete="username"
disabled={loading || !supportPassAuth}
onBlur={handleUsernameChange}
resettable
validate={required()}
{...(loading || !supportPassAuth ? { disabled: true } : {})}
/>
</Box>
<Box>
Expand All @@ -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()}
/>
Expand All @@ -209,7 +228,7 @@ const LoginPage = () => {
<TextInput
source="accessToken"
label="synapseadmin.auth.access_token"
disabled={loading}
{...(loading ? { disabled: true } : {})}
resettable
validate={required()}
/>
Expand All @@ -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]}
Expand Down