diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-08-13 15:07:23 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-25 11:07:56 +0100 |
commit | afff310e50f2fa8419bb4242470cbde46ab54463 (patch) | |
tree | 34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/helpers/middlewares/accounts.ts | |
parent | f619de0e435f7ac3abad2ec772397486358b56e7 (diff) | |
download | PeerTube-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.ts | 20 |
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' | |||
2 | import { AccountModel } from '../../models/account/account' | 2 | import { AccountModel } from '../../models/account/account' |
3 | import * as Bluebird from 'bluebird' | 3 | import * as Bluebird from 'bluebird' |
4 | import { MAccountDefault } from '../../types/models' | 4 | import { MAccountDefault } from '../../types/models' |
5 | import { UserModel } from '@server/models/account/user' | ||
5 | 6 | ||
6 | function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { | 7 | function 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 | ||
43 | async 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 | ||
44 | export { | 61 | export { |
45 | doesAccountIdExist, | 62 | doesAccountIdExist, |
46 | doesLocalAccountNameExist, | 63 | doesLocalAccountNameExist, |
47 | doesAccountNameWithHostExist, | 64 | doesAccountNameWithHostExist, |
48 | doesAccountExist | 65 | doesAccountExist, |
66 | doesUserFeedTokenCorrespond | ||
49 | } | 67 | } |