-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use BaseSetting for default group * Add header authentication * Add instructions for proxy auth * Global flag to enable header authentication * First user goes to setup-wizard regardless of proxy auth * Update readme regarding proxy authentication * Add function for creating a user * Fix issue with bolean value of HEADER_AUTH_ENABLED * Disable password change for proxy users * format code * fix lint errors * Default value for proxy headers * Ensure HEADER_USERNAME is set when using proxy auth * Add error logging for header authentication
- Loading branch information
1 parent
5492817
commit 8742015
Showing
7 changed files
with
174 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<script lang="ts"> | ||
import BaseSetting from "./BaseSetting.svelte"; | ||
type Group = { | ||
id: string; | ||
name: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { client } from "$lib/server/prisma"; | ||
import { Role } from "$lib/schema"; | ||
import { getConfig } from "$lib/server/config"; | ||
import { LegacyScrypt } from "lucia"; | ||
import type { User } from "@prisma/client"; | ||
|
||
type UserMinimal = Pick<User, "username" | "email" | "name">; | ||
|
||
export const createUser = async (user: UserMinimal, role: Role, password: string, signupTokenId?: string) => { | ||
const config = await getConfig(); | ||
const userCount = await client.user.count(); | ||
|
||
let groupId = config.defaultGroup; | ||
if (signupTokenId) { | ||
groupId = await client.signupToken | ||
.findUnique({ | ||
where: { | ||
id: signupTokenId | ||
}, | ||
select: { | ||
groupId: true | ||
} | ||
}) | ||
.then((data) => data?.groupId); | ||
} else if (userCount === 0) { | ||
groupId = ( | ||
await client.group.findFirst({ | ||
select: { | ||
id: true | ||
} | ||
}) | ||
)?.id; | ||
} | ||
const hashedPassword = await new LegacyScrypt().hash(password); | ||
|
||
const newUser = await client.user.create({ | ||
select: { | ||
id: true | ||
}, | ||
data: { | ||
username: user.username, | ||
name: user.name, | ||
email: user.email, | ||
roleId: role, | ||
hashedPassword | ||
} | ||
}); | ||
|
||
if (groupId) { | ||
await client.userGroupMembership.create({ | ||
data: { | ||
groupId: groupId, | ||
userId: newUser.id, | ||
active: true | ||
} | ||
}); | ||
} | ||
|
||
if (signupTokenId) { | ||
await client.signupToken.update({ | ||
where: { | ||
id: signupTokenId | ||
}, | ||
data: { | ||
redeemed: true | ||
} | ||
}); | ||
} | ||
|
||
return newUser; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters