2020-05-16 13:12:49 -04:00
|
|
|
import React, {Fragment, useState} from "react";
|
|
|
|
import {Trans, useTranslation} from "react-i18next";
|
|
|
|
import {Alert, Button, Form} from "react-bootstrap";
|
|
|
|
import {postLdapLogin} from "../../../../../api/user";
|
|
|
|
import {getAndSetUser} from "../../../../../utils/apiUtils";
|
|
|
|
import {useSelector} from "react-redux";
|
|
|
|
import {ApplicationState} from "../../../../../redux";
|
2020-05-14 09:41:38 -04:00
|
|
|
|
|
|
|
const ViaLdap: React.FC = () => {
|
2020-05-16 13:12:49 -04:00
|
|
|
const {t} = useTranslation();
|
|
|
|
const ldapCustomName = useSelector((state: ApplicationState) => state.backendConfig.customAuthNames.ldap);
|
|
|
|
const [username, setUsername] = useState("");
|
|
|
|
const [password, setPassword] = useState("");
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const login = (event: any) => {
|
|
|
|
postLdapLogin(username, password)
|
|
|
|
.then(loginJson => {
|
|
|
|
console.log(loginJson)
|
|
|
|
getAndSetUser();
|
|
|
|
}).catch(_reason => {
|
|
|
|
setError(true);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = ldapCustomName ? `${ldapCustomName} (LDAP)` : "LDAP";
|
|
|
|
|
2020-05-14 09:41:38 -04:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<h5 className="center">
|
2020-05-16 13:12:49 -04:00
|
|
|
<Trans i18nKey="signInVia" values={{service: name}}/>
|
2020-05-14 09:41:38 -04:00
|
|
|
</h5>
|
2020-05-16 13:12:49 -04:00
|
|
|
<Form onSubmit={login}>
|
|
|
|
<Form.Group controlId="email">
|
|
|
|
<Form.Control
|
|
|
|
isInvalid={error}
|
|
|
|
type="text"
|
|
|
|
size="sm"
|
|
|
|
placeholder={t("username")}
|
|
|
|
onChange={(event) => setUsername(event.currentTarget.value)}
|
|
|
|
/>
|
2020-05-14 09:41:38 -04:00
|
|
|
</Form.Group>
|
|
|
|
|
2020-05-16 13:12:49 -04:00
|
|
|
<Form.Group controlId="password">
|
|
|
|
<Form.Control
|
|
|
|
isInvalid={error}
|
|
|
|
type="password"
|
|
|
|
size="sm"
|
|
|
|
placeholder={t("password")}
|
|
|
|
onChange={(event) => setPassword(event.currentTarget.value)}
|
|
|
|
/>
|
2020-05-14 09:41:38 -04:00
|
|
|
</Form.Group>
|
2020-05-16 13:12:49 -04:00
|
|
|
|
|
|
|
<Alert className="small" show={error} variant="danger">
|
|
|
|
<Trans i18nKey="errorLdapLogin"/>
|
|
|
|
</Alert>
|
|
|
|
|
2020-05-14 09:41:38 -04:00
|
|
|
<Button
|
2020-05-16 13:12:49 -04:00
|
|
|
type="submit"
|
2020-05-14 09:41:38 -04:00
|
|
|
size="sm"
|
2020-05-16 13:12:49 -04:00
|
|
|
variant="primary">
|
2020-05-14 09:41:38 -04:00
|
|
|
<Trans i18nKey="signIn"/>
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</Fragment>
|
2020-05-16 13:12:49 -04:00
|
|
|
);
|
2020-05-14 09:41:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export { ViaLdap }
|