mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-22 06:21:28 +00:00
Validate URL on input instead of automatic rewrite of http to https
Change-Id: I3f3a9c5fb408af1f03ef876456133b331dc4cea3
This commit is contained in:
parent
437fd70d6d
commit
dd022eab04
4 changed files with 15 additions and 13 deletions
|
@ -90,6 +90,14 @@ const LoginPage = ({ theme }) => {
|
||||||
const errors = {};
|
const errors = {};
|
||||||
if (!values.homeserver) {
|
if (!values.homeserver) {
|
||||||
errors.homeserver = translate("ra.validation.required");
|
errors.homeserver = translate("ra.validation.required");
|
||||||
|
} else {
|
||||||
|
if (!values.homeserver.match(/^(http|https):\/\//)) {
|
||||||
|
errors.homeserver = translate("synapseadmin.auth.protocol_error");
|
||||||
|
} else if (
|
||||||
|
!values.homeserver.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+$/)
|
||||||
|
) {
|
||||||
|
errors.homeserver = translate("synapseadmin.auth.url_error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!values.username) {
|
if (!values.username) {
|
||||||
errors.username = translate("ra.validation.required");
|
errors.username = translate("ra.validation.required");
|
||||||
|
|
|
@ -6,6 +6,8 @@ export default {
|
||||||
auth: {
|
auth: {
|
||||||
homeserver: "Heimserver",
|
homeserver: "Heimserver",
|
||||||
welcome: "Willkommen bei Synapse-admin",
|
welcome: "Willkommen bei Synapse-admin",
|
||||||
|
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
||||||
|
url_error: "Keine gültige Matrix Server URL",
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id:
|
||||||
|
|
|
@ -6,6 +6,8 @@ export default {
|
||||||
auth: {
|
auth: {
|
||||||
homeserver: "Homeserver",
|
homeserver: "Homeserver",
|
||||||
welcome: "Welcome to Synapse-admin",
|
welcome: "Welcome to Synapse-admin",
|
||||||
|
protocol_error: "URL has to start with 'http://' or 'https://'",
|
||||||
|
url_error: "Not a valid Matrix server URL",
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id:
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
import { fetchUtils } from "react-admin";
|
import { fetchUtils } from "react-admin";
|
||||||
|
|
||||||
const ensureHttpsForUrl = url => {
|
|
||||||
if (/^https:\/\//i.test(url)) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
const domain = url.replace(/http.?:\/\//g, "");
|
|
||||||
return "https://" + domain;
|
|
||||||
};
|
|
||||||
|
|
||||||
const stripTrailingSlash = str => {
|
const stripTrailingSlash = str => {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return;
|
return;
|
||||||
|
@ -17,7 +9,7 @@ const stripTrailingSlash = str => {
|
||||||
|
|
||||||
const authProvider = {
|
const authProvider = {
|
||||||
// called when the user attempts to log in
|
// called when the user attempts to log in
|
||||||
login: ({ homeserver, username, password }) => {
|
login: ({ base_url, username, password }) => {
|
||||||
console.log("login ");
|
console.log("login ");
|
||||||
const options = {
|
const options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -28,10 +20,8 @@ const authProvider = {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = window.decodeURIComponent(homeserver);
|
const decoded_base_url = window.decodeURIComponent(base_url);
|
||||||
const trimmed_url = url.trim().replace(/\s/g, "");
|
const login_api_url = decoded_base_url + "/_matrix/client/r0/login";
|
||||||
const login_api_url =
|
|
||||||
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
|
|
||||||
|
|
||||||
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
||||||
const normalized_base_url = stripTrailingSlash(
|
const normalized_base_url = stripTrailingSlash(
|
||||||
|
|
Loading…
Reference in a new issue