mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-19 08:48:34 +02:00
show smtp note on whitelist
This commit is contained in:
parent
a6d6aaaadd
commit
548a883e3f
1 changed files with 122 additions and 110 deletions
|
@ -46,6 +46,8 @@ import { InfoPopup } from "@app/components/ui/info-popup";
|
||||||
import { Tag, TagInput } from "@app/components/tags/tag-input";
|
import { Tag, TagInput } from "@app/components/tags/tag-input";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { UserType } from "@server/types/UserTypes";
|
import { UserType } from "@server/types/UserTypes";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert";
|
||||||
|
import { InfoIcon } from "lucide-react";
|
||||||
|
|
||||||
const UsersRolesFormSchema = z.object({
|
const UsersRolesFormSchema = z.object({
|
||||||
roles: z.array(
|
roles: z.array(
|
||||||
|
@ -612,117 +614,127 @@ export default function ResourceAuthenticationPage() {
|
||||||
</SettingsSectionBody>
|
</SettingsSectionBody>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
{env.email.emailEnabled && (
|
<SettingsSection>
|
||||||
<SettingsSection>
|
<SettingsSectionHeader>
|
||||||
<SettingsSectionHeader>
|
<SettingsSectionTitle>
|
||||||
<SettingsSectionTitle>
|
One-time Passwords
|
||||||
One-time Passwords
|
</SettingsSectionTitle>
|
||||||
</SettingsSectionTitle>
|
<SettingsSectionDescription>
|
||||||
<SettingsSectionDescription>
|
Require email-based authentication for resource
|
||||||
Require email-based authentication for resource
|
access
|
||||||
access
|
</SettingsSectionDescription>
|
||||||
</SettingsSectionDescription>
|
</SettingsSectionHeader>
|
||||||
</SettingsSectionHeader>
|
<SettingsSectionBody>
|
||||||
<SettingsSectionBody>
|
{!env.email.emailEnabled && (
|
||||||
<SwitchInput
|
<Alert variant="neutral" className="mb-4">
|
||||||
id="whitelist-toggle"
|
<InfoIcon className="h-4 w-4" />
|
||||||
label="Email Whitelist"
|
<AlertTitle className="font-semibold">
|
||||||
defaultChecked={resource.emailWhitelistEnabled}
|
SMTP Required
|
||||||
onCheckedChange={setWhitelistEnabled}
|
</AlertTitle>
|
||||||
/>
|
<AlertDescription>
|
||||||
|
SMTP must be enabled on the server to use one-time password authentication.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
<SwitchInput
|
||||||
|
id="whitelist-toggle"
|
||||||
|
label="Email Whitelist"
|
||||||
|
defaultChecked={resource.emailWhitelistEnabled}
|
||||||
|
onCheckedChange={setWhitelistEnabled}
|
||||||
|
disabled={!env.email.emailEnabled}
|
||||||
|
/>
|
||||||
|
|
||||||
{whitelistEnabled && (
|
{whitelistEnabled && env.email.emailEnabled && (
|
||||||
<Form {...whitelistForm}>
|
<Form {...whitelistForm}>
|
||||||
<form id="whitelist-form">
|
<form id="whitelist-form">
|
||||||
<FormField
|
<FormField
|
||||||
control={whitelistForm.control}
|
control={whitelistForm.control}
|
||||||
name="emails"
|
name="emails"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
<InfoPopup
|
<InfoPopup
|
||||||
text="Whitelisted Emails"
|
text="Whitelisted Emails"
|
||||||
info="Only users with these email addresses will be able to access this resource. They will be prompted to enter a one-time password sent to their email. Wildcards (*@example.com) can be used to allow any email address from a domain."
|
info="Only users with these email addresses will be able to access this resource. They will be prompted to enter a one-time password sent to their email. Wildcards (*@example.com) can be used to allow any email address from a domain."
|
||||||
/>
|
/>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
{/* @ts-ignore */}
|
{/* @ts-ignore */}
|
||||||
<TagInput
|
<TagInput
|
||||||
{...field}
|
{...field}
|
||||||
activeTagIndex={
|
activeTagIndex={
|
||||||
activeEmailTagIndex
|
activeEmailTagIndex
|
||||||
}
|
}
|
||||||
size={"sm"}
|
size={"sm"}
|
||||||
validateTag={(
|
validateTag={(
|
||||||
tag
|
tag
|
||||||
) => {
|
) => {
|
||||||
return z
|
return z
|
||||||
.string()
|
.string()
|
||||||
.email()
|
.email()
|
||||||
.or(
|
.or(
|
||||||
z
|
z
|
||||||
.string()
|
.string()
|
||||||
.regex(
|
.regex(
|
||||||
/^\*@[\w.-]+\.[a-zA-Z]{2,}$/,
|
/^\*@[\w.-]+\.[a-zA-Z]{2,}$/,
|
||||||
{
|
{
|
||||||
message:
|
message:
|
||||||
"Invalid email address. Wildcard (*) must be the entire local part."
|
"Invalid email address. Wildcard (*) must be the entire local part."
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.safeParse(
|
.safeParse(
|
||||||
tag
|
tag
|
||||||
).success;
|
).success;
|
||||||
}}
|
}}
|
||||||
setActiveTagIndex={
|
setActiveTagIndex={
|
||||||
setActiveEmailTagIndex
|
setActiveEmailTagIndex
|
||||||
}
|
}
|
||||||
placeholder="Enter an email"
|
placeholder="Enter an email"
|
||||||
tags={
|
tags={
|
||||||
whitelistForm.getValues()
|
whitelistForm.getValues()
|
||||||
.emails
|
.emails
|
||||||
}
|
}
|
||||||
setTags={(
|
setTags={(
|
||||||
newRoles
|
newRoles
|
||||||
) => {
|
) => {
|
||||||
whitelistForm.setValue(
|
whitelistForm.setValue(
|
||||||
"emails",
|
"emails",
|
||||||
newRoles as [
|
newRoles as [
|
||||||
Tag,
|
Tag,
|
||||||
...Tag[]
|
...Tag[]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
allowDuplicates={
|
allowDuplicates={
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
sortTags={true}
|
sortTags={true}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Press enter to add an
|
Press enter to add an
|
||||||
email after typing it in
|
email after typing it in
|
||||||
the input field.
|
the input field.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
</SettingsSectionBody>
|
</SettingsSectionBody>
|
||||||
<SettingsSectionFooter>
|
<SettingsSectionFooter>
|
||||||
<Button
|
<Button
|
||||||
onClick={saveWhitelist}
|
onClick={saveWhitelist}
|
||||||
form="whitelist-form"
|
form="whitelist-form"
|
||||||
loading={loadingSaveWhitelist}
|
loading={loadingSaveWhitelist}
|
||||||
disabled={loadingSaveWhitelist}
|
disabled={loadingSaveWhitelist}
|
||||||
>
|
>
|
||||||
Save Whitelist
|
Save Whitelist
|
||||||
</Button>
|
</Button>
|
||||||
</SettingsSectionFooter>
|
</SettingsSectionFooter>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
)}
|
|
||||||
</SettingsContainer>
|
</SettingsContainer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue