diff --git a/public/backend-config.json b/public/backend-config.json index 6e42d4b11..c016dc1db 100644 --- a/public/backend-config.json +++ b/public/backend-config.json @@ -12,6 +12,9 @@ "oauth2": false, "email": true }, + "customAuthNames": { + "ldap": "FooBar" + }, "specialLinks": { "privacy": "test", "termsOfUse": "test", diff --git a/public/locales/de.json b/public/locales/de.json index ae32dc307..21b49f4f6 100644 --- a/public/locales/de.json +++ b/public/locales/de.json @@ -122,5 +122,6 @@ "errorEmailLogin": "E-Mail oder Passwort nicht korrekt", "errorLdapLogin": "Benutzername oder Passwort nicht korrekt", "email": "E-Mail", - "password": "Passwort" + "password": "Passwort", + "username": "Benutzername" } diff --git a/public/locales/en.json b/public/locales/en.json index 2fb6f181d..69f465c13 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -122,5 +122,6 @@ "errorEmailLogin": "Invalid email or password", "errorLdapLogin": "Invalid username or password", "email": "Email", - "password": "Password" + "password": "Password", + "username": "Username" } diff --git a/src/api/user.ts b/src/api/user.ts index ce68da5d9..85b4f4de0 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -22,4 +22,24 @@ export const postEmailLogin = async (email: string, password: string) => { }) .then(expectResponseCode()) .then(response => response.json()); -} \ No newline at end of file +} + +export const postLdapLogin = async (username: string, password: string) => { + return fetch(getBackendUrl() + "/auth/ldap", { + method: 'POST', + mode: 'cors', + cache: 'no-cache', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json' + }, + redirect: 'follow', + referrerPolicy: 'no-referrer', + body: JSON.stringify({ + username: username, + password: password, + }) + }) + .then(expectResponseCode()) + .then(response => response.json()); +} diff --git a/src/components/landing/pages/login/auth/via-ldap.tsx b/src/components/landing/pages/login/auth/via-ldap.tsx index 33454c5d6..3fb19f855 100644 --- a/src/components/landing/pages/login/auth/via-ldap.tsx +++ b/src/components/landing/pages/login/auth/via-ldap.tsx @@ -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 (
- +
-
- - + + + setUsername(event.currentTarget.value)} + /> - - + + setPassword(event.currentTarget.value)} + /> + + + + +
- ) + ); }; export { ViaLdap } diff --git a/src/redux/backend-config/reducers.ts b/src/redux/backend-config/reducers.ts index 03b1e6746..199d2fa37 100644 --- a/src/redux/backend-config/reducers.ts +++ b/src/redux/backend-config/reducers.ts @@ -4,7 +4,7 @@ import {BackendConfigActions, BackendConfigState, SET_BACKEND_CONFIG_ACTION_TYPE export const initialState: BackendConfigState = { allowAnonymous: true, authProviders: { - facebook: true, + facebook: false, github: false, twitter: false, gitlab: false, @@ -15,6 +15,9 @@ export const initialState: BackendConfigState = { oauth2: false, email: false }, + customAuthNames: { + ldap: "" + }, specialLinks: { privacy: "", termsOfUse: "", diff --git a/src/redux/backend-config/types.ts b/src/redux/backend-config/types.ts index 43b3423d3..8a3c1c498 100644 --- a/src/redux/backend-config/types.ts +++ b/src/redux/backend-config/types.ts @@ -5,20 +5,25 @@ export const SET_BACKEND_CONFIG_ACTION_TYPE = 'backend-config/set'; export interface BackendConfigState { allowAnonymous: boolean, authProviders: AuthProvidersState, + customAuthNames: CustomAuthNames, specialLinks: SpecialLinks, } export interface AuthProvidersState { - facebook: true, - github: false, - twitter: false, - gitlab: false, - dropbox: false, - ldap: false, - google: false, - saml: false, - oauth2: false, - email: false, + facebook: boolean, + github: boolean, + twitter: boolean, + gitlab: boolean, + dropbox: boolean, + ldap: boolean, + google: boolean, + saml: boolean, + oauth2: boolean, + email: boolean, +} + +export interface CustomAuthNames { + ldap: string; } export interface SpecialLinks {