Notes/src/routes/api/password.ts

29 lines
846 B
TypeScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
2024-04-06 22:00:03 +03:00
import passwordService = require('../../services/encryption/password');
import ValidationError = require('../../errors/validation_error');
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);
}
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();
}
2024-04-06 22:00:03 +03:00
export = {
changePassword,
resetPassword
2020-06-20 12:31:38 +02:00
};