Feature/ldap sign in (#27)

* reworked via-ldap component
* added username i18nkey
* added customAuthNames to backend config
* added postLdapLogin api call

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2020-05-16 19:12:49 +02:00 committed by GitHub
parent fbd29c0338
commit 5eb8ab7517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 26 deletions

View file

@ -1,30 +1,70 @@
import React, {Fragment} from "react";
import {Trans} from "react-i18next";
import {Button, Form} from "react-bootstrap";
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";
const ViaLdap: React.FC = () => {
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";
return (
<Fragment>
<h5 className="center">
<Trans i18nKey="signInVia" values={{service: "LDAP"}}/>
<Trans i18nKey="signInVia" values={{service: name}}/>
</h5>
<Form>
<Form.Group controlId="formBasicUsername">
<Form.Control type="text" size="sm" placeholder="Username" />
<Form onSubmit={login}>
<Form.Group controlId="email">
<Form.Control
isInvalid={error}
type="text"
size="sm"
placeholder={t("username")}
onChange={(event) => setUsername(event.currentTarget.value)}
/>
</Form.Group>
<Form.Group controlId="formBasicPassword">
<Form.Control type="password" size="sm" placeholder="Password" />
<Form.Group controlId="password">
<Form.Control
isInvalid={error}
type="password"
size="sm"
placeholder={t("password")}
onChange={(event) => setPassword(event.currentTarget.value)}
/>
</Form.Group>
<Alert className="small" show={error} variant="danger">
<Trans i18nKey="errorLdapLogin"/>
</Alert>
<Button
type="submit"
size="sm"
variant="primary"
>
variant="primary">
<Trans i18nKey="signIn"/>
</Button>
</Form>
</Fragment>
)
);
};
export { ViaLdap }