Show Synapse server version on login page

Change-Id: Id9b0d2adf83590524069d308f4fe9e5d14147295
This commit is contained in:
Manuel Stahl 2020-05-05 19:07:07 +02:00
parent 300e22a537
commit 0ada5287d7
2 changed files with 34 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import { import {
fetchUtils, fetchUtils,
FormDataConsumer, FormDataConsumer,
@ -65,6 +65,12 @@ const useStyles = makeStyles(theme => ({
actions: { actions: {
padding: "0 1em 1em 1em", padding: "0 1em 1em 1em",
}, },
serverVersion: {
color: "#9e9e9e",
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
marginBottom: "1em",
marginLeft: "0.5em",
},
})); }));
const LoginPage = ({ theme }) => { const LoginPage = ({ theme }) => {
@ -138,6 +144,7 @@ const LoginPage = ({ theme }) => {
const UserData = ({ formData }) => { const UserData = ({ formData }) => {
const form = useForm(); const form = useForm();
const [serverVersion, setServerVersion] = useState("");
const handleUsernameChange = _ => { const handleUsernameChange = _ => {
if (formData.base_url) return; if (formData.base_url) return;
@ -158,6 +165,30 @@ const LoginPage = ({ theme }) => {
} }
}; };
useEffect(
_ => {
if (
!formData.base_url ||
!formData.base_url.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+$/)
)
return;
const versionUrl = `${formData.base_url}/_synapse/admin/v1/server_version`;
fetchUtils
.fetchJson(versionUrl, { method: "GET" })
.then(({ json }) => {
setServerVersion(
`${translate("synapseadmin.auth.server_version")} ${
json["server_version"]
}`
);
})
.catch(_ => {
setServerVersion("");
});
},
[formData.base_url]
);
return ( return (
<div> <div>
<div className={classes.input}> <div className={classes.input}>
@ -190,6 +221,7 @@ const LoginPage = ({ theme }) => {
fullWidth fullWidth
/> />
</div> </div>
<div className={classes.serverVersion}>{serverVersion}</div>
</div> </div>
); );
}; };

View file

@ -6,6 +6,7 @@ export default {
auth: { auth: {
base_url: "Heimserver URL", base_url: "Heimserver URL",
welcome: "Willkommen bei Synapse-admin", welcome: "Willkommen bei Synapse-admin",
server_version: "Synapse Version",
username_error: "Bitte vollständigen Nutzernamen angeben: '@user:domain'", username_error: "Bitte vollständigen Nutzernamen angeben: '@user:domain'",
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen", protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
url_error: "Keine gültige Matrix Server URL", url_error: "Keine gültige Matrix Server URL",