more work with reset page

v1.18.x
Julian Lam 12 years ago
parent 0e8c4f35cd
commit a73481af8b

@ -1,9 +1,10 @@
var config = {
"url": "http://designcreateplay.com:4567/",
"port": 4567,
"mailer": {
host: 'localhost',
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",
"description": "nodeforum dev",
"version": "0.0.1",
"homepage": "http://www.designcreateplay.com",
"repository": {
"url": ""
"url": "https://github.com/psychobunny/node-forum/"
},
"main": "app.js",
"dependencies": {
"socket.io": "0.9.14",
"redis": "0.8.3",
"express": "3.2.0",
"connect": "2.7.6"
"connect": "2.7.6",
"emailjs": "0.3.4"
},
"devDependencies": {},
"optionalDependencies": {},

@ -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) {
var current_uid;
@ -24,7 +28,6 @@ var RDB = require('./redis.js');
if (user.password != password) {
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
} else {
console.log('in');
return global.socket.emit('user.login', {'status': 1, 'message': 'Logged in!'});
}
});
@ -95,13 +98,45 @@ var RDB = require('./redis.js');
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.email.exists(email, function(exists) {
if (exists) {
global.socket.emit('user.send_reset', {
status: "ok",
message: "code-sent",
email: email
User.get_uid_by_email(email, function(uid) {
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" +
"&nbsp;&nbsp;" + 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', {
status: "ok",
message: "code-sent",
email: email
});
}
});
} else {
global.socket.emit('user.send_reset', {
@ -115,8 +150,7 @@ var RDB = require('./redis.js');
User.email = {
exists: function(email, callback) {
RDB.get('email:' + email, function(exists) {
console.log('email:' + email, exists);
User.get_uid_by_email(email, function(exists) {
exists = !!exists;
if (typeof callback !== 'function') global.socket.emit('user.email.exists', { exists: exists });
else callback(exists);

@ -26,10 +26,14 @@ var express = require('express'),
module.exports.init = function() {
// todo move some of this stuff into config.json
app.configure(function() {
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.favicon()); // 2 args: string path and object options (i.e. expire time etc)
app.use(express.bodyParser()); // Puts POST vars in request.body
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' }));
// 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.static(global.configuration.ROOT_DIRECTORY + '/public'));
});

@ -1,6 +1,4 @@
var SocketIO = require('socket.io').listen(global.server);
var SocketIO = require('socket.io').listen(global.server);
(function(io) {
var modules = null;

@ -0,0 +1,10 @@
var utils = {
generateUUID: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}
module.exports = utils;
Loading…
Cancel
Save