aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/accounts.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-13 15:07:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commitafff310e50f2fa8419bb4242470cbde46ab54463 (patch)
tree34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/helpers/middlewares/accounts.ts
parentf619de0e435f7ac3abad2ec772397486358b56e7 (diff)
downloadPeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/helpers/middlewares/accounts.ts')
-rw-r--r--server/helpers/middlewares/accounts.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/server/helpers/middlewares/accounts.ts b/server/helpers/middlewares/accounts.ts
index 29b4ed1a6..9be80167c 100644
--- a/server/helpers/middlewares/accounts.ts
+++ b/server/helpers/middlewares/accounts.ts
@@ -2,6 +2,7 @@ import { Response } from 'express'
2import { AccountModel } from '../../models/account/account' 2import { AccountModel } from '../../models/account/account'
3import * as Bluebird from 'bluebird' 3import * as Bluebird from 'bluebird'
4import { MAccountDefault } from '../../types/models' 4import { MAccountDefault } from '../../types/models'
5import { UserModel } from '@server/models/account/user'
5 6
6function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { 7function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
7 const promise = AccountModel.load(parseInt(id + '', 10)) 8 const promise = AccountModel.load(parseInt(id + '', 10))
@@ -39,11 +40,28 @@ async function doesAccountExist (p: Bluebird<MAccountDefault>, res: Response, se
39 return true 40 return true
40} 41}
41 42
43async function doesUserFeedTokenCorrespond (id: number | string, token: string, res: Response) {
44 const user = await UserModel.loadById(parseInt(id + '', 10))
45
46 if (token !== user.feedToken) {
47 res.status(401)
48 .send({ error: 'User and token mismatch' })
49 .end()
50
51 return false
52 }
53
54 res.locals.user = user
55
56 return true
57}
58
42// --------------------------------------------------------------------------- 59// ---------------------------------------------------------------------------
43 60
44export { 61export {
45 doesAccountIdExist, 62 doesAccountIdExist,
46 doesLocalAccountNameExist, 63 doesLocalAccountNameExist,
47 doesAccountNameWithHostExist, 64 doesAccountNameWithHostExist,
48 doesAccountExist 65 doesAccountExist,
66 doesUserFeedTokenCorrespond
49} 67}