Notes/src/routes/api/password.js

28 lines
805 B
JavaScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
const passwordService = require('../../services/encryption/password.js');
const ValidationError = require('../../errors/validation_error.js');
2020-06-20 12:31:38 +02:00
function changePassword(req) {
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") {
throw new ValidationError("Incorrect password reset confirmation");
}
return passwordService.resetPassword();
}
module.exports = {
changePassword,
resetPassword
2020-06-20 12:31:38 +02:00
};