mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
![]() |
import server from "../../services/server.js";
|
||
|
import protectedSessionHolder from "../../services/protected_session_holder.js";
|
||
|
import infoService from "../../services/info.js";
|
||
|
|
||
|
export default class ChangePasswordOptions {
|
||
|
constructor() {
|
||
|
this.$form = $("#change-password-form");
|
||
|
this.$oldPassword = $("#old-password");
|
||
|
this.$newPassword1 = $("#new-password1");
|
||
|
this.$newPassword2 = $("#new-password2");
|
||
|
|
||
|
this.$form.submit(() => this.save());
|
||
|
}
|
||
|
|
||
|
optionsLoaded(options) {}
|
||
|
|
||
|
save() {
|
||
|
const oldPassword = this.$oldPassword.val();
|
||
|
const newPassword1 = this.$newPassword1.val();
|
||
|
const newPassword2 = this.$newPassword2.val();
|
||
|
|
||
|
this.$oldPassword.val('');
|
||
|
this.$newPassword1.val('');
|
||
|
this.$newPassword2.val('');
|
||
|
|
||
|
if (newPassword1 !== newPassword2) {
|
||
|
alert("New passwords are not the same.");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
server.post('password/change', {
|
||
|
'current_password': oldPassword,
|
||
|
'new_password': newPassword1
|
||
|
}).then(result => {
|
||
|
if (result.success) {
|
||
|
alert("Password has been changed. Trilium will be reloaded after you press OK.");
|
||
|
|
||
|
// password changed so current protected session is invalid and needs to be cleared
|
||
|
protectedSessionHolder.resetProtectedSession();
|
||
|
}
|
||
|
else {
|
||
|
infoService.showError(result.message);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|