From 69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 1 Jul 2016 16:03:53 +0200 Subject: OAuth/User models refractoring -> use mongoose api --- server/controllers/api/v1/pods.js | 6 +++--- server/controllers/api/v1/users.js | 9 +++++---- server/controllers/api/v1/videos.js | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js index feb6bd958..9ce8120b2 100644 --- a/server/controllers/api/v1/pods.js +++ b/server/controllers/api/v1/pods.js @@ -7,7 +7,7 @@ const mongoose = require('mongoose') const logger = require('../../../helpers/logger') const friends = require('../../../lib/friends') const middlewares = require('../../../middlewares') -const oAuth2 = middlewares.oauth2 +const oAuth = middlewares.oauth const reqValidator = middlewares.reqValidators.pods const signatureValidator = middlewares.reqValidators.remote.signature @@ -17,8 +17,8 @@ const Video = mongoose.model('Video') router.get('/', listPodsUrl) router.post('/', reqValidator.podsAdd, addPods) -router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends) -router.get('/quitfriends', oAuth2.authenticate, quitFriends) +router.get('/makefriends', oAuth.authenticate, reqValidator.makeFriends, makeFriends) +router.get('/quitfriends', oAuth.authenticate, quitFriends) // Post because this is a secured request router.post('/remove', signatureValidator, removePods) diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js index 7ce0b9c6a..caa979567 100644 --- a/server/controllers/api/v1/users.js +++ b/server/controllers/api/v1/users.js @@ -1,15 +1,16 @@ 'use strict' const config = require('config') +const mongoose = require('mongoose') const express = require('express') -const oAuth2 = require('../../../middlewares').oauth2 +const oAuth = require('../../../middlewares').oauth -const Users = require('../../../models/users') +const Client = mongoose.model('OAuthClient') const router = express.Router() router.get('/client', getAngularClient) -router.post('/token', oAuth2.token, success) +router.post('/token', oAuth.token, success) // --------------------------------------------------------------------------- @@ -27,7 +28,7 @@ function getAngularClient (req, res, next) { if (req.get('host') !== headerHostShouldBe) return res.type('json').status(403).end() - Users.getFirstClient(function (err, client) { + Client.loadFirstClient(function (err, client) { if (err) return next(err) if (!client) return next(new Error('No client available.')) diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index d06ec8d08..ab115bc30 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js @@ -9,7 +9,7 @@ const multer = require('multer') const logger = require('../../../helpers/logger') const friends = require('../../../lib/friends') const middlewares = require('../../../middlewares') -const oAuth2 = middlewares.oauth2 +const oAuth = middlewares.oauth const pagination = middlewares.pagination const reqValidator = middlewares.reqValidators const reqValidatorPagination = reqValidator.pagination @@ -51,7 +51,7 @@ router.get('/', listVideos ) router.post('/', - oAuth2.authenticate, + oAuth.authenticate, reqFiles, reqValidatorVideos.videosAdd, addVideo @@ -61,7 +61,7 @@ router.get('/:id', getVideo ) router.delete('/:id', - oAuth2.authenticate, + oAuth.authenticate, reqValidatorVideos.videosRemove, removeVideo ) -- cgit v1.2.3