diff --git a/.prettierrc b/.prettierrc
index c3c0ee3..17335ee 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -6,5 +6,6 @@
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
- "jsxBracketSameLine": false
+ "jsxBracketSameLine": false,
+ "arrowParens": "avoid",
}
diff --git a/package.json b/package.json
index 0d49bed..7d754fe 100644
--- a/package.json
+++ b/package.json
@@ -4,28 +4,29 @@
"description": "Admin GUI for the Matrix.org server Synapse",
"author": "Awesome Technologies Innovationslabor GmbH",
"license": "Apache-2.0",
+ "homepage": ".",
"repository": {
"type": "git",
"url": "https://github.com/Awesome-Technologies/synapse-admin"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.1.1",
- "@testing-library/react": "^9.4.0",
- "@testing-library/user-event": "^8.1.0",
+ "@testing-library/react": "^10.0.2",
+ "@testing-library/user-event": "^10.0.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
- "eslint-config-prettier": "^6.10.0",
+ "eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
- "prettier": "^1.19.1"
+ "prettier": "^2.0.0"
},
"dependencies": {
"prop-types": "^15.7.2",
"ra-language-german": "^2.1.2",
- "react": "^16.12.0",
- "react-admin": "^3.1.3",
- "react-dom": "^16.12.0",
- "react-scripts": "^3.3.0"
+ "react": "^16.13.1",
+ "react-admin": "^3.4.0",
+ "react-dom": "^16.13.1",
+ "react-scripts": "^3.4.1"
},
"scripts": {
"start": "react-scripts start",
diff --git a/src/App.js b/src/App.js
index ce37344..f943e3f 100644
--- a/src/App.js
+++ b/src/App.js
@@ -36,6 +36,8 @@ const App = () => (
icon={UserIcon}
/>
+
+
);
diff --git a/src/components/LoginPage.js b/src/components/LoginPage.js
index 19280b3..6834625 100644
--- a/src/components/LoginPage.js
+++ b/src/components/LoginPage.js
@@ -1,13 +1,17 @@
import React, { useState } from "react";
import {
+ fetchUtils,
+ FormDataConsumer,
Notification,
useLogin,
useNotify,
useLocale,
useSetLocale,
useTranslate,
+ PasswordInput,
+ TextInput,
} from "react-admin";
-import { Field, Form } from "react-final-form";
+import { Form, useForm } from "react-final-form";
import {
Avatar,
Button,
@@ -34,7 +38,7 @@ const useStyles = makeStyles(theme => ({
backgroundSize: "cover",
},
card: {
- minWidth: 300,
+ minWidth: "30em",
marginTop: "6em",
},
avatar: {
@@ -70,7 +74,7 @@ const LoginPage = ({ theme }) => {
var locale = useLocale();
const setLocale = useSetLocale();
const translate = useTranslate();
- const homeserver = localStorage.getItem("base_url");
+ const base_url = localStorage.getItem("base_url");
const renderInput = ({
meta: { touched, error } = {},
@@ -88,15 +92,23 @@ const LoginPage = ({ theme }) => {
const validate = values => {
const errors = {};
- if (!values.homeserver) {
- errors.homeserver = translate("ra.validation.required");
- }
if (!values.username) {
errors.username = translate("ra.validation.required");
}
if (!values.password) {
errors.password = translate("ra.validation.required");
}
+ if (!values.base_url) {
+ errors.base_url = translate("ra.validation.required");
+ } else {
+ if (!values.base_url.match(/^(http|https):\/\//)) {
+ errors.base_url = translate("synapseadmin.auth.protocol_error");
+ } else if (
+ !values.base_url.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?$/)
+ ) {
+ errors.base_url = translate("synapseadmin.auth.url_error");
+ }
+ }
return errors;
};
@@ -115,9 +127,75 @@ const LoginPage = ({ theme }) => {
});
};
+ const extractHomeServer = username => {
+ const usernameRegex = /@[a-zA-Z0-9._=\-/]+:([a-zA-Z0-9\-.]+\.[a-zA-Z]+)/;
+ if (!username) return null;
+ const res = username.match(usernameRegex);
+ if (res) return res[1];
+ return null;
+ };
+
+ const UserData = ({ formData }) => {
+ const form = useForm();
+
+ const handleUsernameChange = _ => {
+ if (formData.base_url) return;
+ // check if username is a full qualified userId then set base_url accordially
+ const home_server = extractHomeServer(formData.username);
+ const wellKnownUrl = `https://${home_server}/.well-known/matrix/client`;
+ if (home_server) {
+ // fetch .well-known entry to get base_url
+ fetchUtils
+ .fetchJson(wellKnownUrl, { method: "GET" })
+ .then(({ json }) => {
+ form.change("base_url", json["m.homeserver"].base_url);
+ })
+ .catch(_ => {
+ // if there is no .well-known entry, try the home server name
+ form.change("base_url", `https://${home_server}`);
+ });
+ }
+ };
+
+ return (
+
+ );
+ };
+
return (