Add option to add a mail whitelist and disable sign up

This commit is contained in:
Jonas Lochmann
2020-01-20 01:00:00 +01:00
parent e68ca95320
commit f4046e0fc3
5 changed files with 91 additions and 7 deletions
+5 -3
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import { Router } from 'express'
import { BadRequest } from 'http-errors'
import { Database } from '../database'
import { sendLoginCode, signInByMailCode } from '../function/authentication/login-by-mail'
import { isMailServerBlacklisted, sanitizeMailAddress } from '../util/mail'
import { isMailAddressCoveredByWhitelist, isMailServerBlacklisted, sanitizeMailAddress } from '../util/mail'
import {
isSendMailLoginCodeRequest,
isSignInByMailCodeRequest
@@ -41,7 +41,9 @@ export const createAuthRouter = (database: Database) => {
throw new BadRequest()
}
if (isMailServerBlacklisted(mail)) {
if (!isMailAddressCoveredByWhitelist(mail)) {
res.json({ mailAddressNotWhitelisted: true })
} else if (isMailServerBlacklisted(mail)) {
res.json({ mailServerBlacklisted: true })
} else {
const { mailLoginToken } = await sendLoginCode({
+12 -3
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,7 +17,8 @@
import { json } from 'body-parser'
import { Router } from 'express'
import { BadRequest, Unauthorized } from 'http-errors'
import { BadRequest, Forbidden, Unauthorized } from 'http-errors'
import { config } from '../config'
import { Database } from '../database'
import { removeDevice } from '../function/device/remove-device'
import { canRecoverPassword } from '../function/parent/can-recover-password'
@@ -47,7 +48,11 @@ export const createParentRouter = ({ database, websocket }: {database: Database,
const { mailAuthToken } = req.body
const { status, mail } = await getStatusByMailToken({ database, mailAuthToken })
res.json({ status, mail })
res.json({
status,
mail,
canCreateFamily: !config.disableSignup
})
} catch (ex) {
next(ex)
}
@@ -55,6 +60,10 @@ export const createParentRouter = ({ database, websocket }: {database: Database,
router.post('/create-family', json(), async (req, res, next) => {
try {
if (config.disableSignup) {
throw new Forbidden()
}
if (!isCreateFamilyByMailTokenRequest(req.body)) {
throw new BadRequest()
}