interim commit for password reset

v1.18.x
Julian Lam 12 years ago
parent edf698818d
commit dea9a707dc

@ -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

@ -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 &copy; 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">

@ -8,21 +8,29 @@
<div class="alert" id="error" style="display:none">
<button type="button" class="close" data-dismiss="alert">&times;</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;
}
}
});
}());

@ -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') {

@ -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) {

@ -114,19 +114,21 @@ var config = require('../config.js'),
if (uid !== null) {
// Generate a new reset code
var 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', {

@ -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) {

Loading…
Cancel
Save