mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-25 22:12:31 +08:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
![]() |
import options from '../../services/options.js';
|
||
|
import {generateSecret} from 'time2fa';
|
||
|
|
||
|
function generateTOTPSecret() {
|
||
|
return {success: 'true', message: generateSecret()};
|
||
|
}
|
||
|
|
||
|
function getTotpEnabled() {
|
||
|
if (process.env.TOTP_ENABLED === undefined) {
|
||
|
return false;
|
||
|
}
|
||
|
if (process.env.TOTP_ENABLED.toLocaleLowerCase() !== 'true') {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
function getTOTPStatus() {
|
||
|
const totpEnabled = options.getOptionBool('totpEnabled');
|
||
|
return {success: 'true', message: totpEnabled, enabled: getTotpEnabled()};
|
||
|
}
|
||
|
|
||
|
function enableTOTP() {
|
||
|
if (!getTotpEnabled()) {
|
||
|
return {success: 'false'};
|
||
|
}
|
||
|
|
||
|
options.setOption('totpEnabled', true);
|
||
|
options.setOption('oAuthEnabled', false);
|
||
|
return {success: 'true'};
|
||
|
}
|
||
|
|
||
|
function disableTOTP() {
|
||
|
options.setOption('totpEnabled', false);
|
||
|
return {success: true};
|
||
|
}
|
||
|
|
||
|
function getSecret() {
|
||
|
return process.env.TOTP_SECRET;
|
||
|
}
|
||
|
|
||
|
export default {
|
||
|
generateSecret: generateTOTPSecret,
|
||
|
getTOTPStatus,
|
||
|
enableTOTP,
|
||
|
disableTOTP,
|
||
|
getSecret
|
||
|
};
|