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:
@@ -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