mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 19:22:31 +08:00
28 lines
847 B
TypeScript
28 lines
847 B
TypeScript
"use strict";
|
|
|
|
import passwordService from "../../services/encryption/password.js";
|
|
import ValidationError from "../../errors/validation_error.js";
|
|
import type { Request } from "express";
|
|
|
|
function changePassword(req: Request) {
|
|
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: 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
|
|
};
|