finished pw reset page, finally

v1.18.x
Julian Lam 12 years ago
parent 5792946a16
commit dfd5c9960b

@ -3,7 +3,7 @@
<div class="alert alert-success" id="success" style="display:none">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>Password Changed</strong>
<p></p>
<p>Password successfully reset, please <a href="/login">log in again</a>.</p>
</div>
<div class="alert" id="notice" style="display:none">
<strong></strong>
@ -16,7 +16,6 @@
<div id="reset-form">
<label for="password">New Password</label><input type="password" placeholder="A new password" id="password" /><br />
<label for="repeat">... and again</label><input type="password" placeholder="The same password" id="repeat" /><br />
<input type="hidden" value="{reset_code}" />
<button class="btn btn-primary" id="reset" type="submit" disabled>Reset Password</button>
</div>
</div>
@ -30,11 +29,11 @@
resetEl.addEventListener('click', function() {
if (password.value.length < 6) {
$('#error').hide();
noticeEl.querySelector('strong').value = 'Invalid Password';
noticeEl.querySelector('p').value = 'The password entered it too short, please pick a different password!';
noticeEl.style.display = 'auto';
noticeEl.querySelector('strong').innerHTML = 'Invalid Password';
noticeEl.querySelector('p').innerHTML = 'The password entered it too short, please pick a different password!';
noticeEl.style.display = 'block';
} else if (password.value === repeat.value) {
alert("match");
socket.emit('user:reset.commit', { code: '{reset_code}', password: password.value });
}
}, false);
@ -50,10 +49,12 @@
}
})
// socket.on('user.password.reset', function(data) {
// if (data.success === 'ok') {
// ajaxify.go('/');
// }
// });
socket.on('user:reset.commit', function(data) {
if (data.status === 'ok') {
$('#error').hide();
$('#notice').hide();
$('#success').show();
}
});
}());
</script>

@ -110,19 +110,27 @@ var config = require('../config.js'),
};
User.reset = {
validate: function(code) {
validate: function(code, callback) {
if (typeof callback !== 'function') callback = undefined;
RDB.get('reset:' + code + ':uid', function(uid) {
if (uid !== null) {
RDB.get('reset:' + code + ':expiry', function(expiry) {
if (expiry >= +new Date()/1000|0) global.socket.emit('user:reset.valid', { valid: true });
else {
if (expiry >= +new Date()/1000|0) {
if (!callback) global.socket.emit('user:reset.valid', { valid: true });
else callback(true);
} else {
// Expired, delete from db
RDB.del('reset:' + code + ':uid');
RDB.del('reset:' + code + ':expiry');
global.socket.emit('user:reset.valid', { valid: false });
if (!callback) global.socket.emit('user:reset.valid', { valid: false });
else callback(false);
}
});
} else global.socket.emit('user:reset.valid', { valid: false });
} else {
if (!callback) global.socket.emit('user:reset.valid', { valid: false });
else callback(false);
}
});
},
send: function(email) {
@ -173,6 +181,19 @@ var config = require('../config.js'),
});
}
});
},
commit: function(code, password) {
this.validate(code, function(validated) {
if (validated) {
RDB.get('reset:' + code + ':uid', function(uid) {
RDB.set('uid:' + uid + ':password', password);
RDB.del('reset:' + code + ':uid');
RDB.del('reset:' + code + ':expiry');
global.socket.emit('user:reset.commit', { status: 'ok' });
});
}
});
}
}

@ -52,6 +52,10 @@ var SocketIO = require('socket.io').listen(global.server);
socket.on('user:reset.valid', function(data) {
modules.user.reset.validate(data.code);
});
socket.on('user:reset.commit', function(data) {
modules.user.reset.commit(data.code, data.password);
});
});
}(SocketIO));

Loading…
Cancel
Save