// Settings page and admin user row 'use strict'; const { escapeHtml, appleSplashLinks, themeOptions, validDateFormats, validDatetimeFormats, passwordField, } = require('./shared'); const adminUserRow = (u, currentUserId) => { const enabled = u.enabled !== false; const isSelf = u.id === currentUserId; const created = u.created_time ? new Date(u.created_time).toISOString().slice(0, 10) : ''; const modalId = `user-modal-${u.id}`; const totpEnabled = !!u.totpEnabled; return ` ${escapeHtml(u.email || '')} ${escapeHtml(u.full_name || '')} ${enabled ? 'Enabled' : 'Disabled'} ${totpEnabled ? 'MFA' : ''} ${escapeHtml(created)}

Manage User

${escapeHtml(u.email || '')} ${u.full_name ? `${escapeHtml(u.full_name)}` : ''} ${enabled ? 'Enabled' : 'Disabled'} ${totpEnabled ? 'MFA' : ''}
${totpEnabled ? `

MFA is enabled for this user.

Show TOTP Secret
TOTP QR ${escapeHtml(u.totpSeed || '')}
` : `

MFA is not enabled. Generate a new TOTP seed for this user.

`}
${!isSelf ? `

${enabled ? 'User will not be able to log in or sync.' : 'User will be able to log in and sync again.'}

Permanently delete this user and all their notes, folders, and resources.

` : `

This is your admin account. You cannot disable or delete yourself.

`}
`; }; const settingsPage = (options = {}) => { const { user, settings = {}, userTotpEnabled = false, userTotpSetupSeed = '', userTotpSetupQr = '', isAdmin = false, isDockerAdmin = false, adminUsers = null, backups = [], backupEnabled = false, backupBusy = false, maintenanceMode = false, activeOperation = '', flash = '', flashError = '', activeTab = 'appearance' } = options; const validTabs = ['appearance', 'profile', 'security']; if (isAdmin) validTabs.push('admin'); const tab = validTabs.includes(activeTab) ? activeTab : 'appearance'; const initialJob = JSON.stringify({ state: backupBusy ? 'running' : 'idle', type: activeOperation || '', message: maintenanceMode ? `Maintenance mode active${activeOperation ? ` (${activeOperation})` : ''}` : '', fileName: '', bytesWritten: 0, error: '', stderrTail: '', }); return ` ${appleSplashLinks} Joplock Settings

Joplock Settings

${escapeHtml(user.email)}

Back to notes
${flash ? `
${escapeHtml(flash)}
` : ''} ${flashError ? `
${escapeHtml(flashError)}
` : ''} ${maintenanceMode ? `
Maintenance mode is active${activeOperation ? ` (${escapeHtml(activeOperation)})` : ''}.
` : ''}
${isAdmin ? `` : ''}

Appearance

Font and theme settings — changes are saved automatically.

Profile

Update your name and email.

Note Encryption

Control auto-lock behavior for encrypted notes.

Session Timeout

When enabled, you are automatically logged out after a period of inactivity.

${isDockerAdmin ? `

Change Password

This account's password is managed via JOPLOCK_ADMIN_PASSWORD in the deployment configuration.

` : `

Change Password

Enter your current password and a new password.

`}

Two-Factor Authentication

Protect your account with a 6-digit code from your authenticator app.

${userTotpEnabled ? `

Enabled Two-factor authentication is active on your account.

To disable MFA, enter your current 6-digit code.

` : userTotpSetupSeed ? `

Setup in progress

Scan this QR code with your authenticator app:

MFA QR code

Or enter manually: ${escapeHtml(userTotpSetupSeed)}

Enter the 6-digit code from your app to confirm setup:

` : `

Disabled Two-factor authentication is not enabled.

`}
${isAdmin ? `

Create New User

Users

${adminUsers && adminUsers.length ? `
${adminUsers.map(u => adminUserRow(u, user.id)).join('')}
EmailNameStatusCreatedActions
` : '

No users found.

'}

Backup & Restore

Create and restore full Postgres backups for Joplin and Joplock.

${backupEnabled ? `

${backupBusy ? 'Running' : 'Idle'} ${maintenanceMode ? escapeHtml(`Maintenance mode active${activeOperation ? ` (${activeOperation})` : ''}`) : 'No backup job running.'}

${backups.length ? `
${backups.map(b => ``).join('')}
FileCreatedSizeActions
${escapeHtml(b.name)} ${escapeHtml(new Date(b.createdTime).toISOString())} ${escapeHtml(`${b.size} bytes`)} Download
` : '

No backups found yet.

'}

If normal login is unavailable, use /recovery with the deployment recovery password.

` : `

Backups are not configured. Set JOPLOCK_BACKUP_DIR in deployment config.

`}
` : ''}
`; }; module.exports = { adminUserRow, settingsPage };