-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from rosedu/53-improve-dev
Improve dev env
- Loading branch information
Showing
11 changed files
with
116 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,3 +333,34 @@ exports.refresh_challenges = function() { | |
} | ||
} | ||
} | ||
|
||
/* | ||
Adds dummy user with given id and username to db. | ||
This is used during development when multiple users are needed for testing | ||
purposes. | ||
*/ | ||
exports.add_user = function(userid, username, callback) { | ||
var u = {'id': userid, 'login': username} | ||
|
||
// Add some content for user | ||
var repo = { | ||
'name': username + '\'s cool repo', | ||
'description': 'A very nice description should be added here.', | ||
'html_url': 'http://www.github.com', | ||
'fork': true, | ||
'forks_count': 3, | ||
'watchers_count': 5, | ||
'closed_pulls': 3, | ||
} | ||
var update = { | ||
'user_id': u.id, | ||
'user_name': u.login, | ||
'user_fullname': 'Development user', | ||
'user_email': '[email protected]', | ||
'avatar_url': 'https://avatars.githubusercontent.com/u/0', | ||
'location': 'Somewhere', | ||
'repos': [repo] | ||
} | ||
|
||
Users.update({'user_id': u.id}, update, {'upsert': true}).exec(callback) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "rosedu-challenge.notifications" } ] } |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,64 +58,17 @@ exports.index = function(req, res) { | |
|
||
|
||
/* | ||
Login with or without GitHub auth. | ||
This will provide a session and create a new user if necessary. | ||
Visit /login/$USER to login as $USER. | ||
Show login button or redirect to page if user already logged in. | ||
*/ | ||
exports.login = function(req, res) { | ||
// Use an offline account. Add user if not existent. | ||
if (global.config.status == 'dev') { | ||
if (!req.params.user) { | ||
// If no username provided, redirect to default. | ||
return res.redirect('/login/dev_user'); | ||
|
||
} else { | ||
// Create default user with given name and autogenerated id. | ||
var u = {id: parseInt(req.params.user, 36), login: req.params.user}; | ||
|
||
// Add some content for user | ||
var repo = { | ||
name: req.params.user + '\'s cool repo', | ||
description: 'A very nice description should be added here.', | ||
html_url: 'http://www.github.com', | ||
fork: true, | ||
forks_count: 3, | ||
watchers_count: 5, | ||
closed_pulls: 3, | ||
}; | ||
var update = { | ||
user_id: u.id, | ||
user_name: u.login, | ||
user_fullname: 'Development user', | ||
user_email: '[email protected]', | ||
avatar_url: 'https://avatars.githubusercontent.com/u/0', | ||
location: 'Somewhere', | ||
repos: [repo] | ||
}; | ||
|
||
// Make sure user exists and build session for him. | ||
Users.update({user_id: u.id}, update, {upsert: true}, function(err, num) { | ||
req.session.regenerate(function (err) { | ||
req.session.auth = {}; | ||
req.session.auth.loggedIn = true; | ||
req.session.auth.github = {}; | ||
req.session.auth.github.user = u; | ||
res.redirect('/' + u.login); | ||
}); | ||
}); | ||
} | ||
|
||
// Load login or redirect user to profile page if already logged in. | ||
} else { | ||
if (req.session.auth) | ||
return res.redirect('/' + req.session.auth.github.user.login); | ||
if (req.session.auth) | ||
return res.redirect('/' + req.session.auth.github.user.login); | ||
|
||
res.render('login', { | ||
'title': "Log in", | ||
'status': global.config.status, | ||
'tab': req.query.rf | ||
}); | ||
} | ||
res.render('login', { | ||
'title': "Log in", | ||
'status': global.config.status, | ||
'tab': req.query.rf | ||
}); | ||
}; | ||
|
||
|
||
|