diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 16:09:39 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 16:09:39 +0200 |
commit | 6606150c49f587bc7eb0ecec4263ce7fbb18bf15 (patch) | |
tree | 6e0c13983e667e08dcc1dfb6fcda1524b6920c6a /server/controllers/api/v1/users.js | |
parent | 9bd2662976a75d3b03364cdbe6419e57c80f99a6 (diff) | |
download | PeerTube-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.js | 28 |
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 | ||
3 | const each = require('async/each') | 3 | const each = require('async/each') |
4 | const config = require('config') | ||
5 | const express = require('express') | 4 | const express = require('express') |
6 | const mongoose = require('mongoose') | 5 | const mongoose = require('mongoose') |
7 | const waterfall = require('async/waterfall') | 6 | const waterfall = require('async/waterfall') |
@@ -14,7 +13,6 @@ const admin = middlewares.admin | |||
14 | const oAuth = middlewares.oauth | 13 | const oAuth = middlewares.oauth |
15 | const validatorsUsers = middlewares.validators.users | 14 | const validatorsUsers = middlewares.validators.users |
16 | 15 | ||
17 | const Client = mongoose.model('OAuthClient') | ||
18 | const User = mongoose.model('User') | 16 | const User = mongoose.model('User') |
19 | const Video = mongoose.model('Video') | 17 | const 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 | ) |
44 | router.get('/client', getAngularClient) | 42 | |
45 | router.post('/token', oAuth.token, success) | 43 | router.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 | ||
68 | function 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 | |||
92 | function listUsers (req, res, next) { | 66 | function 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) |