forked from ionicc/Github-organization-inviter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
75 lines (64 loc) · 2.05 KB
/
Copy pathmain.js
File metadata and controls
75 lines (64 loc) · 2.05 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env nodejs
var express = require('express');
var app = express();
var http = require('http').Server(app);
const Octokit = require('@octokit/rest');
var bodyParser = require('body-parser');
var expressIp = require('express-ip');
/*
------------------------------
ENTER YOUR ORGANIZATION NAME
AND
ENTER YOUR GITHUB ACCESS TOKEN
------------------------------
*/
const ORGANIZATION = '';
const TOKEN = ''
var PORT = 8000 || process.env.PORT;
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressIp().getIpInfoMiddleware);
app.set('PORT', PORT);
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
const userInfo = req.ipInfo;
console.log('User connected from %s, %s', userInfo.city, userInfo.country);
console.log('User details = %o', userInfo);
});
app.get('/input_data', function(req,res) {
res.sendFile(__dirname + '/index.html');
});
var client = Octokit({
auth: TOKEN
});
app.post('/input_data',(req,res) => {
if(req.body.handle === '') res.redirect('back');
client.users
.getByUsername({
username: req.body.handle
})
.then((userdata) => {
client.orgs
.createInvitation({
org: ORGANIZATION,
email: req.body.email
})
.then((invitationData) => {
console.log(invitationData);
console.log('Invitation sent to %s At : %s', req.body.handle, req.body.email);
res.send(`Invitation sent to ${req.body.handle} At : ${req.body.email}`);
})
.catch((error) => {
console.log('Invitation failed %o', error)
res.redirect('back')
})
console.log(userdata)
})
.catch((error) => {
console.log('User not found %o', error)
res.redirect('back')
});
});
http.listen(app.get('PORT'),function(){
console.log('listening on : %s', app.get('PORT'));
});