mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<h1><i class="fa fa-facebook-square"></i> Facebook Social Authentication</h1>
|
||||
<hr />
|
||||
|
||||
<form>
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
Create a <strong>Facebook Application</strong> via the
|
||||
<a href="https://developers.facebook.com/">Facebook Developers Page</a> and
|
||||
then paste your application details here.
|
||||
</p>
|
||||
<br />
|
||||
<input type="text" data-field="social:facebook:app_id" title="Application ID" class="form-control input-lg" placeholder="App ID"><br />
|
||||
<input type="text" data-field="social:facebook:secret" title="Application Secret" class="form-control input-md" placeholder="App Secret"><br />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<button class="btn btn-lg btn-primary" id="save">Save</button>
|
||||
|
||||
<script>
|
||||
require(['forum/admin/settings'], function(Settings) {
|
||||
Settings.prepare();
|
||||
});
|
||||
</script>
|
||||
@@ -1,23 +0,0 @@
|
||||
<h1><i class="fa fa-google-plus-square"></i> Google Accounts Social Authentication</h1>
|
||||
<hr />
|
||||
|
||||
<form>
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
Create a <strong>Google Application</strong> via the
|
||||
<a href="https://code.google.com/apis/console/">API Console</a> and then paste
|
||||
your application details here.
|
||||
</p>
|
||||
<br />
|
||||
<input type="text" data-field="social:google:id" title="Client ID" class="form-control input-lg" placeholder="Client ID"><br />
|
||||
<input type="text" data-field="social:google:secret" title="Client Secret" class="form-control" placeholder="Client Secret"><br />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<button class="btn btn-lg btn-primary" id="save">Save</button>
|
||||
|
||||
<script>
|
||||
require(['forum/admin/settings'], function(Settings) {
|
||||
Settings.prepare();
|
||||
});
|
||||
</script>
|
||||
@@ -115,9 +115,6 @@
|
||||
<div class="well sidebar-nav">
|
||||
<ul class="nav nav-list">
|
||||
<li class="nav-header">Social Authentication</li>
|
||||
<li><a href="{relative_path}/admin/twitter"><i class="fa fa-fw fa-twitter-square"></i> Twitter</a></li>
|
||||
<li><a href="{relative_path}/admin/facebook"><i class="fa fa-fw fa-facebook-square"></i> Facebook</a></li>
|
||||
<li><a href="{relative_path}/admin/gplus"><i class="fa fa-fw fa-google-plus-square"></i> Google+</a></li>
|
||||
<!-- BEGIN authentication -->
|
||||
<li>
|
||||
<a href="{relative_path}/admin{authentication.route}"><i class="fa fa-fw {authentication.icon}"></i> {authentication.name}</a>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<h1><i class="fa fa-twitter-square"></i> Twitter Social Authentication</h1>
|
||||
<hr />
|
||||
|
||||
<form>
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
Create a <strong>Twitter Application</strong> via the
|
||||
<a href="https://dev.twitter.com/">Twitter Developers Page</a> and then
|
||||
paste your application details here.
|
||||
</p>
|
||||
<br />
|
||||
<input type="text" data-field="social:twitter:key" title="Consumer Key" class="form-control input-lg" placeholder="Consumer Key"><br />
|
||||
<input type="text" data-field="social:twitter:secret" title="Consumer Secret" class="form-control input-md" placeholder="Consumer Secret">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<button class="btn btn-lg btn-primary" id="save">Save</button>
|
||||
|
||||
<script>
|
||||
require(['forum/admin/settings'], function(Settings) {
|
||||
Settings.prepare();
|
||||
});
|
||||
</script>
|
||||
@@ -11,10 +11,7 @@
|
||||
"^admin/plugins/?$": "admin/plugins",
|
||||
"^admin/languages/?$": "admin/languages",
|
||||
"^admin/settings.*": "admin/settings",
|
||||
"^admin/twitter.*": "admin/twitter",
|
||||
"^admin/facebook.*": "admin/facebook",
|
||||
"^admin/logger.*": "admin/logger",
|
||||
"^admin/gplus.*": "admin/gplus",
|
||||
"^admin/motd/?$": "admin/motd",
|
||||
"^admin/groups/?$": "admin/groups",
|
||||
"^users/sort-posts": "users",
|
||||
|
||||
125
src/login.js
125
src/login.js
@@ -56,129 +56,4 @@ var user = require('./user'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Login.loginViaTwitter = function(twid, handle, photos, callback) {
|
||||
user.getUidByTwitterId(twid, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (uid !== null) {
|
||||
// Existing User
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
// New User
|
||||
user.create({username: handle}, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Save twitter-specific information to the user
|
||||
user.setUserField(uid, 'twid', twid);
|
||||
db.setObjectField('twid:uid', twid, uid);
|
||||
|
||||
// Save their photo, if present
|
||||
if (photos && photos.length > 0) {
|
||||
var photoUrl = photos[0].value;
|
||||
photoUrl = path.dirname(photoUrl) + '/' + path.basename(photoUrl, path.extname(photoUrl)).slice(0, -6) + 'bigger' + path.extname(photoUrl);
|
||||
user.setUserField(uid, 'uploadedpicture', photoUrl);
|
||||
user.setUserField(uid, 'picture', photoUrl);
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Login.loginViaGoogle = function(gplusid, handle, email, callback) {
|
||||
user.getUidByGoogleId(gplusid, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (uid !== null) {
|
||||
// Existing User
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
// New User
|
||||
var success = function(uid) {
|
||||
// Save google-specific information to the user
|
||||
user.setUserField(uid, 'gplusid', gplusid);
|
||||
db.setObjectField('gplusid:uid', gplusid, uid);
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
};
|
||||
|
||||
user.getUidByEmail(email, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
user.create({username: handle, email: email}, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
success(uid);
|
||||
});
|
||||
} else {
|
||||
success(uid); // Existing account -- merge
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Login.loginViaFacebook = function(fbid, name, email, callback) {
|
||||
user.getUidByFbid(fbid, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (uid !== null) {
|
||||
// Existing User
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
// New User
|
||||
var success = function(uid) {
|
||||
// Save facebook-specific information to the user
|
||||
user.setUserField(uid, 'fbid', fbid);
|
||||
db.setObjectField('fbid:uid', fbid, uid);
|
||||
callback(null, {
|
||||
uid: uid
|
||||
});
|
||||
};
|
||||
|
||||
user.getUidByEmail(email, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
user.create({username: name, email: email}, function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
success(uid);
|
||||
});
|
||||
} else {
|
||||
success(uid); // Existing account -- merge
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}(exports));
|
||||
|
||||
@@ -58,8 +58,7 @@ var nconf = require('nconf'),
|
||||
(function () {
|
||||
var routes = [
|
||||
'categories/active', 'categories/disabled', 'users', 'topics', 'settings', 'themes',
|
||||
'twitter', 'facebook', 'gplus', 'database', 'events', 'motd', 'groups', 'plugins',
|
||||
'languages', 'logger',
|
||||
'database', 'events', 'motd', 'groups', 'plugins', 'languages', 'logger',
|
||||
'users/latest', 'users/sort-posts', 'users/sort-reputation', 'users/search'
|
||||
];
|
||||
|
||||
@@ -409,18 +408,6 @@ var nconf = require('nconf'),
|
||||
res.json(200, {});
|
||||
});
|
||||
|
||||
app.get('/twitter', function (req, res) {
|
||||
res.json(200, {});
|
||||
});
|
||||
|
||||
app.get('/facebook', function (req, res) {
|
||||
res.json(200, {});
|
||||
});
|
||||
|
||||
app.get('/gplus', function (req, res) {
|
||||
res.json(200, {});
|
||||
});
|
||||
|
||||
app.get('/testing/categories', function (req, res) {
|
||||
res.json(200, {});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
(function(Auth) {
|
||||
var passport = require('passport'),
|
||||
passportLocal = require('passport-local').Strategy,
|
||||
passportTwitter = require('passport-twitter').Strategy,
|
||||
passportGoogle = require('passport-google-oauth').OAuth2Strategy,
|
||||
passportFacebook = require('passport-facebook').Strategy,
|
||||
login_strategies = [],
|
||||
nconf = require('nconf'),
|
||||
meta = require('../meta'),
|
||||
@@ -32,75 +29,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
if (meta.config['social:twitter:key'] && meta.config['social:twitter:secret']) {
|
||||
passport.use(new passportTwitter({
|
||||
consumerKey: meta.config['social:twitter:key'],
|
||||
consumerSecret: meta.config['social:twitter:secret'],
|
||||
callbackURL: nconf.get('url') + '/auth/twitter/callback'
|
||||
}, function(token, tokenSecret, profile, done) {
|
||||
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
|
||||
login_strategies.push({
|
||||
name: 'twitter',
|
||||
url: '/auth/twitter',
|
||||
callbackURL: '/auth/twitter/callback',
|
||||
icon: 'twitter',
|
||||
scope: ''
|
||||
});
|
||||
}
|
||||
|
||||
if (meta.config['social:google:id'] && meta.config['social:google:secret']) {
|
||||
passport.use(new passportGoogle({
|
||||
clientID: meta.config['social:google:id'],
|
||||
clientSecret: meta.config['social:google:secret'],
|
||||
callbackURL: nconf.get('url') + '/auth/google/callback'
|
||||
}, function(accessToken, refreshToken, profile, done) {
|
||||
login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
|
||||
login_strategies.push({
|
||||
name: 'google',
|
||||
url: '/auth/google',
|
||||
callbackURL: '/auth/google/callback',
|
||||
icon: 'google-plus',
|
||||
scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
|
||||
});
|
||||
}
|
||||
|
||||
if (meta.config['social:facebook:app_id'] && meta.config['social:facebook:secret']) {
|
||||
passport.use(new passportFacebook({
|
||||
clientID: meta.config['social:facebook:app_id'],
|
||||
clientSecret: meta.config['social:facebook:secret'],
|
||||
callbackURL: nconf.get('url') + '/auth/facebook/callback'
|
||||
}, function(accessToken, refreshToken, profile, done) {
|
||||
login_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
|
||||
login_strategies.push({
|
||||
name: 'facebook',
|
||||
url: '/auth/facebook',
|
||||
callbackURL: '/auth/facebook/callback',
|
||||
icon: 'facebook',
|
||||
scope: 'email'
|
||||
});
|
||||
}
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
done(null, user.uid);
|
||||
});
|
||||
|
||||
27
src/user.js
27
src/user.js
@@ -742,33 +742,6 @@ var bcrypt = require('bcryptjs'),
|
||||
});
|
||||
};
|
||||
|
||||
User.getUidByTwitterId = function(twid, callback) {
|
||||
db.getObjectField('twid:uid', twid, function(err, uid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, uid);
|
||||
});
|
||||
};
|
||||
|
||||
User.getUidByGoogleId = function(gplusid, callback) {
|
||||
db.getObjectField('gplusid:uid', gplusid, function(err, uid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, uid);
|
||||
});
|
||||
};
|
||||
|
||||
User.getUidByFbid = function(fbid, callback) {
|
||||
db.getObjectField('fbid:uid', fbid, function(err, uid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, uid);
|
||||
});
|
||||
};
|
||||
|
||||
User.isModerator = function(uid, cid, callback) {
|
||||
db.isSetMember('cid:' + cid + ':moderators', uid, function(err, exists) {
|
||||
if(err) {
|
||||
|
||||
Reference in New Issue
Block a user