import React, { useState } from "react"; import { Notification, useLogin, useNotify, useLocale, useSetLocale, useTranslate, } from "react-admin"; import { Field, Form } from "react-final-form"; import { Avatar, Button, Card, CardActions, CircularProgress, MenuItem, Select, TextField, } from "@material-ui/core"; import { makeStyles } from "@material-ui/core/styles"; import LockIcon from "@material-ui/icons/Lock"; const useStyles = makeStyles(theme => ({ main: { display: "flex", flexDirection: "column", minHeight: "100vh", alignItems: "center", justifyContent: "flex-start", background: "url(./images/floating-cogs.svg)", backgroundColor: "#f9f9f9", backgroundRepeat: "no-repeat", backgroundSize: "cover", }, card: { minWidth: 300, marginTop: "6em", }, avatar: { margin: "1em", display: "flex", justifyContent: "center", }, icon: { backgroundColor: theme.palette.secondary.main, }, hint: { marginTop: "1em", display: "flex", justifyContent: "center", color: theme.palette.grey[500], }, form: { padding: "0 1em 1em 1em", }, input: { marginTop: "1em", }, actions: { padding: "0 1em 1em 1em", }, })); const LoginPage = ({ theme }) => { const classes = useStyles({ theme }); const login = useLogin(); const notify = useNotify(); const [loading, setLoading] = useState(false); var locale = useLocale(); const setLocale = useSetLocale(); const translate = useTranslate(); const homeserver = localStorage.getItem("base_url"); const renderInput = ({ meta: { touched, error } = {}, input: { ...inputProps }, ...props }) => ( ); const validate = values => { 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"); } if (!values.password) { errors.password = translate("ra.validation.required"); } return errors; }; const handleSubmit = auth => { setLoading(true); login(auth).catch(error => { setLoading(false); notify( typeof error === "string" ? error : typeof error === "undefined" || !error.message ? "ra.auth.sign_in_error" : error.message, "warning" ); }); }; return (
(
{translate("synapseadmin.auth.welcome")}
)} /> ); }; export default LoginPage;