diff options
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r-- | server/controllers/api/users.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 583376c38..5e96d789e 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -2,12 +2,13 @@ import * as express from 'express' | |||
2 | import 'multer' | 2 | import 'multer' |
3 | import { extname, join } from 'path' | 3 | import { extname, join } from 'path' |
4 | import * as uuidv4 from 'uuid/v4' | 4 | import * as uuidv4 from 'uuid/v4' |
5 | import * as RateLimit from 'express-rate-limit' | ||
5 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' | 6 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' |
6 | import { retryTransactionWrapper } from '../../helpers/database-utils' | 7 | import { retryTransactionWrapper } from '../../helpers/database-utils' |
7 | import { processImage } from '../../helpers/image-utils' | 8 | import { processImage } from '../../helpers/image-utils' |
8 | import { logger } from '../../helpers/logger' | 9 | import { logger } from '../../helpers/logger' |
9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' | 10 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' |
10 | import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' | 11 | import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, RATES_LIMIT, sequelizeTypescript } from '../../initializers' |
11 | import { updateActorAvatarInstance } from '../../lib/activitypub' | 12 | import { updateActorAvatarInstance } from '../../lib/activitypub' |
12 | import { sendUpdateActor } from '../../lib/activitypub/send' | 13 | import { sendUpdateActor } from '../../lib/activitypub/send' |
13 | import { Emailer } from '../../lib/emailer' | 14 | import { Emailer } from '../../lib/emailer' |
@@ -43,6 +44,11 @@ import { OAuthTokenModel } from '../../models/oauth/oauth-token' | |||
43 | import { VideoModel } from '../../models/video/video' | 44 | import { VideoModel } from '../../models/video/video' |
44 | 45 | ||
45 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) | 46 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) |
47 | const loginRateLimiter = new RateLimit({ | ||
48 | windowMs: RATES_LIMIT.LOGIN.WINDOW_MS, | ||
49 | max: RATES_LIMIT.LOGIN.MAX, | ||
50 | delayMs: 0 | ||
51 | }) | ||
46 | 52 | ||
47 | const usersRouter = express.Router() | 53 | const usersRouter = express.Router() |
48 | 54 | ||
@@ -136,7 +142,11 @@ usersRouter.post('/:id/reset-password', | |||
136 | asyncMiddleware(resetUserPassword) | 142 | asyncMiddleware(resetUserPassword) |
137 | ) | 143 | ) |
138 | 144 | ||
139 | usersRouter.post('/token', token, success) | 145 | usersRouter.post('/token', |
146 | loginRateLimiter, | ||
147 | token, | ||
148 | success | ||
149 | ) | ||
140 | // TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route | 150 | // TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route |
141 | 151 | ||
142 | // --------------------------------------------------------------------------- | 152 | // --------------------------------------------------------------------------- |