diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-04-14 22:06:11 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-04-14 22:06:11 +0200 |
commit | 0c1cbbfe29d91c95f9c574b57adf067654b8b5b4 (patch) | |
tree | b61e48caedea8881cbfd1159295f6c311b35be90 /server/controllers/api | |
parent | c9bf7d30bd688e84b12dca03029dde6e9645a997 (diff) | |
download | PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.gz PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.zst PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.zip |
Add authentications for routes that need it and adapts the tests
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/v1/users.js | 7 | ||||
-rw-r--r-- | server/controllers/api/v1/videos.js | 11 |
2 files changed, 10 insertions, 8 deletions
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js index acb860c66..f45b47077 100644 --- a/server/controllers/api/v1/users.js +++ b/server/controllers/api/v1/users.js | |||
@@ -1,15 +1,14 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | var express = require('express') | 3 | const express = require('express') |
4 | var oAuth2 = require('../../../middlewares/oauth2') | 4 | const oAuth2 = require('../../../middlewares/oauth2') |
5 | 5 | ||
6 | const middleware = require('../../../middlewares') | 6 | const middleware = require('../../../middlewares') |
7 | const cacheMiddleware = middleware.cache | 7 | const cacheMiddleware = middleware.cache |
8 | 8 | ||
9 | const router = express.Router() | 9 | const router = express.Router() |
10 | 10 | ||
11 | router.post('/token', cacheMiddleware.cache(false), oAuth2.token(), success) | 11 | router.post('/token', cacheMiddleware.cache(false), oAuth2.token, success) |
12 | router.get('/authenticate', cacheMiddleware.cache(false), oAuth2.authenticate(), success) | ||
13 | 12 | ||
14 | // --------------------------------------------------------------------------- | 13 | // --------------------------------------------------------------------------- |
15 | 14 | ||
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index 97d3e6b5a..d25ca95f7 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js | |||
@@ -8,6 +8,7 @@ const multer = require('multer') | |||
8 | const logger = require('../../../helpers/logger') | 8 | const logger = require('../../../helpers/logger') |
9 | const friends = require('../../../lib/friends') | 9 | const friends = require('../../../lib/friends') |
10 | const middleware = require('../../../middlewares') | 10 | const middleware = require('../../../middlewares') |
11 | const oAuth2 = require('../../../middlewares/oauth2') | ||
11 | const cacheMiddleware = middleware.cache | 12 | const cacheMiddleware = middleware.cache |
12 | const reqValidator = middleware.reqValidators.videos | 13 | const reqValidator = middleware.reqValidators.videos |
13 | const Videos = require('../../../models/videos') // model | 14 | const Videos = require('../../../models/videos') // model |
@@ -38,9 +39,9 @@ const storage = multer.diskStorage({ | |||
38 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) | 39 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) |
39 | 40 | ||
40 | router.get('/', cacheMiddleware.cache(false), listVideos) | 41 | router.get('/', cacheMiddleware.cache(false), listVideos) |
41 | router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) | 42 | router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) |
42 | router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) | 43 | router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) |
43 | router.delete('/:id', reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) | 44 | router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) |
44 | router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) | 45 | router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) |
45 | 46 | ||
46 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
@@ -63,7 +64,8 @@ function addVideo (req, res, next) { | |||
63 | name: video_infos.name, | 64 | name: video_infos.name, |
64 | namePath: video_file.filename, | 65 | namePath: video_file.filename, |
65 | description: video_infos.description, | 66 | description: video_infos.description, |
66 | magnetUri: torrent.magnetURI | 67 | magnetUri: torrent.magnetURI, |
68 | author: res.locals.oauth.token.user.username | ||
67 | } | 69 | } |
68 | 70 | ||
69 | Videos.add(video_data, function (err) { | 71 | Videos.add(video_data, function (err) { |
@@ -141,7 +143,8 @@ function getFormatedVideo (video_obj) { | |||
141 | description: video_obj.description, | 143 | description: video_obj.description, |
142 | podUrl: video_obj.podUrl, | 144 | podUrl: video_obj.podUrl, |
143 | isLocal: videos.getVideoState(video_obj).owned, | 145 | isLocal: videos.getVideoState(video_obj).owned, |
144 | magnetUri: video_obj.magnetUri | 146 | magnetUri: video_obj.magnetUri, |
147 | author: video_obj.author | ||
145 | } | 148 | } |
146 | 149 | ||
147 | return formated_video | 150 | return formated_video |