commento/frontend/js/signup.js

48 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2018-06-04 00:06:17 +08:00
(function (global, document) {
"use strict"
2018-06-04 00:06:17 +08:00
// Signs up the user and redirects to either the login page or the email
// confirmation, depending on whether or not SMTP is configured in the
// backend.
global.signup = function(event) {
event.preventDefault();
if ($("#password").val() !== $("#password2").val()) {
2018-06-04 00:06:17 +08:00
global.textSet("#err", "The two passwords don't match");
return;
}
var allOk = global.unfilledMark(["#email", "#name", "#password", "#password2"], function(el) {
2018-06-04 00:06:17 +08:00
el.css("border-bottom", "1px solid red");
});
if (!allOk) {
2018-06-04 00:06:17 +08:00
global.textSet("#err", "Please make sure all fields are filled");
return;
}
var json = {
"email": $("#email").val(),
"name": $("#name").val(),
"password": $("#password").val(),
};
global.buttonDisable("#signup-button");
global.post(global.origin + "/api/owner/new", json, function(resp) {
2018-06-04 00:06:17 +08:00
global.buttonEnable("#signup-button")
if (!resp.success) {
global.textSet("#err", resp.message);
return;
}
if (resp.confirmEmail) {
document.location = global.origin + "/confirm-email";
} else {
document.location = global.origin + "/login?signedUp=true";
}
2018-06-04 00:06:17 +08:00
});
};
} (window.commento, document));