1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

frontend: add password reset functionality

This commit is contained in:
Adhityaa
2018-06-09 15:37:53 +05:30
parent 5f23706003
commit a9b235ef0b
7 changed files with 192 additions and 2 deletions

33
frontend/js/forgot.js Normal file
View File

@ -0,0 +1,33 @@
(function (global, document) {
// Talks to the API and sends an reset email.
global.sendResetHex = function() {
var all_ok = global.unfilledMark(["#email"], function(el) {
el.css("border-bottom", "1px solid red");
});
if (!all_ok) {
global.textSet("#err", "Please make sure all fields are filled.");
return;
}
var json = {
"email": $("#email").val(),
};
global.buttonDisable("#reset-button");
global.post(global.commento_origin + "/api/owner/send-reset-hex", json, function(resp) {
global.buttonEnable("#reset-button");
global.textSet("#err", "");
if (!resp.success) {
global.textSet("#err", resp.message);
return
}
$("#msg").html("If that email is a registered account, you will receive an email with instructions on how to reset your password.");
$("#reset-button").hide();
});
}
} (window, document));

37
frontend/js/reset.js Normal file
View File

@ -0,0 +1,37 @@
(function (global, document) {
global.resetPassword = function() {
var all_ok = global.unfilledMark(["#password", "#password2"], function(el) {
el.css("border-bottom", "1px solid red");
});
if (!all_ok) {
global.textSet("#err", "Please make sure all fields are filled.");
return;
}
if ($("#password").val() != $("#password2").val()) {
global.textSet("#err", "The two passwords do not match.");
return;
}
var json = {
"resetHex": paramGet("hex"),
"password": $("#password").val(),
};
global.buttonDisable("#reset-button");
global.post(global.commento_origin + "/api/owner/reset-password", json, function(resp) {
global.buttonEnable("#reset-button");
global.textSet("#err", "");
if (!resp.success) {
global.textSet("#err", resp.message);
return
}
document.location = "/login?changed=true";
});
}
} (window, document));