2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2023-11-22 19:34:48 +01:00
|
|
|
const passwordService = require('../../services/encryption/password.js');
|
|
|
|
const ValidationError = require('../../errors/validation_error.js');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function changePassword(req) {
|
2021-12-30 22:54:08 +01:00
|
|
|
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") {
|
2022-12-09 16:04:13 +01:00
|
|
|
throw new ValidationError("Incorrect password reset confirmation");
|
2021-12-30 22:54:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return passwordService.resetPassword();
|
2018-03-30 13:56:46 -04:00
|
|
|
}
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2018-03-30 13:56:46 -04:00
|
|
|
module.exports = {
|
2021-12-30 22:54:08 +01:00
|
|
|
changePassword,
|
|
|
|
resetPassword
|
2020-06-20 12:31:38 +02:00
|
|
|
};
|