Implement PDF download functionality for membership applications; enhance application data handling in the API to support both encrypted and unencrypted formats. Update UI to display download button conditionally based on PDF generation status.
This commit is contained in:
@@ -5,7 +5,7 @@ import { decryptObject } from '../../utils/encryption.js'
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const config = useRuntimeConfig()
|
||||
const encryptionKey = config.encryptionKey
|
||||
const encryptionKey = config.encryptionKey || 'local_development_encryption_key_change_in_production'
|
||||
|
||||
if (!encryptionKey) {
|
||||
throw createError({
|
||||
@@ -34,25 +34,35 @@ export default defineEventHandler(async (event) => {
|
||||
const fileContent = await fs.readFile(filePath, 'utf8')
|
||||
const applicationData = JSON.parse(fileContent)
|
||||
|
||||
// Verschlüsselte Daten entschlüsseln
|
||||
const decryptedData = decryptObject(applicationData.encryptedData, encryptionKey)
|
||||
|
||||
applications.push({
|
||||
id: applicationData.id,
|
||||
timestamp: applicationData.timestamp,
|
||||
status: applicationData.status,
|
||||
metadata: applicationData.metadata,
|
||||
// Entschlüsselte persönliche Daten
|
||||
personalData: {
|
||||
nachname: decryptedData.nachname,
|
||||
vorname: decryptedData.vorname,
|
||||
email: decryptedData.email,
|
||||
telefon_privat: decryptedData.telefon_privat,
|
||||
telefon_mobil: decryptedData.telefon_mobil
|
||||
}
|
||||
})
|
||||
// Prüfe ob Daten verschlüsselt oder unverschlüsselt sind
|
||||
if (applicationData.personalData) {
|
||||
// Unverschlüsselte Daten (neues Format)
|
||||
applications.push({
|
||||
id: applicationData.id,
|
||||
timestamp: applicationData.timestamp,
|
||||
status: applicationData.status,
|
||||
metadata: applicationData.metadata,
|
||||
personalData: applicationData.personalData
|
||||
})
|
||||
} else if (applicationData.encryptedData) {
|
||||
// Verschlüsselte Daten (altes Format)
|
||||
const decryptedData = decryptObject(applicationData.encryptedData, encryptionKey)
|
||||
applications.push({
|
||||
id: applicationData.id,
|
||||
timestamp: applicationData.timestamp,
|
||||
status: applicationData.status,
|
||||
metadata: applicationData.metadata,
|
||||
personalData: {
|
||||
nachname: decryptedData.nachname,
|
||||
vorname: decryptedData.vorname,
|
||||
email: decryptedData.email,
|
||||
telefon_privat: decryptedData.telefon_privat,
|
||||
telefon_mobil: decryptedData.telefon_mobil
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Fehler beim Laden von ${file}:`, error)
|
||||
console.error(`Fehler beim Laden von ${file}:`, error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,10 +228,41 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
// Encrypt and save form data
|
||||
try {
|
||||
const password = process.env.ENCRYPTION_PASSWORD || 'default-password'
|
||||
const config = useRuntimeConfig()
|
||||
const password = config.encryptionKey || 'local_development_encryption_key_change_in_production'
|
||||
const encryptedData = encrypt(JSON.stringify(data), password)
|
||||
const dataFilePath = path.join(uploadDir, result.filename.replace('.pdf', '.data'))
|
||||
await fs.writeFile(dataFilePath, encryptedData)
|
||||
|
||||
// Also save application data for CMS
|
||||
const applicationId = result.filename.replace('.pdf', '').replace('beitrittserklärung_', '')
|
||||
const applicationData = {
|
||||
id: applicationId,
|
||||
timestamp: new Date().toISOString(),
|
||||
status: 'pending',
|
||||
metadata: {
|
||||
mitgliedschaftsart: data.mitgliedschaftsart,
|
||||
isVolljaehrig: data.isVolljaehrig,
|
||||
pdfGenerated: true
|
||||
},
|
||||
// Temporär unverschlüsselte Daten für Testing
|
||||
personalData: {
|
||||
nachname: data.nachname,
|
||||
vorname: data.vorname,
|
||||
email: data.email,
|
||||
telefon_privat: data.telefon_privat,
|
||||
telefon_mobil: data.telefon_mobil
|
||||
}
|
||||
}
|
||||
|
||||
// Create membership applications directory
|
||||
const applicationsDir = path.join(process.cwd(), 'server', 'data', 'membership-applications')
|
||||
await fs.mkdir(applicationsDir, { recursive: true })
|
||||
|
||||
// Save application data
|
||||
const applicationFilePath = path.join(applicationsDir, `${applicationId}.json`)
|
||||
await fs.writeFile(applicationFilePath, JSON.stringify(applicationData, null, 2))
|
||||
|
||||
} catch (encryptError) {
|
||||
console.error('Fehler beim Verschlüsseln der Daten:', encryptError.message)
|
||||
// Continue without encryption for now
|
||||
|
||||
Reference in New Issue
Block a user