mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 00:12:11 +08:00
add log in frontend
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import settings from './settings.js';
|
||||
|
||||
function logDebug(msg, obj) {
|
||||
if (settings.isEnableDebug()) {
|
||||
if (obj) {
|
||||
console.debug('[lab Debug] ' + msg, obj);
|
||||
} else {
|
||||
console.debug('[lab Debug] ' + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logInfo(msg, obj) {
|
||||
if (obj) {
|
||||
console.info('[lab Info] ' + msg, obj);
|
||||
} else {
|
||||
console.info('[lab Info] ' + msg);
|
||||
}
|
||||
}
|
||||
|
||||
function logWarn(msg, obj) {
|
||||
if (obj) {
|
||||
console.warn('[lab Warn] ' + msg, obj);
|
||||
} else {
|
||||
console.warn('[lab Warn] ' + msg);
|
||||
}
|
||||
}
|
||||
|
||||
function logError(msg, obj) {
|
||||
if (obj) {
|
||||
console.error('[lab Error] ' + msg, obj);
|
||||
} else {
|
||||
console.error('[lab Error] ' + msg);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
debug: logDebug,
|
||||
info: logInfo,
|
||||
warn: logWarn,
|
||||
error: logError
|
||||
};
|
||||
@@ -5,6 +5,7 @@ const serverSettingsCookieKey = 'ACP_SETTINGS';
|
||||
|
||||
const defaultSettings = {
|
||||
lang: 'en',
|
||||
debug: false,
|
||||
applicationLock: false,
|
||||
applicationLockWebAuthn: false,
|
||||
autoUpdateExchangeRatesData: true,
|
||||
@@ -75,6 +76,8 @@ function clearSettings() {
|
||||
export default {
|
||||
getLanguage: () => getOriginalOption('lang'),
|
||||
setLanguage: value => setOption('lang', value),
|
||||
isEnableDebug: () => getOption('debug'),
|
||||
setEnableDebug: value => setOption('debug', value),
|
||||
isEnableApplicationLock: () => getOption('applicationLock'),
|
||||
setEnableApplicationLock: value => setOption('applicationLock', value),
|
||||
isEnableApplicationLockWebAuthn: () => getOption('applicationLockWebAuthn'),
|
||||
|
||||
+19
-3
@@ -1,4 +1,5 @@
|
||||
import CBOR from 'cbor-js';
|
||||
import logger from './logger.js';
|
||||
import utils from './utils.js';
|
||||
|
||||
const PUBLIC_KEY_CREDENTIAL_CREATION_OPTIONS_TEMPLATE = {
|
||||
@@ -72,6 +73,8 @@ function registerCredential({ username, nickname }, userSecret) {
|
||||
}
|
||||
});
|
||||
|
||||
logger.debug('webauthn create options', publicKeyCredentialCreationOptions);
|
||||
|
||||
return navigator.credentials.create({
|
||||
publicKey: publicKeyCredentialCreationOptions
|
||||
}).then(rawCredential => {
|
||||
@@ -80,15 +83,20 @@ function registerCredential({ username, nickname }, userSecret) {
|
||||
|
||||
const challengeFromClientData = clientData && clientData.challenge ? atob(clientData.challenge) : null;
|
||||
|
||||
logger.debug('webauthn create raw response', rawCredential);
|
||||
|
||||
if (rawCredential && rawCredential.rawId &&
|
||||
clientData && clientData.type === 'webauthn.create' && challengeFromClientData === challenge) {
|
||||
|
||||
return {
|
||||
const ret = {
|
||||
id: utils.base64encode(rawCredential.rawId),
|
||||
clientData: clientData,
|
||||
publicKey: publicKey,
|
||||
rawCredential: rawCredential
|
||||
};
|
||||
|
||||
logger.debug('webauthn create response', ret);
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
return Promise.reject({
|
||||
invalid: true
|
||||
@@ -137,22 +145,30 @@ function verifyCredential(credentialId) {
|
||||
});
|
||||
publicKeyCredentialRequestOptions.allowCredentials[0].id = Uint8Array.from(atob(credentialId), c=>c.charCodeAt(0)).buffer;
|
||||
|
||||
logger.debug('webauthn get options', publicKeyCredentialRequestOptions);
|
||||
|
||||
return navigator.credentials.get({
|
||||
publicKey: publicKeyCredentialRequestOptions
|
||||
}).then(rawCredential => {
|
||||
const clientData = rawCredential ? parseClientData(rawCredential) : null;
|
||||
const challengeFromClientData = clientData && clientData.challenge ? atob(clientData.challenge) : null;
|
||||
|
||||
logger.debug('webauthn get raw response', rawCredential);
|
||||
|
||||
if (rawCredential && rawCredential.rawId &&
|
||||
rawCredential.response && rawCredential.response.userHandle &&
|
||||
clientData && clientData.type === 'webauthn.get' && challengeFromClientData === challenge) {
|
||||
|
||||
return {
|
||||
const ret = {
|
||||
id: utils.base64encode(rawCredential.rawId),
|
||||
userSecret: utils.arrayBufferToString(rawCredential.response.userHandle),
|
||||
clientData: clientData,
|
||||
rawCredential: rawCredential
|
||||
};
|
||||
|
||||
logger.debug('webauthn get response', ret);
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
return Promise.reject({
|
||||
invalid: true
|
||||
|
||||
Reference in New Issue
Block a user