Skip to content

Commit a9d57ed

Browse files
JeremieCHNxhofe
andauthored
feat: add ldap login support (#126)
* feat: add ldap login support * fix: code factor --------- Co-authored-by: Andy Hsu <i@nn.ci>
1 parent ca02608 commit a9d57ed

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/lang/en/manage.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"indexes": "Indexes",
2121
"sso": "Single Sign-on",
2222
"docs": "Documentation",
23-
"offline_download": "Offline Download"
23+
"offline_download": "Offline Download",
24+
"ldap": "LDAP"
2425
},
2526
"title": "AList Manage",
2627
"not_admin": "You are not admin user, please login with admin account.",

src/lang/en/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,14 @@
9797
"version": "Version",
9898
"video_autoplay": "Video autoplay",
9999
"video_types": "Video types",
100-
"webauthn_login_enabled": "Webauthn login enabled"
100+
"webauthn_login_enabled": "Webauthn login enabled",
101+
"ldap_login_enabled": "LDAP login enabled",
102+
"ldap_server": "Server",
103+
"ldap_manager_dn": "Manager DN",
104+
"ldap_manager_password": "Manager Password",
105+
"ldap_user_search_base": "User Search Base",
106+
"ldap_user_search_filter": "User Search Filter",
107+
"ldap_default_permission": "Default permission",
108+
"ldap_default_dir": "Default Dir",
109+
"ldap_login_tips": "Login tips"
101110
}

src/pages/login/index.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,23 @@ const Login = () => {
5656
const [opt, setOpt] = createSignal("")
5757
const [useauthn, setuseauthn] = createSignal(false)
5858
const [remember, setRemember] = createStorageSignal("remember-pwd", "false")
59+
const [useLdap, setUseLdap] = createSignal(false)
5960
const [loading, data] = useFetch(
60-
async (): Promise<Resp<{ token: string }>> =>
61-
r.post("/auth/login/hash", {
62-
username: username(),
63-
password: hashPwd(password()),
64-
otp_code: opt(),
65-
}),
61+
async (): Promise<Resp<{ token: string }>> => {
62+
if (useLdap()) {
63+
return r.post("/auth/login/ldap", {
64+
username: username(),
65+
password: password(),
66+
otp_code: opt(),
67+
})
68+
} else {
69+
return r.post("/auth/login/hash", {
70+
username: username(),
71+
password: hashPwd(password()),
72+
otp_code: opt(),
73+
})
74+
}
75+
},
6676
)
6777
const [, postauthnlogin] = useFetch(
6878
(
@@ -149,6 +159,11 @@ const Login = () => {
149159
}
150160
}
151161
const [needOpt, setNeedOpt] = createSignal(false)
162+
const ldapLoginEnabled = getSettingBool("ldap_login_enabled")
163+
const ldapLoginTips = getSetting("ldap_login_tips")
164+
if (ldapLoginEnabled) {
165+
setUseLdap(true)
166+
}
152167

153168
return (
154169
<Center zIndex="1" w="$full" h="100vh">
@@ -247,6 +262,15 @@ const Login = () => {
247262
{t("login.login")}
248263
</Button>
249264
</HStack>
265+
<Show when={ldapLoginEnabled}>
266+
<Checkbox
267+
w="$full"
268+
checked={useLdap() === true}
269+
onChange={() => setUseLdap(!useLdap())}
270+
>
271+
{ldapLoginTips}
272+
</Checkbox>
273+
</Show>
250274
<Button
251275
w="$full"
252276
colorScheme="accent"

src/pages/manage/sidemenu_items.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { OcWorkflow2 } from "solid-icons/oc"
1919
import { IoCopy, IoHome, IoMagnetOutline } from "solid-icons/io"
2020
import { Component, lazy } from "solid-js"
2121
import { Group, UserRole } from "~/types"
22-
import { FaBrandsQuinscape, FaSolidBook, FaSolidDatabase } from "solid-icons/fa"
22+
import { FaSolidBook, FaSolidDatabase } from "solid-icons/fa"
2323

2424
export type SideMenuItem = SideMenuItemProps & {
2525
component?: Component
@@ -71,6 +71,12 @@ export const side_menu_items: SideMenuItem[] = [
7171
to: "/@manage/settings/sso",
7272
component: () => <CommonSettings group={Group.SSO} />,
7373
},
74+
{
75+
title: "manage.sidemenu.ldap",
76+
icon: FiLogIn,
77+
to: "/@manage/settings/ldap",
78+
component: () => <CommonSettings group={Group.LDAP} />,
79+
},
7480
{
7581
title: "manage.sidemenu.other",
7682
icon: BsMedium,

src/types/setting.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum Group {
99
ARIA2,
1010
INDEX,
1111
SSO,
12+
LDAP
1213
}
1314
export enum Flag {
1415
PUBLIC,

0 commit comments

Comments
 (0)