mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
feat(react/settings): port change password
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
import passwordService from "../../services/encryption/password.js";
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
import type { Request } from "express";
|
||||
import { ChangePasswordResponse } from "@triliumnext/commons";
|
||||
|
||||
function changePassword(req: Request) {
|
||||
function changePassword(req: Request): ChangePasswordResponse {
|
||||
if (passwordService.isPasswordSet()) {
|
||||
return passwordService.changePassword(req.body.current_password, req.body.new_password);
|
||||
} else {
|
||||
|
||||
@@ -3,12 +3,13 @@ import optionService from "../options.js";
|
||||
import myScryptService from "./my_scrypt.js";
|
||||
import { randomSecureToken, toBase64 } from "../utils.js";
|
||||
import passwordEncryptionService from "./password_encryption.js";
|
||||
import { ChangePasswordResponse } from "@triliumnext/commons";
|
||||
|
||||
function isPasswordSet() {
|
||||
return !!sql.getValue("SELECT value FROM options WHERE name = 'passwordVerificationHash'");
|
||||
}
|
||||
|
||||
function changePassword(currentPassword: string, newPassword: string) {
|
||||
function changePassword(currentPassword: string, newPassword: string): ChangePasswordResponse {
|
||||
if (!isPasswordSet()) {
|
||||
throw new Error("Password has not been set yet, so it cannot be changed. Use 'setPassword' instead.");
|
||||
}
|
||||
@@ -41,7 +42,7 @@ function changePassword(currentPassword: string, newPassword: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function setPassword(password: string) {
|
||||
function setPassword(password: string): ChangePasswordResponse {
|
||||
if (isPasswordSet()) {
|
||||
throw new Error("Password is set already. Either change it or perform 'reset password' first.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user