resetting/setting password from options

This commit is contained in:
zadam
2021-12-30 22:54:08 +01:00
parent f92016f9ec
commit 8120f1bf25
10 changed files with 137 additions and 73 deletions

View File

@@ -67,6 +67,8 @@ function getOptions() {
}
}
resultMap['isPasswordSet'] = !!optionMap['passwordVerificationHash'] ? 'true' : 'false';
return resultMap;
}

View File

@@ -1,11 +1,26 @@
"use strict";
const changePasswordService = require('../../services/change_password');
const passwordService = require('../../services/password.js');
function changePassword(req) {
return changePasswordService.changePassword(req.body.current_password, req.body.new_password);
if (passwordService.isPasswordSet()) {
return passwordService.changePassword(req.body.current_password, req.body.new_password);
}
else {
return passwordService.setPassword(req.body.new_password);
}
}
function resetPassword(req) {
// protection against accidental call (not a security measure)
if (req.query.really !== "yesIReallyWantToResetPasswordAndLoseAccessToMyProtectedNotes") {
return [400, "Incorrect password reset confirmation"];
}
return passwordService.resetPassword();
}
module.exports = {
changePassword
changePassword,
resetPassword
};