Prosody auth WIP.
This commit is contained in:
@ -44,11 +44,17 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
}
|
||||
// check settings (chat enabled for this video?)
|
||||
const settings = await options.settingsManager.getSettings([
|
||||
'chat-use-prosody',
|
||||
'chat-only-locals',
|
||||
'chat-all-lives',
|
||||
'chat-all-non-lives',
|
||||
'chat-videos-list'
|
||||
])
|
||||
if (!settings['chat-use-prosody']) {
|
||||
logger.warn('Prosody chat is not active')
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
if (!videoHasWebchat({
|
||||
'chat-only-locals': settings['chat-only-locals'] as boolean,
|
||||
'chat-all-lives': settings['chat-all-lives'] as boolean,
|
||||
@ -73,6 +79,82 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
}
|
||||
))
|
||||
|
||||
router.post('/user/register', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
res.sendStatus(501)
|
||||
}
|
||||
))
|
||||
|
||||
router.get('/user/check_password', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
const settings = await options.settingsManager.getSettings([
|
||||
'chat-use-prosody',
|
||||
'chat-only-locals',
|
||||
'chat-all-lives',
|
||||
'chat-all-non-lives',
|
||||
'chat-videos-list'
|
||||
])
|
||||
if (!settings['chat-use-prosody']) {
|
||||
logger.warn('Prosody chat is not active')
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
const user = req.query.user
|
||||
const server = req.query.server
|
||||
const pass = req.query.pass
|
||||
if (server !== 'localhost') {
|
||||
logger.warn(`Cannot call check_password on user on server ${server as string}.`)
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
if (user === 'john' && pass === 'password') {
|
||||
res.status(200).send('true')
|
||||
return
|
||||
}
|
||||
res.status(200).send('false')
|
||||
}
|
||||
))
|
||||
|
||||
router.get('/user/user_exists', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
const settings = await options.settingsManager.getSettings([
|
||||
'chat-use-prosody',
|
||||
'chat-only-locals',
|
||||
'chat-all-lives',
|
||||
'chat-all-non-lives',
|
||||
'chat-videos-list'
|
||||
])
|
||||
if (!settings['chat-use-prosody']) {
|
||||
logger.warn('Prosody chat is not active')
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
const user = req.query.user
|
||||
const server = req.query.server
|
||||
if (server !== 'localhost') {
|
||||
logger.warn(`Cannot call user_exists on user on server ${server as string}.`)
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
if (user === 'john') {
|
||||
res.status(200).send('true')
|
||||
}
|
||||
res.status(200).send('false')
|
||||
}
|
||||
))
|
||||
|
||||
router.post('/user/set_password', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
res.sendStatus(501)
|
||||
}
|
||||
))
|
||||
|
||||
router.post('/user/remove_user', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
res.sendStatus(501)
|
||||
}
|
||||
))
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type { Router, RequestHandler, Request, Response, NextFunction } from 'express'
|
||||
import type { ProxyOptions } from 'express-http-proxy'
|
||||
import { getBaseRouter } from '../helpers'
|
||||
import { asyncMiddleware } from '../middlewares/async'
|
||||
import * as path from 'path'
|
||||
const bodyParser = require('body-parser')
|
||||
|
||||
@ -20,8 +21,8 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
||||
|
||||
const router: Router = getRouter()
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
router.get('/room/:videoUUID', async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
router.get('/room/:videoUUID', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
||||
const settings = await settingsManager.getSettings([
|
||||
'chat-use-prosody', 'chat-use-builtin', 'chat-room', 'chat-server',
|
||||
'chat-bosh-uri', 'chat-ws-uri'
|
||||
@ -69,14 +70,13 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
||||
page = page.replace(/{{ROOM}}/g, room)
|
||||
page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri)
|
||||
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
||||
page = page.replace(/{{TRY_AUTHENTICATED_MODE}}/g, settings['chat-use-prosody'] ? 'true' : 'false')
|
||||
|
||||
res.status(200)
|
||||
res.type('html')
|
||||
res.send(page)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
))
|
||||
|
||||
changeHttpBindRoute(options, null)
|
||||
router.all('/http-bind',
|
||||
|
Reference in New Issue
Block a user