Allow fixed homeserver (#142)

This commit is contained in:
Dirk Klimpel 2021-05-18 12:39:53 +02:00 committed by GitHub
parent 3ea1f51eb5
commit e19c34324b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

5
.env Normal file
View file

@ -0,0 +1,5 @@
# This setting allows to fix the homeserver.
# If you set this setting, the user will not be able to select
# the server and have to use synapse-admin with this server.
#REACT_APP_SERVER=https://yourmatrixserver.example.com

View file

@ -33,6 +33,11 @@ Steps for 1):
- download dependencies: `yarn install` - download dependencies: `yarn install`
- start web server: `yarn start` - start web server: `yarn start`
You can fix the homeserver, so that the user can no longer define it himself.
Either you define it at startup (e.g. `REACT_APP_SERVER=https://yourmatrixserver.example.com yarn start`)
or by editing it in the [.env](.env) file. See also the
[documentation](https://create-react-app.dev/docs/adding-custom-environment-variables/).
Steps for 2): Steps for 2):
- run the Docker container from the public docker registry: `docker run -p 8080:80 awesometechnologies/synapse-admin` or use the (docker-compose.yml)[docker-compose.yml]: `docker-compose up -d` - run the Docker container from the public docker registry: `docker run -p 8080:80 awesometechnologies/synapse-admin` or use the (docker-compose.yml)[docker-compose.yml]: `docker-compose up -d`

View file

@ -82,6 +82,7 @@ const LoginPage = ({ theme }) => {
const setLocale = useSetLocale(); const setLocale = useSetLocale();
const translate = useTranslate(); const translate = useTranslate();
const base_url = localStorage.getItem("base_url"); const base_url = localStorage.getItem("base_url");
const cfg_base_url = process.env.REACT_APP_SERVER;
const renderInput = ({ const renderInput = ({
meta: { touched, error } = {}, meta: { touched, error } = {},
@ -149,7 +150,7 @@ const LoginPage = ({ theme }) => {
const [serverVersion, setServerVersion] = useState(""); const [serverVersion, setServerVersion] = useState("");
const handleUsernameChange = _ => { const handleUsernameChange = _ => {
if (formData.base_url) return; if (formData.base_url || cfg_base_url) return;
// check if username is a full qualified userId then set base_url accordially // check if username is a full qualified userId then set base_url accordially
const home_server = extractHomeServer(formData.username); const home_server = extractHomeServer(formData.username);
const wellKnownUrl = `https://${home_server}/.well-known/matrix/client`; const wellKnownUrl = `https://${home_server}/.well-known/matrix/client`;
@ -201,6 +202,7 @@ const LoginPage = ({ theme }) => {
label={translate("ra.auth.username")} label={translate("ra.auth.username")}
disabled={loading} disabled={loading}
onBlur={handleUsernameChange} onBlur={handleUsernameChange}
resettable
fullWidth fullWidth
/> />
</div> </div>
@ -211,6 +213,7 @@ const LoginPage = ({ theme }) => {
label={translate("ra.auth.password")} label={translate("ra.auth.password")}
type="password" type="password"
disabled={loading} disabled={loading}
resettable
fullWidth fullWidth
/> />
</div> </div>
@ -219,7 +222,8 @@ const LoginPage = ({ theme }) => {
name="base_url" name="base_url"
component={renderInput} component={renderInput}
label={translate("synapseadmin.auth.base_url")} label={translate("synapseadmin.auth.base_url")}
disabled={loading} disabled={cfg_base_url || loading}
resettable
fullWidth fullWidth
/> />
</div> </div>
@ -230,7 +234,7 @@ const LoginPage = ({ theme }) => {
return ( return (
<Form <Form
initialValues={{ base_url: base_url }} initialValues={{ base_url: cfg_base_url || base_url }}
onSubmit={handleSubmit} onSubmit={handleSubmit}
validate={validate} validate={validate}
render={({ handleSubmit }) => ( render={({ handleSubmit }) => (

View file

@ -3,6 +3,9 @@ import { fetchUtils } from "react-admin";
const authProvider = { const authProvider = {
// called when the user attempts to log in // called when the user attempts to log in
login: ({ base_url, username, password }) => { login: ({ base_url, username, password }) => {
// force homeserver for protection in case the form is manipulated
base_url = process.env.REACT_APP_SERVER || base_url;
console.log("login "); console.log("login ");
const options = { const options = {
method: "POST", method: "POST",