Kontakt-Modul
Dieser Commit ist enthalten in:
committet von
Server Deploy
Ursprung
623bbdf5dd
Commit
7d67557be4
@ -305,6 +305,46 @@ function sanitizeMiddleware(req, res, next) {
|
||||
next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontakt-Validierung Middleware
|
||||
*/
|
||||
validators.contact = function(req, res, next) {
|
||||
const errors = [];
|
||||
const { firstName, lastName, company, email, phone, mobile, website } = req.body;
|
||||
|
||||
// Mindestens ein Name oder Firma muss vorhanden sein
|
||||
if (!firstName && !lastName && !company) {
|
||||
errors.push('Mindestens Vorname, Nachname oder Firma muss angegeben werden');
|
||||
}
|
||||
|
||||
// Email validieren
|
||||
if (email) {
|
||||
const emailError = validators.email(email, 'E-Mail');
|
||||
if (emailError) errors.push(emailError);
|
||||
}
|
||||
|
||||
// Website URL validieren
|
||||
if (website) {
|
||||
const urlError = validators.url(website, 'Website');
|
||||
if (urlError) errors.push(urlError);
|
||||
}
|
||||
|
||||
// Telefonnummer Format (optional)
|
||||
if (phone && !/^[\d\s\-\+\(\)]+$/.test(phone)) {
|
||||
errors.push('Telefonnummer enthält ungültige Zeichen');
|
||||
}
|
||||
|
||||
if (mobile && !/^[\d\s\-\+\(\)]+$/.test(mobile)) {
|
||||
errors.push('Mobilnummer enthält ungültige Zeichen');
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return res.status(400).json({ errors });
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
stripHtml,
|
||||
sanitizeMarkdown,
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren