mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
refactor: 💡 fix typo and imporve code quality
This commit is contained in:
parent
bd092e0119
commit
2eeb376d24
@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS "user_data"
|
||||
tmpID INT,
|
||||
username TEXT,
|
||||
email TEXT,
|
||||
userIDEcnryptedDataKey TEXT,
|
||||
userIDEncryptedDataKey TEXT,
|
||||
userIDVerificationHash TEXT,
|
||||
salt TEXT,
|
||||
derivedKey TEXT,
|
||||
|
@ -1,4 +1,4 @@
|
||||
class OpenIDrror {
|
||||
class OpenIdError {
|
||||
message: string;
|
||||
|
||||
constructor(message: string) {
|
||||
@ -6,4 +6,4 @@ class OpenIDrror {
|
||||
}
|
||||
}
|
||||
|
||||
export default OpenIDrror;
|
||||
export default OpenIdError;
|
@ -50,13 +50,6 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
||||
matchTags: { bothTags: true },
|
||||
highlightSelectionMatches: { showToken: false, annotateScrollbar: false },
|
||||
lineNumbers: true,
|
||||
keyMap: "default",
|
||||
lint: false,
|
||||
gutters: [],
|
||||
tabindex: 0,
|
||||
dragDrop: true,
|
||||
placeholder: "",
|
||||
readOnly: false,
|
||||
// we line wrap partly also because without it horizontal scrollbar displays only when you scroll
|
||||
// all the way to the bottom of the note. With line wrap, there's no horizontal scrollbar so no problem
|
||||
lineWrapping: options.is("codeLineWrapEnabled"),
|
||||
|
@ -6,7 +6,7 @@ import { t } from "../../../services/i18n.js";
|
||||
import utils from "../../../services/utils.js";
|
||||
import dialogService from "../../../services/dialog.js";
|
||||
|
||||
const TPL_WEB = `
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
<h4>${t("multi_factor_authentication.title")}</h4>
|
||||
<p class="form-text">${t("multi_factor_authentication.description")}</p>
|
||||
@ -147,7 +147,7 @@ export default class MultiFactorAuthenticationOptions extends OptionsWidget {
|
||||
private $missingVars!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
const template = utils.isElectron() ? TPL_ELECTRON : TPL_WEB;
|
||||
const template = utils.isElectron() ? TPL_ELECTRON : TPL;
|
||||
this.$widget = $(template);
|
||||
|
||||
if (!utils.isElectron()) {
|
||||
|
@ -21,38 +21,38 @@ function getScryptHash(password: crypto.BinaryLike, salt: crypto.BinaryLike) {
|
||||
}
|
||||
|
||||
function getSubjectIdentifierVerificationHash(
|
||||
guessedUserId: string | crypto.BinaryLike,
|
||||
salt?: string
|
||||
guessedUserId: string | crypto.BinaryLike,
|
||||
salt?: string
|
||||
) {
|
||||
if (salt != null) return getScryptHash(guessedUserId, salt);
|
||||
if (salt != null) return getScryptHash(guessedUserId, salt);
|
||||
|
||||
const savedSalt = sql.getValue("SELECT salt FROM user_data;");
|
||||
if (savedSalt === undefined || savedSalt === null) {
|
||||
console.log("User salt undefined!");
|
||||
return undefined;
|
||||
}
|
||||
return getScryptHash(guessedUserId, savedSalt.toString());
|
||||
const savedSalt = sql.getValue("SELECT salt FROM user_data;");
|
||||
if (!savedSalt) {
|
||||
console.error("User salt undefined!");
|
||||
return undefined;
|
||||
}
|
||||
return getScryptHash(guessedUserId, savedSalt.toString());
|
||||
}
|
||||
|
||||
function getSubjectIdentifierDerivedKey(
|
||||
subjectIdentifer: crypto.BinaryLike,
|
||||
givenSalt?: string
|
||||
subjectIdentifer: crypto.BinaryLike,
|
||||
givenSalt?: string
|
||||
) {
|
||||
if (givenSalt !== undefined) {
|
||||
return getScryptHash(subjectIdentifer, givenSalt.toString());
|
||||
}
|
||||
if (givenSalt !== undefined) {
|
||||
return getScryptHash(subjectIdentifer, givenSalt.toString());
|
||||
}
|
||||
|
||||
const salt = sql.getValue("SELECT salt FROM user_data;");
|
||||
if (salt === undefined || salt === null) return undefined;
|
||||
const salt = sql.getValue("SELECT salt FROM user_data;");
|
||||
if (!salt) return undefined;
|
||||
|
||||
return getScryptHash(subjectIdentifer, salt.toString());
|
||||
return getScryptHash(subjectIdentifer, salt.toString());
|
||||
}
|
||||
|
||||
function createSubjectIdentifierDerivedKey(
|
||||
subjectIdentifer: string | crypto.BinaryLike,
|
||||
salt: string | crypto.BinaryLike
|
||||
subjectIdentifer: string | crypto.BinaryLike,
|
||||
salt: string | crypto.BinaryLike
|
||||
) {
|
||||
return getScryptHash(subjectIdentifer, salt);
|
||||
return getScryptHash(subjectIdentifer, salt);
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -3,7 +3,7 @@ import utils from "../utils.js";
|
||||
import dataEncryptionService from "./data_encryption.js";
|
||||
import sql from "../sql.js";
|
||||
import sqlInit from "../sql_init.js";
|
||||
import OpenIDError from "../../errors/open_id_error.js";
|
||||
import OpenIdError from "../../errors/open_id_error.js";
|
||||
|
||||
function saveUser(subjectIdentifier: string, name: string, email: string) {
|
||||
if (isUserSaved()) return false;
|
||||
@ -15,8 +15,8 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {
|
||||
subjectIdentifier,
|
||||
verificationSalt
|
||||
);
|
||||
if (verificationHash === undefined) {
|
||||
throw new OpenIDError("Verification hash undefined!")
|
||||
if (!verificationHash) {
|
||||
throw new OpenIdError("Verification hash undefined!")
|
||||
}
|
||||
|
||||
const userIDEncryptedDataKey = setDataKey(
|
||||
@ -25,8 +25,8 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {
|
||||
verificationSalt
|
||||
);
|
||||
|
||||
if (userIDEncryptedDataKey === undefined || userIDEncryptedDataKey === null) {
|
||||
console.log("USERID ENCRYPTED DATA KEY NULL");
|
||||
if (!userIDEncryptedDataKey) {
|
||||
console.error("UserID encrypted data key null");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {
|
||||
userIDVerificationHash: utils.toBase64(verificationHash),
|
||||
salt: verificationSalt,
|
||||
derivedKey: derivedKeySalt,
|
||||
userIDEcnryptedDataKey: userIDEncryptedDataKey,
|
||||
userIDEncryptedDataKey: userIDEncryptedDataKey,
|
||||
isSetup: "true",
|
||||
username: name,
|
||||
email: email
|
||||
@ -46,7 +46,7 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {
|
||||
}
|
||||
|
||||
function isSubjectIdentifierSaved() {
|
||||
const value = sql.getValue("SELECT userIDEcnryptedDataKey FROM user_data;");
|
||||
const value = sql.getValue("SELECT userIDEncryptedDataKey FROM user_data;");
|
||||
if (value === undefined || value === null || value === "") return false;
|
||||
return true;
|
||||
}
|
||||
@ -58,7 +58,7 @@ function isUserSaved() {
|
||||
|
||||
function verifyOpenIDSubjectIdentifier(subjectIdentifier: string) {
|
||||
if (!sqlInit.isDbInitialized()) {
|
||||
throw new OpenIDError("Database not initialized!");
|
||||
throw new OpenIdError("Database not initialized!");
|
||||
}
|
||||
|
||||
if (isUserSaved()) {
|
||||
@ -100,7 +100,7 @@ function setDataKey(
|
||||
myScryptService.getSubjectIdentifierDerivedKey(subjectIdentifier, salt);
|
||||
|
||||
if (subjectIdentifierDerivedKey === undefined) {
|
||||
console.log("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");
|
||||
console.error("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");
|
||||
return undefined;
|
||||
}
|
||||
const newEncryptedDataKey = dataEncryptionService.encrypt(
|
||||
@ -116,16 +116,16 @@ function getDataKey(subjectIdentifier: string) {
|
||||
myScryptService.getSubjectIdentifierDerivedKey(subjectIdentifier);
|
||||
|
||||
const encryptedDataKey = sql.getValue(
|
||||
"SELECT userIDEcnryptedDataKey FROM user_data"
|
||||
"SELECT userIDEncryptedDataKey FROM user_data"
|
||||
);
|
||||
|
||||
if (encryptedDataKey === undefined || encryptedDataKey === null) {
|
||||
console.log("Encrypted data key empty!");
|
||||
if (!encryptedDataKey) {
|
||||
console.error("Encrypted data key empty!");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (subjectIdentifierDerivedKey === undefined) {
|
||||
console.log("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");
|
||||
if (!subjectIdentifierDerivedKey) {
|
||||
console.error("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");
|
||||
return undefined;
|
||||
}
|
||||
const decryptedDataKey = dataEncryptionService.decrypt(
|
||||
|
@ -126,14 +126,12 @@ function generateOAuthConfig() {
|
||||
return session;
|
||||
}
|
||||
|
||||
// 保存用户信息
|
||||
openIDEncryption.saveUser(
|
||||
req.oidc.user.sub.toString(),
|
||||
req.oidc.user.name.toString(),
|
||||
req.oidc.user.email.toString()
|
||||
);
|
||||
|
||||
// 设置登录状态
|
||||
req.session.loggedIn = true;
|
||||
req.session.lastAuthState = {
|
||||
totpEnabled: false,
|
||||
|
@ -52,7 +52,7 @@ async function initDbConnection() {
|
||||
tmpID INT,
|
||||
username TEXT,
|
||||
email TEXT,
|
||||
userIDEcnryptedDataKey TEXT,
|
||||
userIDEncryptedDataKey TEXT,
|
||||
userIDVerificationHash TEXT,
|
||||
salt TEXT,
|
||||
derivedKey TEXT,
|
||||
|
Loading…
x
Reference in New Issue
Block a user