anilkumarbp /
Glipped
| 1 | require('dotenv').config(); |
||
| 2 | var express = require('express'); |
||
| 3 | var path = require('path'); |
||
| 4 | var cons = require('consolidate'); |
||
| 5 | |||
| 6 | var port = 8080; |
||
| 7 | var app = module.exports = express(); |
||
| 8 | var swig = require('swig'); |
||
| 9 | |||
| 10 | // handlebars initiation |
||
| 11 | var exphbs = require('express-handlebars'); |
||
| 12 | var hbs = exphbs.create({}); |
||
| 13 | |||
| 14 | // Configure View and Handlebars |
||
| 15 | app.use(express.static(path.join(__dirname))); |
||
| 16 | app.engine('handlebars', hbs.engine); |
||
| 17 | app.set('views', path.join(__dirname, 'views')); |
||
| 18 | app.set('view engine', 'handlebars'); |
||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | // Create body parsers for application/json and application/x-www-form-urlencoded |
||
| 23 | var bodyParser = require('body-parser') |
||
| 24 | app.use(bodyParser.json()) |
||
| 25 | var urlencodedParser = bodyParser.urlencoded({ extended: false }) |
||
| 26 | |||
| 27 | if(!module.parent){ app.listen(process.env.PORT || port); } |
||
| 28 | |||
| 29 | console.log("Application started. Listening on port:" + port); |
||
|
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
| 30 | |||
| 31 | |||
| 32 | var ringcentral = require('ringcentral'); |
||
| 33 | |||
| 34 | var rcsdk = new ringcentral({ |
||
|
0 ignored issues
–
show
|
|||
| 35 | server: process.env.GLIP_APP_SERVER_URL, |
||
| 36 | appKey: process.env.GLIP_APP_KEY, |
||
| 37 | appSecret: process.env.GLIP_APP_SECRET |
||
| 38 | }); |
||
| 39 | |||
| 40 | var groupMembers; |
||
| 41 | var userList = []; |
||
| 42 | |||
| 43 | // Route for the home page |
||
| 44 | app.get('/inviteDemo', function (req, res) { |
||
| 45 | var badge = swig.renderFile(path.join(__dirname, '/views/badge.svg')); |
||
| 46 | res.writeHead(200, {"Content-Type": "image/svg+xml"}) |
||
| 47 | res.write(badge); |
||
| 48 | res.send(); |
||
| 49 | }); |
||
| 50 | // Route for the inviteDemo |
||
| 51 | app.get('/', function (req, res) { |
||
| 52 | |||
| 53 | console.log('Insdei'); |
||
|
0 ignored issues
–
show
|
|||
| 54 | rcsdk.platform() |
||
| 55 | .login({ |
||
| 56 | username: process.env.GLIP_USERNAME, |
||
| 57 | extension: process.env.GLIP_EXTENSION || null, |
||
| 58 | password: process.env.GLIP_PASSWORD |
||
| 59 | }) |
||
| 60 | .then(function(response) { |
||
|
0 ignored issues
–
show
|
|||
| 61 | console.log('Logged in to platform'); |
||
|
0 ignored issues
–
show
|
|||
| 62 | return rcsdk.platform() |
||
| 63 | .get('/glip/groups/' + process.env.GLIP_GROUP_ID) |
||
| 64 | .then(function(apiResponse) { |
||
| 65 | var response = apiResponse.json(); |
||
| 66 | if(response.members){ |
||
| 67 | groupMembers = response.members.length; |
||
| 68 | console.log(groupMembers); |
||
|
0 ignored issues
–
show
|
|||
| 69 | } |
||
| 70 | res.render('index', {RC_Logo: process.env.GLIP_LOGO, RC_Community: process.env.GLIP_GROUP_NAME, RC_Total_members: groupMembers, RC_groupId: process.env.GLIP_GROUP_ID}); |
||
|
0 ignored issues
–
show
|
|||
| 71 | }) |
||
| 72 | .catch(function(e) { |
||
| 73 | console.log('INVITE USER DID NOT WORK'); |
||
|
0 ignored issues
–
show
|
|||
| 74 | console.log(e); |
||
| 75 | }); |
||
| 76 | }) |
||
| 77 | .catch(function(e) { |
||
| 78 | console.log('ERR_CALLBACK ' + e.message || 'Server cannot authorize user'); |
||
|
0 ignored issues
–
show
|
|||
| 79 | res.send('Error'); |
||
| 80 | }); |
||
| 81 | }); |
||
| 82 | |||
| 83 | // Route for the invite user |
||
| 84 | app.post('/inviteUser', urlencodedParser, function (req, res, next) { |
||
|
0 ignored issues
–
show
|
|||
| 85 | var userInvite = [ req.body.userInvite || '' ]; |
||
| 86 | userList.push(userInvite); |
||
| 87 | rcsdk.platform().loggedIn() |
||
| 88 | .then(function(status) { |
||
|
0 ignored issues
–
show
|
|||
| 89 | return rcsdk.platform() |
||
| 90 | .post('/glip/groups/' + process.env.GLIP_GROUP_ID + '/bulk-assign',{ |
||
| 91 | "addedPersonEmails": userInvite |
||
| 92 | }) |
||
| 93 | .then(function(response) { |
||
| 94 | console.log('The response is :', response.json()); |
||
|
0 ignored issues
–
show
|
|||
| 95 | console.log('The total number of users invited to the grpup is :'+ userList.length); |
||
| 96 | console.log('The total number of users registered in the grpup is :'+response.json().members.length); |
||
| 97 | console.log("The type of data is :" + typeof userList.length); |
||
| 98 | res.send(userList.length.toString()); |
||
| 99 | }) |
||
| 100 | .catch(function(e) { |
||
| 101 | console.log('INVITE USER DID NOT WORK'); |
||
|
0 ignored issues
–
show
|
|||
| 102 | console.log(e); |
||
| 103 | }); |
||
| 104 | }) |
||
| 105 | .catch(function(e) { |
||
|
0 ignored issues
–
show
|
|||
| 106 | res.send("E_NOT_LOGGED_IN"); |
||
| 107 | }); |
||
| 108 | }); |
||
| 109 | |||
| 110 | |||
| 111 | module.exports = { |
||
| 112 | app : app |
||
| 113 | }; |
||
| 114 |