aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
commita6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch)
tree03204a408d56311692c3528bedcf95d2455e94f2 /server/lib
parent052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff)
parentc4403b29ad4db097af528a7f04eea07e0ed320d0 (diff)
downloadPeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip
Merge branch 'master' into webseed-merged
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/friends.js34
-rw-r--r--server/lib/oauth-model.js29
2 files changed, 38 insertions, 25 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 6e1516b94..556d2e773 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -1,6 +1,5 @@
1'use strict' 1'use strict'
2 2
3const config = require('config')
4const each = require('async/each') 3const each = require('async/each')
5const eachLimit = require('async/eachLimit') 4const eachLimit = require('async/eachLimit')
6const eachSeries = require('async/eachSeries') 5const eachSeries = require('async/eachSeries')
@@ -11,24 +10,20 @@ const waterfall = require('async/waterfall')
11 10
12const constants = require('../initializers/constants') 11const constants = require('../initializers/constants')
13const logger = require('../helpers/logger') 12const logger = require('../helpers/logger')
14const peertubeCrypto = require('../helpers/peertube-crypto')
15const requests = require('../helpers/requests') 13const requests = require('../helpers/requests')
16 14
17const http = config.get('webserver.https') ? 'https' : 'http'
18const host = config.get('webserver.host')
19const port = config.get('webserver.port')
20const Pod = mongoose.model('Pod') 15const Pod = mongoose.model('Pod')
21const Request = mongoose.model('Request') 16const Request = mongoose.model('Request')
22const Video = mongoose.model('Video') 17const Video = mongoose.model('Video')
23 18
24const friends = { 19const friends = {
25 addVideoToFriends: addVideoToFriends, 20 addVideoToFriends,
26 hasFriends: hasFriends, 21 hasFriends,
27 getMyCertificate: getMyCertificate, 22 getMyCertificate,
28 makeFriends: makeFriends, 23 makeFriends,
29 quitFriends: quitFriends, 24 quitFriends,
30 removeVideoToFriends: removeVideoToFriends, 25 removeVideoToFriends,
31 sendOwnedVideosToPod: sendOwnedVideosToPod 26 sendOwnedVideosToPod
32} 27}
33 28
34function addVideoToFriends (video) { 29function addVideoToFriends (video) {
@@ -45,10 +40,10 @@ function hasFriends (callback) {
45} 40}
46 41
47function getMyCertificate (callback) { 42function getMyCertificate (callback) {
48 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', callback) 43 fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback)
49} 44}
50 45
51function makeFriends (callback) { 46function makeFriends (urls, callback) {
52 const podsScore = {} 47 const podsScore = {}
53 48
54 logger.info('Make friends!') 49 logger.info('Make friends!')
@@ -58,8 +53,6 @@ function makeFriends (callback) {
58 return callback(err) 53 return callback(err)
59 } 54 }
60 55
61 const urls = config.get('network.friends')
62
63 eachSeries(urls, function (url, callbackEach) { 56 eachSeries(urls, function (url, callbackEach) {
64 computeForeignPodsList(url, podsScore, callbackEach) 57 computeForeignPodsList(url, podsScore, callbackEach)
65 }, function (err) { 58 }, function (err) {
@@ -205,7 +198,12 @@ function getForeignPodsList (url, callback) {
205 request.get(url + path, function (err, response, body) { 198 request.get(url + path, function (err, response, body) {
206 if (err) return callback(err) 199 if (err) return callback(err)
207 200
208 callback(null, JSON.parse(body)) 201 try {
202 const json = JSON.parse(body)
203 return callback(null, json)
204 } catch (err) {
205 return callback(err)
206 }
209 }) 207 })
210} 208}
211 209
@@ -220,7 +218,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
220 url: pod.url + '/api/' + constants.API_VERSION + '/pods/', 218 url: pod.url + '/api/' + constants.API_VERSION + '/pods/',
221 method: 'POST', 219 method: 'POST',
222 json: { 220 json: {
223 url: http + '://' + host + ':' + port, 221 url: constants.CONFIG.WEBSERVER.URL,
224 publicKey: cert 222 publicKey: cert
225 } 223 }
226 } 224 }
diff --git a/server/lib/oauth-model.js b/server/lib/oauth-model.js
index d9f8b175a..45f796796 100644
--- a/server/lib/oauth-model.js
+++ b/server/lib/oauth-model.js
@@ -8,12 +8,12 @@ const User = mongoose.model('User')
8 8
9// See https://github.com/oauthjs/node-oauth2-server/wiki/Model-specification for the model specifications 9// See https://github.com/oauthjs/node-oauth2-server/wiki/Model-specification for the model specifications
10const OAuthModel = { 10const OAuthModel = {
11 getAccessToken: getAccessToken, 11 getAccessToken,
12 getClient: getClient, 12 getClient,
13 getRefreshToken: getRefreshToken, 13 getRefreshToken,
14 getUser: getUser, 14 getUser,
15 revokeToken: revokeToken, 15 revokeToken,
16 saveToken: saveToken 16 saveToken
17} 17}
18 18
19// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
@@ -41,7 +41,22 @@ function getRefreshToken (refreshToken, callback) {
41function getUser (username, password) { 41function getUser (username, password) {
42 logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') 42 logger.debug('Getting User (username: ' + username + ', password: ' + password + ').')
43 43
44 return User.getByUsernameAndPassword(username, password) 44 return User.getByUsername(username).then(function (user) {
45 if (!user) return null
46
47 // We need to return a promise
48 return new Promise(function (resolve, reject) {
49 return user.isPasswordMatch(password, function (err, isPasswordMatch) {
50 if (err) return reject(err)
51
52 if (isPasswordMatch === true) {
53 return resolve(user)
54 }
55
56 return resolve(null)
57 })
58 })
59 })
45} 60}
46 61
47function revokeToken (token) { 62function revokeToken (token) {