mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
modularized SSO, paving the way for potential plugins. cleaned up associated templates/js
This commit is contained in:
@@ -2,23 +2,6 @@ define(function() {
|
|||||||
var Login = {};
|
var Login = {};
|
||||||
|
|
||||||
Login.init = function() {
|
Login.init = function() {
|
||||||
// Alternate Logins
|
|
||||||
var altLoginEl = document.querySelector('.alt-logins');
|
|
||||||
altLoginEl.addEventListener('click', function(e) {
|
|
||||||
var target;
|
|
||||||
switch (e.target.nodeName) {
|
|
||||||
case 'LI':
|
|
||||||
target = e.target;
|
|
||||||
break;
|
|
||||||
case 'I':
|
|
||||||
target = e.target.parentNode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (target) {
|
|
||||||
document.location.href = target.getAttribute('data-url');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#login').on('click', function() {
|
$('#login').on('click', function() {
|
||||||
var loginData = {
|
var loginData = {
|
||||||
'username': $('#username').val(),
|
'username': $('#username').val(),
|
||||||
|
|||||||
@@ -134,11 +134,6 @@ define(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Alternate Logins
|
|
||||||
$('.alt-logins li').on('click', function(e) {
|
|
||||||
document.location.href = $(this).attr('data-url');
|
|
||||||
});
|
|
||||||
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
validationError = false;
|
validationError = false;
|
||||||
|
|
||||||
|
|||||||
@@ -49,14 +49,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6 {alternate_logins:display}">
|
<!-- IF alternate_logins -->
|
||||||
|
<div class="col-md-6">
|
||||||
<div class="well well-lg">
|
<div class="well well-lg">
|
||||||
<h4>[[login:alternative_logins]]</h4>
|
<h4>[[login:alternative_logins]]</h4>
|
||||||
<ul class="alt-logins">
|
<ul class="alt-logins">
|
||||||
<li data-url="/auth/twitter" class="twitter {twitter:display}"><i class="fa fa-twitter-square fa-3x"></i></li>
|
<!-- BEGIN authentication -->
|
||||||
<li data-url="/auth/google" class="google {google:display}"><i class="fa fa-google-plus-square fa-3x"></i></li>
|
<li class="{authentication.name}"><a rel="nofollow" href="{authentication.url}"><i class="fa fa-{authentication.icon}-square fa-3x"></i></a></li>
|
||||||
<li data-url="/auth/facebook" class="facebook {facebook:display}"><i class="fa fa-facebook-square fa-3x"></i></li>
|
<!-- END authentication -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- ENDIF alternate_logins -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -69,14 +69,17 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 {alternate_logins:display}">
|
|
||||||
|
<!-- IF alternate_logins -->
|
||||||
|
<div class="col-md-6">
|
||||||
<div class="well well-lg">
|
<div class="well well-lg">
|
||||||
<h4>[[register:alternative_registration]]</h4>
|
<h4>[[register:alternative_registration]]</h4>
|
||||||
<ul class="alt-logins">
|
<ul class="alt-logins">
|
||||||
<li data-url="/auth/twitter" class="twitter {twitter:display}"><i class="fa fa-twitter-square fa-3x"></i></li>
|
<!-- BEGIN authentication -->
|
||||||
<li data-url="/auth/google" class="google {google:display}"><i class="fa fa-google-plus-square fa-3x"></i></li>
|
<li class="{authentication.name}"><a rel="nofollow" href="{authentication.url}"><i class="fa fa-{authentication.icon}-square fa-3x"></i></a></li>
|
||||||
<li data-url="/auth/facebook" class="facebook {facebook:display}"><i class="fa fa-facebook-square fa-3x"></i></li>
|
<!-- END authentication -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- ENDIF alternate_logins -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -72,18 +72,17 @@ var user = require('../user'),
|
|||||||
if (num_strategies == 0) {
|
if (num_strategies == 0) {
|
||||||
data = {
|
data = {
|
||||||
'login_window:spansize': 'col-md-12',
|
'login_window:spansize': 'col-md-12',
|
||||||
'alternate_logins:display': 'none'
|
'alternate_logins': false
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
data = {
|
data = {
|
||||||
'login_window:spansize': 'col-md-6',
|
'login_window:spansize': 'col-md-6',
|
||||||
'alternate_logins:display': 'block'
|
'alternate_logins': true
|
||||||
}
|
|
||||||
for (var i = 0, ii = num_strategies; i < ii; i++) {
|
|
||||||
data[login_strategies[i] + ':display'] = 'active';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.authentication = login_strategies;
|
||||||
|
|
||||||
data.token = res.locals.csrf_token;
|
data.token = res.locals.csrf_token;
|
||||||
|
|
||||||
res.json(data);
|
res.json(data);
|
||||||
@@ -97,18 +96,17 @@ var user = require('../user'),
|
|||||||
if (num_strategies == 0) {
|
if (num_strategies == 0) {
|
||||||
data = {
|
data = {
|
||||||
'register_window:spansize': 'col-md-12',
|
'register_window:spansize': 'col-md-12',
|
||||||
'alternate_logins:display': 'none'
|
'alternate_logins': false
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
data = {
|
data = {
|
||||||
'register_window:spansize': 'col-md-6',
|
'register_window:spansize': 'col-md-6',
|
||||||
'alternate_logins:display': 'block'
|
'alternate_logins': true
|
||||||
}
|
|
||||||
for (var i = 0, ii = num_strategies; i < ii; i++) {
|
|
||||||
data[login_strategies[i] + ':display'] = 'active';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.authentication = login_strategies;
|
||||||
|
|
||||||
data.token = res.locals.csrf_token;
|
data.token = res.locals.csrf_token;
|
||||||
data.minimumUsernameLength = meta.config['minimumUsernameLength'];
|
data.minimumUsernameLength = meta.config['minimumUsernameLength'];
|
||||||
data.maximumUsernameLength = meta.config['maximumUsernameLength'];
|
data.maximumUsernameLength = meta.config['maximumUsernameLength'];
|
||||||
|
|||||||
@@ -32,7 +32,13 @@
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
login_strategies.push('twitter');
|
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']) {
|
if (meta.config['social:google:id'] && meta.config['social:google:secret']) {
|
||||||
@@ -49,7 +55,13 @@
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
login_strategies.push('google');
|
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']) {
|
if (meta.config['social:facebook:app_id'] && meta.config['social:facebook:secret']) {
|
||||||
@@ -66,7 +78,13 @@
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
login_strategies.push('facebook');
|
login_strategies.push({
|
||||||
|
name: 'facebook',
|
||||||
|
url: '/auth/facebook',
|
||||||
|
callbackURL: '/auth/facebook/callback',
|
||||||
|
icon: 'facebook',
|
||||||
|
scope: 'email'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
passport.serializeUser(function(user, done) {
|
passport.serializeUser(function(user, done) {
|
||||||
@@ -103,38 +121,18 @@
|
|||||||
res.send(200)
|
res.send(200)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (login_strategies.indexOf('twitter') !== -1) {
|
for (var i in login_strategies) {
|
||||||
app.get('/auth/twitter', passport.authenticate('twitter'));
|
var strategy = login_strategies[i];
|
||||||
|
app.get(strategy.url, passport.authenticate(strategy.name, {
|
||||||
|
scope: strategy.scope
|
||||||
|
}));
|
||||||
|
|
||||||
app.get('/auth/twitter/callback', passport.authenticate('twitter', {
|
app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
|
||||||
successRedirect: '/',
|
successRedirect: '/',
|
||||||
failureRedirect: '/login'
|
failureRedirect: '/login'
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (login_strategies.indexOf('google') !== -1) {
|
|
||||||
app.get('/auth/google', passport.authenticate('google', {
|
|
||||||
scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.get('/auth/google/callback', passport.authenticate('google', {
|
|
||||||
successRedirect: '/',
|
|
||||||
failureRedirect: '/login'
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (login_strategies.indexOf('facebook') !== -1) {
|
|
||||||
app.get('/auth/facebook', passport.authenticate('facebook', {
|
|
||||||
scope: 'email'
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
|
|
||||||
successRedirect: '/',
|
|
||||||
failureRedirect: '/login'
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.get('/reset/:code', function(req, res) {
|
app.get('/reset/:code', function(req, res) {
|
||||||
app.build_header({
|
app.build_header({
|
||||||
|
|||||||
Reference in New Issue
Block a user