mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-08 15:54:51 +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 = {};
|
||||
if (!values.homeserver) {
|
||||
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) {
|
||||
errors.username = translate("ra.validation.required");
|
||||
|
|
|
@ -6,6 +6,8 @@ export default {
|
|||
auth: {
|
||||
homeserver: "Heimserver",
|
||||
welcome: "Willkommen bei Synapse-admin",
|
||||
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
||||
url_error: "Keine gültige Matrix Server URL",
|
||||
},
|
||||
users: {
|
||||
invalid_user_id:
|
||||
|
|
|
@ -6,6 +6,8 @@ export default {
|
|||
auth: {
|
||||
homeserver: "Homeserver",
|
||||
welcome: "Welcome to Synapse-admin",
|
||||
protocol_error: "URL has to start with 'http://' or 'https://'",
|
||||
url_error: "Not a valid Matrix server URL",
|
||||
},
|
||||
users: {
|
||||
invalid_user_id:
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
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 => {
|
||||
if (!str) {
|
||||
return;
|
||||
|
@ -17,7 +9,7 @@ const stripTrailingSlash = str => {
|
|||
|
||||
const authProvider = {
|
||||
// called when the user attempts to log in
|
||||
login: ({ homeserver, username, password }) => {
|
||||
login: ({ base_url, username, password }) => {
|
||||
console.log("login ");
|
||||
const options = {
|
||||
method: "POST",
|
||||
|
@ -28,10 +20,8 @@ const authProvider = {
|
|||
}),
|
||||
};
|
||||
|
||||
const url = window.decodeURIComponent(homeserver);
|
||||
const trimmed_url = url.trim().replace(/\s/g, "");
|
||||
const login_api_url =
|
||||
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
|
||||
const decoded_base_url = window.decodeURIComponent(base_url);
|
||||
const login_api_url = decoded_base_url + "/_matrix/client/r0/login";
|
||||
|
||||
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
||||
const normalized_base_url = stripTrailingSlash(
|
||||
|
|
Loading…
Reference in a new issue