aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/users.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-05 16:09:39 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-05 16:09:39 +0200
commit6606150c49f587bc7eb0ecec4263ce7fbb18bf15 (patch)
tree6e0c13983e667e08dcc1dfb6fcda1524b6920c6a /server/controllers/api/v1/users.js
parent9bd2662976a75d3b03364cdbe6419e57c80f99a6 (diff)
downloadPeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.tar.gz
PeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.tar.zst
PeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.zip
Server: move clients in its own file
Diffstat (limited to 'server/controllers/api/v1/users.js')
-rw-r--r--server/controllers/api/v1/users.js28
1 files changed, 1 insertions, 27 deletions
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js
index e084974ce..fdbcc3ff5 100644
--- a/server/controllers/api/v1/users.js
+++ b/server/controllers/api/v1/users.js
@@ -1,7 +1,6 @@
1'use strict' 1'use strict'
2 2
3const each = require('async/each') 3const each = require('async/each')
4const config = require('config')
5const express = require('express') 4const express = require('express')
6const mongoose = require('mongoose') 5const mongoose = require('mongoose')
7const waterfall = require('async/waterfall') 6const waterfall = require('async/waterfall')
@@ -14,7 +13,6 @@ const admin = middlewares.admin
14const oAuth = middlewares.oauth 13const oAuth = middlewares.oauth
15const validatorsUsers = middlewares.validators.users 14const validatorsUsers = middlewares.validators.users
16 15
17const Client = mongoose.model('OAuthClient')
18const User = mongoose.model('User') 16const User = mongoose.model('User')
19const Video = mongoose.model('Video') 17const Video = mongoose.model('Video')
20 18
@@ -41,7 +39,7 @@ router.delete('/:username',
41 validatorsUsers.usersRemove, 39 validatorsUsers.usersRemove,
42 removeUser 40 removeUser
43) 41)
44router.get('/client', getAngularClient) 42
45router.post('/token', oAuth.token, success) 43router.post('/token', oAuth.token, success)
46// TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route 44// TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route
47 45
@@ -65,30 +63,6 @@ function createUser (req, res, next) {
65 }) 63 })
66} 64}
67 65
68function getAngularClient (req, res, next) {
69 const serverHost = config.get('webserver.host')
70 const serverPort = config.get('webserver.port')
71 let headerHostShouldBe = serverHost
72 if (serverPort !== 80 && serverPort !== 443) {
73 headerHostShouldBe += ':' + serverPort
74 }
75
76 // Don't make this check if this is a test instance
77 if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) {
78 return res.type('json').status(403).end()
79 }
80
81 Client.loadFirstClient(function (err, client) {
82 if (err) return next(err)
83 if (!client) return next(new Error('No client available.'))
84
85 res.json({
86 client_id: client._id,
87 client_secret: client.clientSecret
88 })
89 })
90}
91
92function listUsers (req, res, next) { 66function listUsers (req, res, next) {
93 User.list(function (err, usersList) { 67 User.list(function (err, usersList) {
94 if (err) return next(err) 68 if (err) return next(err)