mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-18 23:45:26 +02:00
Merge pull request #19 from Myzel394/add-allow-registration
Add allow registration
This commit is contained in:
commit
4f3ff28e34
@ -66,6 +66,10 @@
|
|||||||
"maxAliasesPerUser": {
|
"maxAliasesPerUser": {
|
||||||
"label": "Maximum aliases per user",
|
"label": "Maximum aliases per user",
|
||||||
"description": "The maximum number of aliases a user can create. 0 means unlimited. Existing aliases will not be affected."
|
"description": "The maximum number of aliases a user can create. 0 means unlimited. Existing aliases will not be affected."
|
||||||
|
},
|
||||||
|
"allowRegistrations": {
|
||||||
|
"label": "Allow registrations",
|
||||||
|
"description": "If enabled, users will be able to register on your instance. This only affects new account registrations."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,10 @@
|
|||||||
"continueActionLabel": "Yes, edit email"
|
"continueActionLabel": "Yes, edit email"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"registrationsDisabled": {
|
||||||
|
"title": "Registrations are disabled",
|
||||||
|
"description": "We are sorry, but registrations on this instance are disabled.",
|
||||||
|
"login": "Login"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
import {ServerSettings} from "~/server-types"
|
import {ServerSettings} from "~/server-types"
|
||||||
import {client} from "~/constants/axios-client"
|
import {client} from "~/constants/axios-client"
|
||||||
|
|
||||||
export default async function getServerSettings(): Promise<ServerSettings> {
|
const loadData = async () => {
|
||||||
const savedData = sessionStorage.getItem("server-settings")
|
|
||||||
|
|
||||||
if (savedData) {
|
|
||||||
return JSON.parse(savedData)
|
|
||||||
}
|
|
||||||
|
|
||||||
const {data} = await client.get(`${import.meta.env.VITE_SERVER_BASE_URL}/v1/server/settings`)
|
const {data} = await client.get(`${import.meta.env.VITE_SERVER_BASE_URL}/v1/server/settings`)
|
||||||
|
|
||||||
sessionStorage.setItem("server-settings", JSON.stringify(data))
|
sessionStorage.setItem("server-settings", JSON.stringify(data))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function getServerSettings(): Promise<ServerSettings> {
|
||||||
|
const savedData = sessionStorage.getItem("server-settings")
|
||||||
|
|
||||||
|
if (savedData) {
|
||||||
|
// Refresh data in background
|
||||||
|
loadData()
|
||||||
|
|
||||||
|
return JSON.parse(savedData)
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadData()
|
||||||
|
}
|
||||||
|
@ -14,4 +14,5 @@ export const DEFAULT_ADMIN_SETTINGS: AdminSettings = {
|
|||||||
allowStatistics: true,
|
allowStatistics: true,
|
||||||
allowAliasDeletion: false,
|
allowAliasDeletion: false,
|
||||||
maxAliasesPerUser: 0,
|
maxAliasesPerUser: 0,
|
||||||
|
allowRegistrations: true,
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
|
|||||||
allowStatistics: yup.boolean().label(t("fields.allowStatistics.label")),
|
allowStatistics: yup.boolean().label(t("fields.allowStatistics.label")),
|
||||||
allowAliasDeletion: yup.boolean().label(t("fields.allowAliasDeletion.label")),
|
allowAliasDeletion: yup.boolean().label(t("fields.allowAliasDeletion.label")),
|
||||||
maxAliasesPerUser: yup.number().label(t("fields.maxAliasesPerUser.label")).min(0),
|
maxAliasesPerUser: yup.number().label(t("fields.maxAliasesPerUser.label")).min(0),
|
||||||
|
allowRegistrations: yup.boolean().label(t("fields.allowRegistrations.label")),
|
||||||
} as Record<keyof AdminSettings, any>)
|
} as Record<keyof AdminSettings, any>)
|
||||||
|
|
||||||
const {mutateAsync} = useMutation<
|
const {mutateAsync} = useMutation<
|
||||||
@ -520,6 +521,31 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
|
|||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<FormGroup key="allow_registrations">
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
checked={formik.values.allowRegistrations}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
name="allowRegistrations"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
disabled={formik.isSubmitting}
|
||||||
|
label={t("fields.allowRegistrations.label")}
|
||||||
|
/>
|
||||||
|
<FormHelperText
|
||||||
|
error={
|
||||||
|
formik.touched.allowRegistrations &&
|
||||||
|
Boolean(formik.errors.allowRegistrations)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{(formik.touched.allowRegistrations &&
|
||||||
|
formik.errors.allowRegistrations) ||
|
||||||
|
t("fields.allowRegistrations.description")}
|
||||||
|
</FormHelperText>
|
||||||
|
</FormGroup>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
|
40
src/route-widgets/SignupRoute/RegistrationsDisabled.tsx
Normal file
40
src/route-widgets/SignupRoute/RegistrationsDisabled.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import {ReactElement} from "react"
|
||||||
|
import {Link} from "react-router-dom"
|
||||||
|
import {useTranslation} from "react-i18next"
|
||||||
|
|
||||||
|
import {Box, Button, Grid, Paper, Typography} from "@mui/material"
|
||||||
|
|
||||||
|
export default function RegistrationsDisabled(): ReactElement {
|
||||||
|
const {t} = useTranslation("signup")
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Paper>
|
||||||
|
<Box maxWidth="sm">
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={4}
|
||||||
|
padding={4}
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
flexDirection="column"
|
||||||
|
>
|
||||||
|
<Grid item>
|
||||||
|
<Typography variant="h4" align="center">
|
||||||
|
{t("registrationsDisabled.title")}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Typography variant="body1" align="center">
|
||||||
|
{t("registrationsDisabled.description")}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Button component={Link} to="/auth/login" variant="contained">
|
||||||
|
{t("registrationsDisabled.login")}
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
)
|
||||||
|
}
|
@ -5,6 +5,7 @@ import {useLoaderData} from "react-router-dom"
|
|||||||
import {MultiStepForm} from "~/components"
|
import {MultiStepForm} from "~/components"
|
||||||
import {ServerSettings} from "~/server-types"
|
import {ServerSettings} from "~/server-types"
|
||||||
import EmailForm from "~/route-widgets/SignupRoute/EmailForm"
|
import EmailForm from "~/route-widgets/SignupRoute/EmailForm"
|
||||||
|
import RegistrationsDisabled from "~/route-widgets/SignupRoute/RegistrationsDisabled"
|
||||||
import YouGotMail from "~/route-widgets/SignupRoute/YouGotMail"
|
import YouGotMail from "~/route-widgets/SignupRoute/YouGotMail"
|
||||||
|
|
||||||
export default function SignupRoute(): ReactElement {
|
export default function SignupRoute(): ReactElement {
|
||||||
@ -13,6 +14,10 @@ export default function SignupRoute(): ReactElement {
|
|||||||
|
|
||||||
const index = email ? 1 : 0
|
const index = email ? 1 : 0
|
||||||
|
|
||||||
|
if (!serverSettings.allowRegistrations) {
|
||||||
|
return <RegistrationsDisabled />
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MultiStepForm
|
<MultiStepForm
|
||||||
steps={[
|
steps={[
|
||||||
|
@ -85,6 +85,7 @@ export interface ServerSettings {
|
|||||||
publicKey: string
|
publicKey: string
|
||||||
allowAliasDeletion: boolean
|
allowAliasDeletion: boolean
|
||||||
apiKeyMaxDays: number
|
apiKeyMaxDays: number
|
||||||
|
allowRegistrations: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Alias {
|
export interface Alias {
|
||||||
@ -241,6 +242,7 @@ export interface AdminSettings {
|
|||||||
allowStatistics: boolean
|
allowStatistics: boolean
|
||||||
allowAliasDeletion: boolean
|
allowAliasDeletion: boolean
|
||||||
maxAliasesPerUser: number
|
maxAliasesPerUser: number
|
||||||
|
allowRegistrations: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerCronReport {
|
export interface ServerCronReport {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user