Add traps; user registration
This commit is contained in:
19
app/routing/middleware/util/Setting.middleware.js
Normal file
19
app/routing/middleware/util/Setting.middleware.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const { Middleware, HTTPError } = require('libflitter')
|
||||
|
||||
class SettingMiddleware extends Middleware {
|
||||
static get services() {
|
||||
return [...super.services, 'models']
|
||||
}
|
||||
|
||||
async test(req, res, next, { key, value = true }) {
|
||||
const Setting = this.models.get('Setting')
|
||||
const actual_value = await Setting.get(key)
|
||||
|
||||
if ( actual_value !== value )
|
||||
throw new HTTPError(404)
|
||||
|
||||
return next()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = SettingMiddleware
|
||||
Reference in New Issue
Block a user