Skip to content

Commit 072a4e2

Browse files
committed
Merge branch 'master' into inputForm
2 parents bae4594 + 50e020e commit 072a4e2

4 files changed

Lines changed: 81 additions & 14 deletions

File tree

controllers/endPointCtrl.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const app = require('../server');
2+
const db = app.get('db');
3+
const testCtrl = require('./testCtrl');
4+
5+
module.exports = {
6+
testScript: (req, res, next) => {
7+
let script = req.body;
8+
console.log(script);
9+
let results = testCtrl.firstTest(script);
10+
console.log(results);
11+
res.json(results);
12+
}
13+
}

controllers/testCtrl.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@
77

88
const exec = require('child_process').exec;
99

10-
let script = `let addTwo = (x) => {return x+2};`;
11-
let test = `Test.assertEquals(addTwo(2), 4);`;
10+
// let script = `let addTwo = (x) => {return x+2};`;
11+
let test = `Test.assertEquals(addTwo(2), 4)`;
12+
1213

1314

1415
// This is where wer run a script.. I have verified that so long as we get it in string format we run unit tests
15-
exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
16+
// exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
17+
// (err, stdout, stderr) => {
18+
// if (err) console.log('err', err);
19+
// console.log(typeof stdout);
20+
// console.log('stdout', stdout);
21+
// console.log('stderr', stderr);
22+
// });
23+
24+
module.exports = {
25+
firstTest: (script) => {
26+
exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
1627
(err, stdout, stderr) => {
1728
if (err) console.log('err', err);
18-
console.log(typeof stdout);
19-
console.log('stdout', stdout);
20-
console.log('stderr', stderr);
29+
if (stdout) return stdout;
30+
if (stderr) return stderr;
2131
});
22-
23-
32+
}
33+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"gulp-sass": "^3.0.0",
3333
"gulp-sourcemaps": "^1.9.1",
3434
"gulp-uglify": "^2.0.0",
35-
"massive": "^2.5.0"
35+
"massive": "^2.5.0",
36+
"passport": "^0.3.2",
37+
"passport-github2": "^0.1.10"
3638
}
3739
}

server.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,68 @@ const session = require('express-session');
44
const cors = require('cors');
55
const config = require('./config.js');
66
const massive = require('massive');
7+
const passport = require('passport');
8+
const GithubStrategy = require('passport-github2').Strategy;
79
const connectionString = config.connectionString;
810

11+
passport.serializeUser((user, done) => {
12+
done(null, user);
13+
});
14+
15+
passport.deserializeUser((obj, done) => {
16+
done(null, obj);
17+
});
18+
19+
passport.use(new GithubStrategy({
20+
clientID: config.githubId,
21+
clientSecret: config.githubSecret,
22+
callbackURL: '/auth/github/callback'
23+
}, (accessToken, refreshToken, profile, done) => {
24+
// code goes here
25+
// go to database and look for profile.id
26+
// create user using profile.id
27+
return done(null/*error*/, profile/*info that goes on session*/);
28+
}));
29+
30+
931
const app = module.exports = express();
1032

33+
1134
const massiveInstance = massive.connectSync({connectionString : connectionString});
1235

1336
app.use(express.static(__dirname + '/dist'));
1437
app.use(bodyParser.json());
1538
app.use(cors());
1639

17-
app.set('db', massiveInstance);
18-
19-
let db = app.get('db');
2040

2141
app.use(session({
2242
secret: config.sessionSecret,
2343
saveUninitialized: false,
2444
resave: false
2545
}));
2646

27-
app.listen(config.port, () => {
28-
console.log('listening to port', config.port);
47+
48+
app.use(passport.initialize());
49+
app.use(passport.session());
50+
51+
app.set('db', massiveInstance);
52+
const db = app.get('db');
53+
const endPointCtrl = require('./controllers/endPointCtrl');
54+
55+
app.get('/auth/github', passport.authenticate('github'));
56+
57+
app.get('/auth/github/callback',
58+
passport.authenticate('github', { failureRedirect: '/login' }),
59+
function(req, res) {
60+
// Successful authentication, redirect home.
61+
res.redirect('/');
62+
});
63+
64+
app.post('/solution', endPointCtrl.testScript);
65+
66+
67+
app.listen(config.port, function() {
68+
console.log(`listening on port ${this.address().port}`);
69+
70+
2971
});

0 commit comments

Comments
 (0)