Notes/src/routes/api/password.ts

28 lines
842 B
TypeScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
import passwordService from "../../services/encryption/password.js";
import ValidationError from "../../errors/validation_error.js";
2025-01-09 18:07:02 +02:00
import { Request } from "express";
2024-04-06 22:00:03 +03:00
function changePassword(req: Request) {
if (passwordService.isPasswordSet()) {
return passwordService.changePassword(req.body.current_password, req.body.new_password);
2025-01-09 18:07:02 +02:00
} else {
return passwordService.setPassword(req.body.new_password);
}
}
2024-04-06 22:00:03 +03:00
function resetPassword(req: Request) {
// protection against accidental call (not a security measure)
if (req.query.really !== "yesIReallyWantToResetPasswordAndLoseAccessToMyProtectedNotes") {
throw new ValidationError("Incorrect password reset confirmation");
}
return passwordService.resetPassword();
}
export default {
changePassword,
resetPassword
2020-06-20 12:31:38 +02:00
};