-
Notifications
You must be signed in to change notification settings - Fork 5
/
handler.js
46 lines (45 loc) · 1.11 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var Model = require('./db/config');
var refresh = require('passport-oauth2-refresh');
module.exports = {
refresh: (req, res) => {
var id = req.params.userId;
Model.User.findOne({_id: id})
.then((result) => {
refresh.requestNewAccessToken('google', result.refresh_token,
(err, accessToken, refreshToken) => {
res.json({accessToken: accessToken});
})
})
.catch((err) => {
res.send('no token available');
});
},
getUsers: (req, res) => {
var users = [];
Model.User.find({})
.then((result) => {
result.forEach((value) => {
if (!!value.refresh_token) users.push(value._id);
});
res.json(users);
})
.catch((err) => {
res.send('err in finding user');
});
},
logOut: (req, res) => {
req.session.destroy(() => {
res.redirect('/#/');
});
},
dropTable: (req, res) => {
Model.User.remove(function (err, result) {
if (err) {
console.log('err is', err);
} else {
console.log('result is', result);
}
});
res.send('table dropped');
}
}