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