mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
Merge branch 'master' of https://github.com/psychobunny/node-forum
This commit is contained in:
7
app.js
7
app.js
@@ -4,7 +4,8 @@ var modules = {
|
||||
posts: require('./src/posts.js'),
|
||||
templates: require('./src/templates.js'),
|
||||
webserver: require('./src/webserver.js'),
|
||||
websockets: require('./src/websockets.js')
|
||||
websockets: require('./src/websockets.js'),
|
||||
fs: require('fs')
|
||||
}
|
||||
|
||||
DEVELOPMENT = true;
|
||||
@@ -13,15 +14,11 @@ var modules = {
|
||||
global.configuration = {};
|
||||
global.modules = modules;
|
||||
|
||||
// change this to = null when auth module is complete
|
||||
// global.uid = 1;
|
||||
|
||||
|
||||
(function(config) {
|
||||
config['ROOT_DIRECTORY'] = __dirname;
|
||||
|
||||
modules.templates.init();
|
||||
// modules.webserver.init();
|
||||
modules.websockets.init();
|
||||
|
||||
|
||||
|
||||
@@ -169,3 +169,10 @@ footer.footer {
|
||||
.pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.none {
|
||||
display: none !important;
|
||||
}
|
||||
.block {
|
||||
display: block !important;
|
||||
}
|
||||
@@ -45,7 +45,6 @@
|
||||
});
|
||||
socket.emit('api:user.get', { fields: ['username', 'picture'] });
|
||||
socket.on('api:user.get', function(data) {
|
||||
console.log(data);
|
||||
if (data.uid > 0) {
|
||||
var gravatar = document.createElement('img'),
|
||||
name = document.createElement('span')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1>Login</h1>
|
||||
<div class="row-fluid">
|
||||
<div class="well span6">
|
||||
<div class="well {login_window:spansize}">
|
||||
<h4>Login via Username & Password</h4>
|
||||
<div class="alert alert-error" id="error" style="display:none">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
@@ -9,14 +9,13 @@
|
||||
<form method="post" action="/login">
|
||||
<label>Username</label><input type="text" placeholder="Enter Username" name="username" id="username" /><br />
|
||||
<label>Password</label><input type="password" placeholder="Enter Password" name="password" id="password" /><br />
|
||||
<button class="btn btn-primary" id="login" type="submit">Login</button>
|
||||
<button class="btn btn-primary" id="login" type="submit">Login</button> <a href="/reset">Forgot Password?</a>
|
||||
</form>
|
||||
<a href="/reset">Forgot Password?</a>
|
||||
</div>
|
||||
<div class="well span6">
|
||||
<div class="well span6 {alternate_logins:display}">
|
||||
<h4>Alternative Logins</h4>
|
||||
<ul class="alt-logins">
|
||||
<li><a href="/auth/twitter"><img src="/images/twitter_login.png" /></a></li>
|
||||
<li class="none {twitter:display}"><a href="/auth/twitter"><img src="/images/twitter_login.png" /></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
(function(Templates) {
|
||||
|
||||
@@ -7,7 +7,7 @@ var fs = require('fs');
|
||||
function loadTemplates(templatesToLoad) {
|
||||
for (var t in templatesToLoad) {
|
||||
(function(file) {
|
||||
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
||||
modules.fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
||||
var template = function() {
|
||||
this.toString = function() {
|
||||
return this.html;
|
||||
|
||||
@@ -8,7 +8,8 @@ var express = require('express'),
|
||||
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
|
||||
passport = require('passport'),
|
||||
passportLocal = require('passport-local').Strategy,
|
||||
passportTwitter = require('passport-twitter').Strategy;
|
||||
passportTwitter = require('passport-twitter').Strategy,
|
||||
login_strategies = [];
|
||||
|
||||
passport.use(new passportLocal(function(user, password, next) {
|
||||
global.modules.user.loginViaLocal(user, password, function(login) {
|
||||
@@ -17,6 +18,7 @@ passport.use(new passportLocal(function(user, password, next) {
|
||||
});
|
||||
}));
|
||||
|
||||
if (config.twitter && config.twitter.key && config.twitter.key.length > 0 && config.twitter.secret.length > 0) {
|
||||
passport.use(new passportTwitter({
|
||||
consumerKey: config.twitter.key,
|
||||
consumerSecret: config.twitter.secret,
|
||||
@@ -28,6 +30,9 @@ passport.use(new passportTwitter({
|
||||
});
|
||||
}));
|
||||
|
||||
login_strategies.push('twitter');
|
||||
}
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
done(null, user.uid);
|
||||
});
|
||||
@@ -120,6 +125,28 @@ passport.deserializeUser(function(uid, done) {
|
||||
res.send(JSON.stringify(data));
|
||||
});
|
||||
break;
|
||||
case 'login' :
|
||||
var data = {},
|
||||
num_strategies = login_strategies.length;
|
||||
|
||||
if (num_strategies == 0) {
|
||||
data = {
|
||||
'login_window:spansize': 'span12',
|
||||
'alternate_logins:display': 'none'
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
'login_window:spansize': 'span6',
|
||||
'alternate_logins:display': 'block'
|
||||
}
|
||||
for (var i=0, ii=num_strategies; i<ii; i++) {
|
||||
data[login_strategies[i] + ':display'] = 'block';
|
||||
}
|
||||
}
|
||||
console.log(data);
|
||||
res.send(JSON.stringify(data));
|
||||
|
||||
break;
|
||||
case 'topic' :
|
||||
global.modules.posts.get(function(data) {
|
||||
res.send(JSON.stringify(data));
|
||||
@@ -147,12 +174,14 @@ passport.deserializeUser(function(uid, done) {
|
||||
});
|
||||
});
|
||||
|
||||
if (login_strategies.indexOf('twitter') !== -1) {
|
||||
app.get('/auth/twitter', passport.authenticate('twitter'));
|
||||
|
||||
app.get('/auth/twitter/callback', passport.authenticate('twitter', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
}));
|
||||
}
|
||||
|
||||
app.get('/reset/:code', function(req, res) {
|
||||
res.send(templates['header'] + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);
|
||||
|
||||
Reference in New Issue
Block a user