feat(PublicPages): add email and phone obfucations

This commit is contained in:
Matthieu Bessat 2020-08-14 16:30:08 +02:00
parent 9ae135f816
commit 4d46ed86f4
4 changed files with 139 additions and 29 deletions

View file

@ -99,39 +99,73 @@ export default class PublicController {
version.cover = { location: "https://fva-condorcet.s3.fr-par.scw.cloud/default-cover-plz-get-you-a-real-image.jpg" }
}
let formatPhone = (phone: string) => {
if (phone.indexOf('+33') === 0) {
phone = '0' + phone.substr(3)
}
let phoneSplit = ''
let partEnd = false
for (var i = 0; i < phone.length; i++) {
phoneSplit += phone.charAt(i)
if (partEnd === true) {
phoneSplit += ' '
let offuscate = (original: string) => {
if (original.length === 0) { return original }
let cipher: string[] = []
let data: string = Buffer.from(original, 'utf-8').toString('base64')
data = data.replace(/A/gm, '$')
data = data.replace(/c/gm, '£')
data = data.replace(/b/gm, 'ù')
data = data.replace(/d/gm, '#')
data = data.replace(/e/gm, 'µ')
data = data.replace(/z/gm, '§')
data = data.replace(/i/gm, 'à')
data = data.replace(/f/gm, '|')
let remain = data
let take: number = 0
while (remain.length != 0) {
take = remain.length
if (take > 5) { take = 5 }
take = Math.floor(Math.random() * (take + 1))
if (take === 0) { take = 2 }
if (take > remain.length) {
take = remain.length
}
partEnd = !partEnd
cipher.push('%_' + remain.substr(0, take) + '%_')
remain = remain.substr(take)
}
return ["+33" + phone.substr(1), phoneSplit]
return JSON.stringify(cipher).replace(/"/gm, "'")
}
/**
* Parse contact
*/
if (Utils.isUsable(version.contacts)) {
if (Utils.isStrUsable(version.contacts, 'email')) {
version.contacts.email = offuscate(version.contacts.email)
}
if (Utils.isStrUsable(version.contacts, 'address')) {
version.contacts.address = version.contacts.address.split('\n')
}
if (Utils.isStrUsable(version.contacts, 'phone')) {
let formated: any = formatPhone(version.contacts.phone)
version.contacts.phoneInt = formated[0]
version.contacts.phoneSplit = formated[1]
//let formated: any = formatPhone(version.contacts.phone)
version.contacts.phone = offuscate(version.contacts.phone)
}
if (Utils.isUsable(version.contacts, 'peoples') && Array.isArray(version.contacts.peoples)) {
version.contacts.peoples = version.contacts.peoples.map((p: any) => {
let formated: any = formatPhone(p.phone)
p.phoneInt = formated[0]
p.phoneSplit = formated[1]
// let formated: any = formatPhone(p.phone)
// p.phoneInt = formated[0]
// p.phoneSplit = formated[1]
p.email = offuscate(p.email)
p.phone = offuscate(p.phone)
return p
})
}
if (Utils.isStrUsable(version.contacts, 'website')) {
if (version.contacts.website.indexOf('https://') === -1 || version.contacts.website.indexOf('https://') === -1) {
version.contacts.website = 'http://' + version.contacts.website
}
try {
let url = new URL(version.contacts.website)
version.contacts.websiteLabel = url.hostname + (url.pathname === '/' ? '' : url.pathname)
} catch (err) {
console.error(err)
version.contacts.website = version.contacts.websiteLabel = "OULA, c'est pas bon :("
}
}
if (Utils.isStrUsable(version.contacts, 'facebook')) {
try {
version.contacts.facebookLabel = new URL(version.contacts.facebook).pathname.replace('/', '')
@ -157,12 +191,20 @@ export default class PublicController {
}
}
}
/**
* Parse gallery
*/
if (Array.isArray(version.gallery)) {
version.gallery = version.gallery.slice(0, 5).map((media: any) => {
media.isVideo = media.contentType.indexOf('video/') !== -1
return media
})
}
/**
* Parse schedule
*/
if (Utils.isUsable(version, 'schedule')) {
// TODO: Rassembler les horaires qui sont dans le même jour, uniquement pour le front
version.schedule = version.schedule.map((s: any) => {
@ -193,6 +235,12 @@ export default class PublicController {
// if (hour.charAt(1) === ':') {
// hour = '0' + hour
// }
/**
* Obfuscate emails and phone
*/
res.render('organization.twig', {
layout: 'standalone',
data: version,