Skip to content

Commit 780b21e

Browse files
author
Joshua Baert
committed
Got exec commands to return results paired with the exact test.
1 parent 11e18f2 commit 780b21e

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

db/create/new_user_from_github.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO users (github_id, first_name, last_name, email, username, picutre_url)
2+
VALUES ($1, null, null, $2, $3, $4);

db/read/user_by_github_id.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select * from users
2+
where github_id = $1;

db/start/tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CREATE TABLE ratings (
3737
);
3838

3939
INSERT INTO users (github_id, first_name, last_name, email, username, picutre_url)
40-
VALUES (null, 'bob', 'smith', 'bob@smith.com', 'bobIScool', null);
40+
VALUES ('12', 'bob', 'smith', 'bob@smith.com', 'bobIScool', null);
4141

4242
INSERT INTO katas (kyu, description, starter_code, name, examples, test_script)
4343
VALUES (8, 'var a should equal 1', 'var a = 1', 'Sumbit This', '[{"test":"Test.assertEquals(a, 1)","result":""}]', '[{"test":"Test.assertEquals(a, 0)","result":""},{"test":"Test.assertEquals(a, 2)","result":""},{"test":"Test.assertEquals(a, 1)","result":""}]');

server.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,35 @@ passport.use(new GithubStrategy({
2222
clientSecret: config.githubSecret,
2323
callbackURL: '/auth/github/callback'
2424
}, (accessToken, refreshToken, profile, done) => {
25-
// code goes here
26-
// go to database and look for profile.id
27-
// create user using profile.id
28-
return done(null, profile);
25+
db.read.user_by_github_id([profile.id], (err, user) => {
26+
console.log(user);
27+
if (err) {
28+
console.log(err);
29+
} else if (user [0]) {
30+
done(null, user);
31+
} else {
32+
console.log('attempting account creation')
33+
db.create.new_user_from_github([profile.id, profile._json.email, profile.displayName, profile._json.avatar_url],
34+
(err) => {
35+
if (err) {
36+
console.log(err);
37+
} else {
38+
db.read.user_by_github_id([profile.id], (err, newUser) => {
39+
if(err) {
40+
console.log(err);
41+
} else {
42+
console.log(newUser);
43+
done(null, newUser[0])
44+
}
45+
});
46+
}
47+
})
48+
}
49+
50+
});
51+
52+
53+
// return done(null, profile);
2954
}));
3055

3156

@@ -57,7 +82,7 @@ app.use(passport.session());
5782

5883

5984

60-
app.get('/auth/github', passport.authenticate('github'));
85+
app.get('/auth/github', passport.authenticate('github', {scope: ['user:email', 'user']}));
6186

6287
app.get('/auth/github/callback',
6388
passport.authenticate('github', {failureRedirect: '/login'}),
@@ -81,7 +106,6 @@ app.post('/solution/:kataId', kataCtrl.postSolution);
81106

82107

83108

84-
85109
app.listen(config.port, function () {
86110
console.log(`listening on port ${this.address().port}`);
87111

src/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<p class='font16-reg logo-font logo'>clonewars</p><br><br>
1313
</div>
1414
<div>
15-
<a href='http://www.github.com' style=>
15+
<a href='/auth/github' style=>
1616
<div class='button font12-reg'>
1717
<div>
1818
<!--<img src='../src/assets/imgs/ST.png' class='button-icon'>-->

0 commit comments

Comments
 (0)