mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
more work with reset page
This commit is contained in:
@@ -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": {},
|
||||
|
||||
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) {
|
||||
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,14 +98,46 @@ 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) {
|
||||
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" +
|
||||
" " + 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', {
|
||||
status: "error",
|
||||
@@ -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,7 +1,5 @@
|
||||
|
||||
var SocketIO = require('socket.io').listen(global.server);
|
||||
|
||||
|
||||
(function(io) {
|
||||
var modules = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user