Replace alert() with modal for ACP password reset

Some browsers (e.g. Chrome) don't allow copying text out of alert()
dialogs.
This commit is contained in:
Calvin Montgomery 2017-07-24 22:35:15 -07:00
parent 5a78056c91
commit f593f7283c
3 changed files with 22 additions and 8 deletions

View file

@ -139,7 +139,7 @@ function handleSetRank(user, data) {
}); });
} }
function handleResetPassword(user, data) { function handleResetPassword(user, data, ack) {
var name = data.name; var name = data.name;
var email = data.email; var email = data.email;
if (typeof name !== "string" || typeof email !== "string") { if (typeof name !== "string" || typeof email !== "string") {
@ -164,19 +164,14 @@ function handleResetPassword(user, data) {
expire: expire expire: expire
}, function (err) { }, function (err) {
if (err) { if (err) {
user.socket.emit("errMessage", { ack && ack({ error: err });
msg: err
});
return; return;
} }
Logger.eventlog.log("[acp] " + eventUsername(user) + " initialized a " + Logger.eventlog.log("[acp] " + eventUsername(user) + " initialized a " +
"password recovery for " + name); "password recovery for " + name);
user.socket.emit("errMessage", { ack && ack({ hash });
msg: "Reset link: " + Config.get("http.domain") +
"/account/passwordrecover/" + hash
});
}); });
}); });
} }

View file

@ -229,6 +229,20 @@ socket.on("acp-list-users", function (users) {
socket.emit("acp-reset-password", { socket.emit("acp-reset-password", {
name: u.name, name: u.name,
email: u.email email: u.email
}, function (result) {
if (result.error) {
modalAlert({
title: "Error",
textContent: result.error
});
} else {
var link = new URL("/account/passwordrecover/" + result.hash,
new URL(location));
modalAlert({
title: "Reset Link",
textContent: link
});
}
}); });
}).appendTo(reset); }).appendTo(reset);
} }

View file

@ -2097,6 +2097,11 @@ function errDialog(err) {
* I *promise* that one day I will actually split this file into submodules * I *promise* that one day I will actually split this file into submodules
* -cal * -cal
*/ */
/**
* modalAlert accepts options { title, textContent, htmlContent }
* All are optional
*/
function modalAlert(options) { function modalAlert(options) {
if (typeof options !== "object" || options === null) { if (typeof options !== "object" || options === null) {
throw new Error("modalAlert() called without required parameter"); throw new Error("modalAlert() called without required parameter");