mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
more work with reset page
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
var config = {
|
var config = {
|
||||||
|
"url": "http://designcreateplay.com:4567/",
|
||||||
"port": 4567,
|
"port": 4567,
|
||||||
"mailer": {
|
"mailer": {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: '25',
|
port: '25',
|
||||||
from: 'mailer@localhost.lan'
|
from: 'mailer@designcreateplay.com'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
{
|
{
|
||||||
"author": "psychobunny <andrew@designcreateplay.com>",
|
"author": "psychobunny <andrew@designcreateplay.com>, julianlam <julian@designcreateplay.com>",
|
||||||
"name": "nodeforum",
|
"name": "nodeforum",
|
||||||
"description": "nodeforum dev",
|
"description": "nodeforum dev",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"homepage": "http://www.designcreateplay.com",
|
"homepage": "http://www.designcreateplay.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": ""
|
"url": "https://github.com/psychobunny/node-forum/"
|
||||||
},
|
},
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"socket.io": "0.9.14",
|
"socket.io": "0.9.14",
|
||||||
"redis": "0.8.3",
|
"redis": "0.8.3",
|
||||||
"express": "3.2.0",
|
"express": "3.2.0",
|
||||||
"connect": "2.7.6"
|
"connect": "2.7.6",
|
||||||
|
"emailjs": "0.3.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"optionalDependencies": {},
|
"optionalDependencies": {},
|
||||||
|
|||||||
46
src/user.js
46
src/user.js
@@ -1,4 +1,8 @@
|
|||||||
var RDB = require('./redis.js');
|
var config = require('../config.js'),
|
||||||
|
utils = require('../utils.js'),
|
||||||
|
RDB = require('./redis.js'),
|
||||||
|
emailjs = require('emailjs'),
|
||||||
|
emailjsServer = emailjs.server.connect(config.mailer);
|
||||||
|
|
||||||
(function(User) {
|
(function(User) {
|
||||||
var current_uid;
|
var current_uid;
|
||||||
@@ -24,7 +28,6 @@ var RDB = require('./redis.js');
|
|||||||
if (user.password != password) {
|
if (user.password != password) {
|
||||||
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
|
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
|
||||||
} else {
|
} else {
|
||||||
console.log('in');
|
|
||||||
return global.socket.emit('user.login', {'status': 1, 'message': 'Logged in!'});
|
return global.socket.emit('user.login', {'status': 1, 'message': 'Logged in!'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -95,14 +98,46 @@ var RDB = require('./redis.js');
|
|||||||
RDB.get('username:' + username + ':uid', callback);
|
RDB.get('username:' + username + ':uid', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.get_uid_by_email = function(email, callback) {
|
||||||
|
RDB.get('email:' + email, callback)
|
||||||
|
};
|
||||||
|
|
||||||
User.send_reset = function(email) {
|
User.send_reset = function(email) {
|
||||||
User.email.exists(email, function(exists) {
|
User.get_uid_by_email(email, function(uid) {
|
||||||
if (exists) {
|
if (uid !== null) {
|
||||||
|
// Generate a new reset code
|
||||||
|
var reset_code = utils.generateUUID();
|
||||||
|
RDB.set('user:reset:' + reset_code, uid);
|
||||||
|
|
||||||
|
var message = emailjs.message.create({
|
||||||
|
text: "Hello,\n\n" +
|
||||||
|
"We received a request to reset your password, possibly because you have forgotten it. If this is not the case, please ignore this email.\n\n" +
|
||||||
|
"To continue with the password reset, please click on the following link:\n\n" +
|
||||||
|
" " + config.url + 'reset/' + reset_code + "\n\n\n" +
|
||||||
|
"Thanks!\nNodeBB",
|
||||||
|
from: config.mailer.from,
|
||||||
|
to: email,
|
||||||
|
subject: 'Password Reset Requested',
|
||||||
|
attachment: [
|
||||||
|
{
|
||||||
|
data: "<p>Hello,</p>" +
|
||||||
|
"<p>We received a request to reset your password, possibly because you have forgotten it. If this is not the case, please ignore this email.</p>" +
|
||||||
|
"<p>To continue with the password reset, please click on the following link:</p>" +
|
||||||
|
"<blockquote>" + config.url + 'reset/' + reset_code + "</blockquote>" +
|
||||||
|
"<p>Thanks!<br /><strong>NodeBB</strong>",
|
||||||
|
alternative: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
emailjsServer.send(message, function(err, success) {
|
||||||
|
if (err === null) {
|
||||||
global.socket.emit('user.send_reset', {
|
global.socket.emit('user.send_reset', {
|
||||||
status: "ok",
|
status: "ok",
|
||||||
message: "code-sent",
|
message: "code-sent",
|
||||||
email: email
|
email: email
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
global.socket.emit('user.send_reset', {
|
global.socket.emit('user.send_reset', {
|
||||||
status: "error",
|
status: "error",
|
||||||
@@ -115,8 +150,7 @@ var RDB = require('./redis.js');
|
|||||||
|
|
||||||
User.email = {
|
User.email = {
|
||||||
exists: function(email, callback) {
|
exists: function(email, callback) {
|
||||||
RDB.get('email:' + email, function(exists) {
|
User.get_uid_by_email(email, function(exists) {
|
||||||
console.log('email:' + email, exists);
|
|
||||||
exists = !!exists;
|
exists = !!exists;
|
||||||
if (typeof callback !== 'function') global.socket.emit('user.email.exists', { exists: exists });
|
if (typeof callback !== 'function') global.socket.emit('user.email.exists', { exists: exists });
|
||||||
else callback(exists);
|
else callback(exists);
|
||||||
|
|||||||
@@ -26,10 +26,14 @@ var express = require('express'),
|
|||||||
module.exports.init = function() {
|
module.exports.init = function() {
|
||||||
// todo move some of this stuff into config.json
|
// todo move some of this stuff into config.json
|
||||||
app.configure(function() {
|
app.configure(function() {
|
||||||
app.use(express.favicon());
|
app.use(express.favicon()); // 2 args: string path and object options (i.e. expire time etc)
|
||||||
app.use(express.bodyParser());
|
app.use(express.bodyParser()); // Puts POST vars in request.body
|
||||||
app.use(express.cookieParser());
|
app.use(express.cookieParser()); // Presumably important
|
||||||
|
|
||||||
|
// Dunno wtf this does
|
||||||
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
|
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
|
||||||
|
|
||||||
|
// Useful if you want to use app.put and app.delete (instead of app.post all the time)
|
||||||
// app.use(express.methodOverride());
|
// app.use(express.methodOverride());
|
||||||
app.use(express.static(global.configuration.ROOT_DIRECTORY + '/public'));
|
app.use(express.static(global.configuration.ROOT_DIRECTORY + '/public'));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
var SocketIO = require('socket.io').listen(global.server);
|
var SocketIO = require('socket.io').listen(global.server);
|
||||||
|
|
||||||
|
|
||||||
(function(io) {
|
(function(io) {
|
||||||
var modules = null;
|
var modules = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user