fix not working login and form validation
This commit is contained in:
parent
d8959afda7
commit
6d35886eae
@ -4,6 +4,7 @@ import {
|
|||||||
Form,
|
Form,
|
||||||
FormDataConsumer,
|
FormDataConsumer,
|
||||||
Notification,
|
Notification,
|
||||||
|
required,
|
||||||
useLogin,
|
useLogin,
|
||||||
useNotify,
|
useNotify,
|
||||||
useLocaleState,
|
useLocaleState,
|
||||||
@ -26,7 +27,7 @@ import {
|
|||||||
import { styled } from "@mui/material/styles";
|
import { styled } from "@mui/material/styles";
|
||||||
import LockIcon from "@mui/icons-material/Lock";
|
import LockIcon from "@mui/icons-material/Lock";
|
||||||
|
|
||||||
const FormBox = styled("div")(({ theme }) => ({
|
const FormBox = styled(Box)(({ theme }) => ({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
minHeight: "calc(100vh - 1em)",
|
minHeight: "calc(100vh - 1em)",
|
||||||
@ -76,10 +77,10 @@ const FormBox = styled("div")(({ theme }) => ({
|
|||||||
const LoginPage = () => {
|
const LoginPage = () => {
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
|
const translate = useTranslate();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [supportPassAuth, setSupportPassAuth] = useState(true);
|
const [supportPassAuth, setSupportPassAuth] = useState(true);
|
||||||
const [locale, setLocale] = useLocaleState();
|
const [locale, setLocale] = useLocaleState();
|
||||||
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 cfg_base_url = process.env.REACT_APP_SERVER;
|
||||||
const [ssoBaseUrl, setSSOBaseUrl] = useState("");
|
const [ssoBaseUrl, setSSOBaseUrl] = useState("");
|
||||||
@ -133,28 +134,16 @@ const LoginPage = () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
const validate = values => {
|
const validateBaseUrl = value => {
|
||||||
const errors = {};
|
if (!value.match(/^(http|https):\/\//)) {
|
||||||
if (!values.username) {
|
return translate("synapseadmin.auth.protocol_error");
|
||||||
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 (
|
} else if (
|
||||||
!values.base_url.match(
|
!value.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?[^?&\s]*$/)
|
||||||
/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?[^?&\s]*$/
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
errors.base_url = translate("synapseadmin.auth.url_error");
|
return translate("synapseadmin.auth.url_error");
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return errors;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = auth => {
|
const handleSubmit = auth => {
|
||||||
@ -274,6 +263,7 @@ const LoginPage = () => {
|
|||||||
resettable
|
resettable
|
||||||
fullWidth
|
fullWidth
|
||||||
className="input"
|
className="input"
|
||||||
|
validate={required()}
|
||||||
/>
|
/>
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
name="password"
|
name="password"
|
||||||
@ -284,6 +274,7 @@ const LoginPage = () => {
|
|||||||
resettable
|
resettable
|
||||||
fullWidth
|
fullWidth
|
||||||
className="input"
|
className="input"
|
||||||
|
validate={required()}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
name="base_url"
|
name="base_url"
|
||||||
@ -293,6 +284,7 @@ const LoginPage = () => {
|
|||||||
resettable
|
resettable
|
||||||
fullWidth
|
fullWidth
|
||||||
className="input"
|
className="input"
|
||||||
|
validate={[required(), validateBaseUrl]}
|
||||||
/>
|
/>
|
||||||
<Box className="serverVersion">{serverVersion}</Box>
|
<Box className="serverVersion">{serverVersion}</Box>
|
||||||
</>
|
</>
|
||||||
@ -301,9 +293,9 @@ const LoginPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
initialValues={{ base_url: cfg_base_url || base_url }}
|
defaultValues={{ base_url: cfg_base_url || base_url }}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
validate={validate}
|
mode="onTouched"
|
||||||
>
|
>
|
||||||
<FormBox>
|
<FormBox>
|
||||||
<Card className="card">
|
<Card className="card">
|
||||||
|
@ -6,7 +6,7 @@ const authProvider = {
|
|||||||
// force homeserver for protection in case the form is manipulated
|
// force homeserver for protection in case the form is manipulated
|
||||||
base_url = process.env.REACT_APP_SERVER || base_url;
|
base_url = process.env.REACT_APP_SERVER || base_url;
|
||||||
|
|
||||||
console.log("login ");
|
console.log("login");
|
||||||
const options = {
|
const options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(
|
body: JSON.stringify(
|
||||||
|
Loading…
Reference in New Issue
Block a user