forked from OpenUserJS/OpenUserJS.org
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage the authentication strategy keys for OAuth via a webpage.
- Loading branch information
1 parent
29d5b85
commit c3b6596
Showing
9 changed files
with
157 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
var Strategy = require('../models/strategies.js').Strategy; | ||
var User = require('../models/user.js').User; | ||
var strategies = require('./strategies.json'); | ||
|
||
function userIsAdmin(req) { | ||
return req.session.user && req.session.user.role < 3; | ||
} | ||
|
||
function getOAuthStrategies(stored) { | ||
var oAuthStrats = []; | ||
for (var i in strategies) { | ||
var strategy = strategies[i]; | ||
if (strategy.oauth) { | ||
oAuthStrats.push(stored[i] || { 'strat' : i, 'id' : '', 'key' : ''}); | ||
} | ||
} | ||
|
||
return oAuthStrats; | ||
} | ||
|
||
exports.userAdmin = function(req, res) { | ||
if (!userIsAdmin(req)) res.redirect('/'); | ||
|
||
res.render('index', options, res); | ||
}; | ||
|
||
exports.apiAdmin = function(req, res) { | ||
//if (!userIsAdmin(req)) res.redirect('/'); | ||
|
||
Strategy.find({}, function(err, strats) { | ||
var stored = {}; | ||
strats.forEach(function(strat) { | ||
//strat.remove(function (err, product) {}); | ||
stored[strat.name] = { 'strat' : strat.name, | ||
'id' : strat.id, 'key' : strat.key }; | ||
}); | ||
|
||
var strategies = getOAuthStrategies(stored); | ||
var options = { 'strategies' : strategies }; | ||
|
||
res.render('apiAdmin', options, res); | ||
}); | ||
}; | ||
|
||
exports.apiAdminUpdate = function(req, res) { | ||
var postStrats = req.body; | ||
var doneCount = 0; | ||
function done() { | ||
if (!(--doneCount)) res.redirect('/admin/api'); | ||
} | ||
|
||
Strategy.find({}, function(err, strats) { | ||
var stored = {}; | ||
strats.forEach(function(strat) { | ||
stored[strat.name] = strat; | ||
}); | ||
|
||
for (var i in postStrats) { | ||
var postStrat = postStrats[i]; | ||
var strategy = null; | ||
if (postStrat[0] && postStrat[1]) { | ||
if (stored[i]) { | ||
strategy = stored[i]; | ||
strategy.id = postStrat[0] | ||
strategy.key = postStrat[1]; | ||
} else { | ||
strategy = new Strategy({ | ||
'id' : postStrat[0], | ||
'key' : postStrat[1], | ||
'name' : i, | ||
'display' : strategies[i].name | ||
}); | ||
} | ||
|
||
++doneCount; | ||
strategy.save(function() { return done(); }); | ||
} | ||
} | ||
|
||
++doneCount; | ||
done(); | ||
}); | ||
}; | ||
|
||
exports.userAdminUpdate = function(req, res) { | ||
}; |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,17 @@ | ||
[ | ||
"github", "facebook", "google", "paypal", "yahoo", "aol" | ||
] | ||
{ | ||
"github" : { "name" : "GitHub", "oauth" : true }, | ||
"facebook" : { "name" : "Facebook", "oauth" : true }, | ||
"google" : { "name" : "Google", "oauth" : false }, | ||
"paypal" : { "name" : "PayPal", "oauth" : false }, | ||
"yahoo" : { "name" : "Yahoo!", "oauth" : false }, | ||
"aol" : { "name" : "AOL", "oauth" : false }, | ||
"twitter" : { "name" : "Twitter", "oauth" : true }, | ||
"flickr" : { "name" : "Flickr", "oauth" : true }, | ||
"linkedin" : { "name" : "LinkedIn", "oauth" : true }, | ||
"netflix" : { "name" : "Netflix", "oauth" : true }, | ||
"reddit" : { "name" : "Reddit", "oauth" : true }, | ||
"imgur" : { "name" : "Imgur", "oauth" : true }, | ||
"amazon" : { "name" : "Amazon", "oauth" : true }, | ||
"windowslive" : { "name" : "Windows Live", "oauth" : true }, | ||
"openid" : { "name" : "OpenID", "oauth" : false } | ||
} |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
var strategySchema = new Schema({ | ||
id: String, | ||
key: String, | ||
name: String, | ||
display: String | ||
}); | ||
|
||
var Strategy = mongoose.model('Strategy', strategySchema); | ||
|
||
exports.Strategy = Strategy; |
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,8 @@ | ||
[ | ||
"Root", | ||
"Founding Father", | ||
"Admin", | ||
"Moderator", | ||
"Script Writer", | ||
"User" | ||
] |
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,17 @@ | ||
<html> | ||
<head> | ||
<title>Edit Authenticator Settings</title> | ||
</head> | ||
<body> | ||
<form method="post" action="/admin/api/update"> | ||
{{#strategies}} | ||
<strong>{{strat}}</strong><br /> | ||
<strong>id: </strong> | ||
<input type="text" name="{{strat}}[0]" value="{{id}}" /><br /> | ||
<strong>key: </strong> | ||
<input type="text" name="{{strat}}[1]" value="{{key}}" /><br /><br /> | ||
{{/strategies}} | ||
<input type="submit" value="Update" /> | ||
</form> | ||
</body> | ||
</html> |