Node.js based forum software built for the modern web
interim commit for password reset
Julian Lamdea9a707dc89
diff --git a/public/templates/emails/reset_plaintext.tpl b/public/templates/emails/reset_plaintext.tplnew file mode 100644index 0000000000..066b496491--- /dev/null+++ b/public/templates/emails/reset_plaintext.tpl@@ -0,0 +1,10 @@+Hello,++We received a request to reset your password, possibly because you have forgotten it. If this is not the case, please ignore this email.++To continue with the password reset, please click on the following link:++ {RESET_LINK}++Thanks!+NodeBB\ No newline at end of filediff --git a/public/templates/footer.tpl b/public/templates/footer.tplindex 6379a7fe40..279d1389c1 100644--- a/public/templates/footer.tpl+++ b/public/templates/footer.tpl@@ -7,7 +7,7 @@<span id="number_of_users"></span><br /><span id="latest_user"></span></div>- <footer class="footer">Copyright (c) 2013 <a target="_blank" href="http://www.nodebb.com">NodeBB</a> by <a target="_blank" href="https://github.com/psychobunny">psychobunny</a>, <a href="https://github.com/julianlam" target="_blank">julianlam</a>, <a href="https://github.com/barisusakli" target="_blank">barisusakli</a> from <a target="_blank" href="http://www.designcreateplay.com">designcreateplay</a></footer>+ <footer class="footer">Copyright © 2013 <a target="_blank" href="http://www.nodebb.com">NodeBB</a> by <a target="_blank" href="https://github.com/psychobunny">psychobunny</a>, <a href="https://github.com/julianlam" target="_blank">julianlam</a>, <a href="https://github.com/barisusakli" target="_blank">barisusakli</a> from <a target="_blank" href="http://www.designcreateplay.com">designcreateplay</a></footer></div><script type="text/javascript">diff --git a/public/templates/reset.tpl b/public/templates/reset.tplindex 5a58af20d0..9952287f4d 100644--- a/public/templates/reset.tpl+++ b/public/templates/reset.tpl@@ -8,21 +8,29 @@<div class="alert" id="error" style="display:none"><button type="button" class="close" data-dismiss="alert">×</button><strong>Invalid Email!</strong>- <p>The email you put in (<span id="invalid-email"></span>) is not registered with us. Please try again.</p>+ <p></p></div>- <label>Email Address</label><input type="text" placeholder="Enter Email Address" id="email" /><br />+ <label for="email">Email Address</label><input type="text" placeholder="Enter Email Address" id="email" /><br /><button class="btn btn-primary" id="reset" type="submit">Reset Password</button></div><script type="text/javascript">(function() {+ var inputEl = document.getElementById('email'),+ errorEl = document.getElementById('error'),+ errorTextEl = errorEl.querySelector('p');+document.getElementById('reset').onclick = function() {- socket.emit('user.send_reset', { email: document.getElementById('email').value });+ if (inputEl.value.length > 0 && inputEl.value.indexOf('@') !== -1) {+ socket.emit('user.send_reset', { email: inputEl.value });+ } else {+ jQuery('#success').hide();+ jQuery(errorEl).show();+ errorTextEl.innerHTML = 'Please enter a valid email';+ }};socket.on('user.send_reset', function(data) {- var inputEl = document.getElementById('email'),- submitEl = document.getElementById('reset'),- invalidEl = document.getElementById('invalid-email');+ var submitEl = document.getElementById('reset');if (data.status === 'ok') {jQuery('#error').hide();@@ -31,8 +39,15 @@inputEl.value = '';} else {jQuery('#success').hide();- jQuery('#error').show();- invalidEl.innerHTML = data.email;+ jQuery(errorEl).show();+ switch(data.message) {+ case 'invalid-email':+ errorTextEl.innerHTML = 'The email you put in (<span>' + data.email + '</span>) is not registered with us. Please try again.';+ break;+ case 'send-failed':+ errorTextEl.innerHTML = 'There was a problem sending the reset code. Please try again later.';+ break;+ }}});}());diff --git a/public/templates/reset_code.tpl b/public/templates/reset_code.tplindex 46ca92d0fe..ca5d63c8ff 100644--- a/public/templates/reset_code.tpl+++ b/public/templates/reset_code.tpl@@ -6,16 +6,20 @@<p></p></div><label>New Password</label><input type="password" placeholder="A new password" id="password" /><br />- <label>... and again</label><input type="password" placeholder="" id="password_2" /><br />- <input type="hidden" value="{andrew - the code goes here}" />+ <label>... and again</label><input type="password" placeholder="" id="repeat" /><br />+ <input type="hidden" value="{reset_code}" /><button class="btn btn-primary" id="reset" type="submit">Reset Password</button></div><script type="text/javascript">(function() {- var resetEl = document.getElementById('reset');+ var resetEl = document.getElementById('reset'),+ password = document.getElementById('password'),+ repeat = document.getElementById('repeat');resetEl.addEventListener('click', function() {-+ if (password.value === repeat.value) {+ alert("match");+ }}, false);// socket.on('user.password.reset', function(data) {// if (data.success === 'ok') {diff --git a/src/templates.js b/src/templates.jsindex e0cacbb9d1..13b75fb288 100644--- a/src/templates.js+++ b/src/templates.js@@ -24,7 +24,7 @@ var fs = require('fs');}Templates.init = function() {- loadTemplates(['header', 'footer', 'register', 'home', 'login', 'reset', 'reset_code', 'emails/reset']);+ loadTemplates(['header', 'footer', 'register', 'home', 'login', 'reset', 'reset_code', 'emails/reset', 'emails/reset_plaintext']);}var parse = function(data) {diff --git a/src/user.js b/src/user.jsindex 50a1ecf55f..a9619d4af7 100644--- a/src/user.js+++ b/src/user.js@@ -114,19 +114,21 @@ var config = require('../config.js'),if (uid !== null) {// Generate a new reset codevar reset_code = utils.generateUUID();- RDB.set('user:reset:' + reset_code, uid);+ RDB.set('reset:' + reset_code + ':uid', uid);+ // RDB.set('reset:' + reset_code + ':expiry', expiry);var reset_link = config.url + 'reset/' + reset_code,- reset_email = global.templates['emails/reset'].parse({'RESET_LINK': reset_link});+ reset_email = global.templates['emails/reset'].parse({'RESET_LINK': reset_link}),+ reset_email_plaintext = global.templates['emails/reset_plaintext'].parse({ 'RESET_LINK': reset_link });var message = emailjs.message.create({- text: reset_email,+ text: reset_email_plaintext,from: config.mailer.from,to: email,subject: 'Password Reset Requested',attachment: [{- data: reset_email,+ data: reset_email,alternative: true}]@@ -139,8 +141,13 @@ var config = require('../config.js'),message: "code-sent",email: email});+ } else {+ global.socket.emit('user.send_reset', {+ status: "error",+ message: "send-failed"+ });+ throw new Error(err);}- else throw new Error(err);});} else {global.socket.emit('user.send_reset', {diff --git a/src/webserver.js b/src/webserver.jsindex 4557658c80..44d6203c6d 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -26,7 +26,7 @@ var express = require('express'),app.get('/reset/:code', function(req, res) {refreshTemplates();- res.send(templates['header'] + templates['reset_code'] + templates['footer']);+ res.send(templates['header'] + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);});app.get('/reset', function(req, res) {