aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-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}