case insensitive login
Massimo Melina committed
Jan 9, 2022 at 16:57 UTC
9c631e13096238a0bfce748b63ceb7b616da97dc
4 files changed
+9
-3
src/api.auth.ts
+2
@@ -18,6 +18,7 @@ export const login: ApiHandler = async ({ username, password }, ctx) => {
18
return ctx.status = 400
19
if (!password)
20
return ctx.status = 400
21
+ username = username.toLocaleLowerCase()
22
const acc = getAccount(username)
23
if (!acc)
24
return ctx.status = 401
@@ -31,6 +32,7 @@ export const login: ApiHandler = async ({ username, password }, ctx) => {
32
}
33
34
export const loginSrp1: ApiHandler = async ({ username }, ctx) => {
35
+ username = username.toLocaleLowerCase()
36
const account = getAccount(username)
37
if (!ctx.session)
38
return ctx.throw(500)
src/index.ts
-1
@@ -15,7 +15,6 @@ import session from 'koa-session'
15
import { zipStreamFromFolder } from './zip'
16
import { frontEndApis } from './frontEndApis'
17
import { log } from './log'
18
-import './plugins'
18
import { pluginsMiddleware } from './plugins'
19
import { throttler } from './throttler'
20
src/perm.ts
+7
-1
@@ -101,8 +101,14 @@ async function applyAccounts(newAccounts:Accounts) {
101
// we should validate content here
102
accounts = newAccounts
103
await Promise.all(_.map(accounts, async (rec,k) => {
104
+ const lc = k.toLocaleLowerCase()
105
if (!rec) // an empty object in yaml is stored as null
105
- rec = accounts[k] = { username: k, srp:'' }
106
+ rec = accounts[lc] = { username: lc, srp:'' }
107
+ else if (lc !== k) {
108
+ accounts[lc] = rec
109
+ delete accounts[k]
110
+ k = lc
111
+ }
112
setHidden(rec, { username: k })
113
await updateAccount(k)
114
}))
todo.md
-1
@@ -1,5 +1,4 @@
1
# To do
2
-- case insensitive usernames
2
- api to get config
3
- update tests to SRP login
4
- anti-csrf