Skip to content

Commit 086ad6d

Browse files
committed
feat: add registrationsEnabled config option
1 parent 197c2ac commit 086ad6d

11 files changed

Lines changed: 43 additions & 5 deletions

File tree

docs/content/rctf/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Configuration for advanced users - sane defaults are automatically set by the in
8181
| `proxy.trust` | _(none)_ | yes | `false` | boolean, string, string array, or integer | X-Forwarded-For trust: the trust parameter to [proxy-addr](https://www.npmjs.com/package/proxy-addr) |
8282
| `loginTimeout` | `RCTF_LOGIN_TIMEOUT` | yes | 3600000 | integer | lifetime of registration, email update, and recovery links, in milliseconds |
8383
| `userMembers` | `RCTF_USER_MEMBERS` | yes | `true` | boolean | whether to allow a user to provide emails for individual members |
84+
| `registrationsEnabled` | _(none)_ | yes | `true` | boolean | whether to allow new teams creation |
8485
| `database.migrate` | `RCTF_DATABASE_MIGRATE` | yes | `never` | `before` \| `only` \| `never` | how to run postgreSQL migrations. [documentation](management/migration.md) |
8586
| `instanceType` | `RCTF_INSTANCE_TYPE` | yes | `all` | `all` \| `frontend` \| `leaderboard` | what type of instance to run. [documentation](management/scaling.md) |
8687
| `challengeProvider` | _(none)_ | yes | `database` | provider | provider for challenges. [documentation](providers/challenges/index.md) |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
status: 400
2+
message: The registrations are disabled.

packages/api-types/src/responses/goodClientConfig.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ data:
4949
type: string
5050
emailEnabled:
5151
type: boolean
52+
registrationsEnabled:
53+
type: boolean
5254
ctftime:
5355
type: object
5456
properties:

packages/api-types/src/routes/auth/register/post.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ responses:
2828
- badKnownCtftimeId
2929
- badKnownEmail
3030
- badKnownName
31+
- badRegistrationsDisabled

packages/client/src/api/auth.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export const register = async ({
8282
case 'badEmail':
8383
case 'badKnownEmail':
8484
case 'badCompetitionNotAllowed':
85+
case 'badRegistrationsDisabled':
8586
return {
8687
errors: {
8788
email: resp.message,

packages/client/src/app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,25 @@ import { ToastProvider } from './components/toast'
2727

2828
import { navigateRef } from './history-hack'
2929
import { hasChallsReadPermission } from './util/permissions'
30+
import config from './config'
3031

3132
const LoggedOutRedir = <Navigate to='/' />
3233
const LoggedInRedir = <Navigate to='/profile' />
3334

3435
function App({ classes }) {
3536
const loggedOut = !localStorage.token
37+
const registerItems = config.registrationsEnabled
38+
? [
39+
{
40+
element: <Register />,
41+
path: '/register',
42+
name: 'Register',
43+
},
44+
]
45+
: []
3646

3747
const loggedOutPaths = [
38-
{
39-
element: <Register />,
40-
path: '/register',
41-
name: 'Register',
42-
},
48+
...registerItems,
4349
{
4450
element: <Login />,
4551
path: '/login',

packages/server/src/api/auth/register.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { getUserByNameOrEmail } from '../../database/users'
1010
import { sendVerification } from '../../email'
1111

1212
export default makeFastifyRoute(authRegisterPost, async ({ req, res }) => {
13+
if (!config.registrationsEnabled) {
14+
return res.badRegistrationsDisabled()
15+
}
16+
1317
let email
1418
let ctftimeId
1519
if (req.body.ctftimeToken !== undefined) {

packages/server/src/config/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const config: ClientConfig = {
1515
faviconUrl: server.faviconUrl,
1616
emailEnabled: server.email != null,
1717
userMembers: server.userMembers,
18+
registrationsEnabled: server.registrationsEnabled,
1819
ctftime:
1920
server.ctftime == null
2021
? undefined

packages/server/src/config/load.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const defaultConfig: PartialDeep<ServerConfig> = {
131131
},
132132
instanceType: 'all',
133133
userMembers: true,
134+
registrationsEnabled: true,
134135
sponsors: [],
135136
homeContent: '',
136137
faviconUrl: 'https://redpwn.storage.googleapis.com/branding/rctf-favicon.ico',

packages/server/src/config/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface ServerConfig {
4949
}
5050

5151
userMembers: boolean
52+
registrationsEnabled: boolean
53+
5254
sponsors: Sponsor[]
5355
homeContent: string
5456
ctfName: string
@@ -98,6 +100,7 @@ export type ClientConfig = Pick<
98100
| 'startTime'
99101
| 'endTime'
100102
| 'userMembers'
103+
| 'registrationsEnabled'
101104
| 'faviconUrl'
102105
> & {
103106
emailEnabled: boolean

0 commit comments

Comments
 (0)