浏览代码

Done with useless spaces

父节点
当前提交
21e86f5fe8
签署人:: Brendan Abolivier <contact@brendanabolivier.com> GPG 密钥 ID: 8EF1500759F70623
共有 7 个文件被更改,包括 117 次插入117 次删除
  1. 22
    22
      front/form.js
  2. 11
    11
      front/index.html
  3. 18
    18
      locales/en.json
  4. 18
    18
      locales/fr.json
  5. 16
    16
      server.js
  6. 17
    17
      settings.example.json
  7. 15
    15
      template.example.pug

+ 22
- 22
front/form.js 查看文件

@@ -88,7 +88,7 @@ function getServer() {
88 88
 				return url.match(/^(https?:\/\/[^\/]+)/)[1];
89 89
 			}
90 90
 		}
91
-	}	
91
+	}
92 92
 }
93 93
 
94 94
 
@@ -100,12 +100,12 @@ function generateForm(id) {
100 100
 	getLangSync();
101 101
 	// Get custom fields if defined in the configuration
102 102
 	getCustomFieldsSync();
103
-	
103
+
104 104
 	var el = document.getElementById(id);
105
-	
105
+
106 106
 	// Set the form's behaviour
107 107
 	el.setAttribute('onsubmit', 'sendForm(); return false;');
108
-	
108
+
109 109
 	// Add an empty paragraph for status
110 110
 	var status = document.createElement('p');
111 111
 	status.setAttribute('id', 'form_status');
@@ -138,13 +138,13 @@ function generateForm(id) {
138 138
 			required: true
139 139
 		})
140 140
 	};
141
-	
141
+
142 142
 	// Adding custom fields
143 143
 	for(let fieldName in customFields) {
144 144
 		let field = customFields[fieldName];
145 145
 		DOMFields[fieldName] = getField(field);
146 146
 	}
147
-	
147
+
148 148
 	// Adding all nodes to document
149 149
 	for(let field in DOMFields) {
150 150
 		el.appendChild(DOMFields[field]);
@@ -152,7 +152,7 @@ function generateForm(id) {
152 152
 
153 153
 	// Adding submit button
154 154
 	el.appendChild(getSubmitButton('form_subm', lang.form_subm_label));
155
-	
155
+
156 156
 	// Retrieve the token from the server
157 157
 	getToken();
158 158
 }
@@ -184,7 +184,7 @@ function getField(fieldInfos) {
184 184
 	if(labels) {
185 185
 		block.appendChild(getLabel(fieldInfos.label, field.id));
186 186
 	}
187
-	
187
+
188 188
 	// Assemble the block and return it
189 189
 	block.appendChild(field);
190 190
 	return block;
@@ -197,10 +197,10 @@ function getField(fieldInfos) {
197 197
 // return: a label node the field's description
198 198
 function getLabel(content, id) {
199 199
 	var label = document.createElement('label');
200
-	
200
+
201 201
 	label.setAttribute('for', id);
202 202
 	label.innerHTML = content;
203
-	
203
+
204 204
 	return label;
205 205
 }
206 206
 
@@ -219,7 +219,7 @@ function getSelectField(fieldInfos) {
219 219
 	field.setAttribute('id', prefix + '_' + fieldInfos.name + '_select');
220 220
 
221 221
 	let index = 0;
222
-	
222
+
223 223
 	// Add header option, useful if the field is required
224 224
 	let header = document.createElement('option');
225 225
 	// The value must be an empty string so the browser can block the submit
@@ -227,7 +227,7 @@ function getSelectField(fieldInfos) {
227 227
 	header.setAttribute('value', '');
228 228
 	header.innerHTML = lang.form_select_header_option;
229 229
 	field.appendChild(header);
230
-	
230
+
231 231
 	// Add all options to select
232 232
 	for(let choice of fieldInfos.options) {
233 233
 		let option = document.createElement('option');
@@ -273,13 +273,13 @@ function getTextarea(fieldInfos, required) {
273 273
 // return: a HTML element of the given tag with basic info given as input
274 274
 function getBaseField(fieldInfos, required, tag) {
275 275
 	let field = document.createElement(tag);
276
-	
276
+
277 277
 	if(fieldInfos.required) {
278 278
 		field.setAttribute('required', 'required');
279 279
 	}
280 280
 	field.setAttribute('placeholder', fieldInfos.label);
281 281
 	field.setAttribute('id', prefix + '_' + fieldInfos.name + '_' + tag);
282
-	
282
+
283 283
 	return field;
284 284
 }
285 285
 
@@ -290,18 +290,18 @@ function getBaseField(fieldInfos, required, tag) {
290 290
 // return: a div node containing the button
291 291
 function getSubmitButton(id, text) {
292 292
 	var submit = document.createElement('div');
293
-	
293
+
294 294
 	submit.setAttribute('id', id);
295
-	
295
+
296 296
 	var button = document.createElement('button');
297
-	
297
+
298 298
 	button.setAttribute('type', 'submit');
299 299
 	button.setAttribute('id', id + '_btn');
300
-	
300
+
301 301
 	button.innerHTML = text;
302
-	
302
+
303 303
 	submit.appendChild(button);
304
-	
304
+
305 305
 	return submit;
306 306
 }
307 307
 
@@ -313,11 +313,11 @@ function sendForm() {
313 313
 	let status = document.getElementById('form_status');
314 314
 	status.setAttribute('class', 'sending');
315 315
 	status.innerHTML = lang.send_status_progress;
316
-	
316
+
317 317
 	xhr.send.open('POST', server + '/send');
318 318
 	xhr.send.setRequestHeader('Content-Type', 'application/json');
319 319
 	xhr.send.send(JSON.stringify(getFormData()));
320
-	
320
+
321 321
 	// Get a new token
322 322
 	getToken();
323 323
 }

+ 11
- 11
front/index.html 查看文件

@@ -1,14 +1,14 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3
-    <head>
4
-        <meta charset="utf-8">
5
-        <title>Send Me A Mail</title>
6
-        <script src="http://localhost:1970/form.js" charset="utf-8"></script>
7
-    </head>
8
-    <body>
9
-        <form id="smam"></form>
10
-        <script type="text/javascript">
11
-            generateForm('smam');
12
-        </script>
13
-    </body>
3
+	<head>
4
+		<meta charset="utf-8">
5
+		<title>Send Me A Mail</title>
6
+		<script src="http://localhost:1970/form.js" charset="utf-8"></script>
7
+	</head>
8
+	<body>
9
+		<form id="smam"></form>
10
+		<script type="text/javascript">
11
+			generateForm('smam');
12
+		</script>
13
+	</body>
14 14
 </html>

+ 18
- 18
locales/en.json 查看文件

@@ -1,21 +1,21 @@
1 1
 {
2
-    "client": {
3
-        "form_name_label": "Your name",
4
-        "form_addr_label": "Your e-mail address",
5
-        "form_subj_label": "Your message's subject",
6
-        "form_mesg_label": "Your message",
7
-        "form_subm_label": "Send the mail",
2
+	"client": {
3
+		"form_name_label": "Your name",
4
+		"form_addr_label": "Your e-mail address",
5
+		"form_subj_label": "Your message's subject",
6
+		"form_mesg_label": "Your message",
7
+		"form_subm_label": "Send the mail",
8 8
 		"form_select_header_option": "Select an answer",
9
-        "send_status_success": "Your message has been sent.",
10
-        "send_status_failure": "An error happened while sending your message, please retry later.",
11
-        "send_status_progress": "Sending the e-mail"
12
-    },
13
-    "server": {
14
-        "log_server_start": "Server started on",
15
-        "log_sending": "Sending message from",
16
-        "log_send_success": "Message sent to",
17
-        "log_send_failure": "Message failed to send to",
18
-        "log_invalid_token": "just tried to send a message with an invalid token",
19
-        "log_cleared_token": "Cleared expired tokens"
20
-    }
9
+		"send_status_success": "Your message has been sent.",
10
+		"send_status_failure": "An error happened while sending your message, please retry later.",
11
+		"send_status_progress": "Sending the e-mail"
12
+	},
13
+	"server": {
14
+		"log_server_start": "Server started on",
15
+		"log_sending": "Sending message from",
16
+		"log_send_success": "Message sent to",
17
+		"log_send_failure": "Message failed to send to",
18
+		"log_invalid_token": "just tried to send a message with an invalid token",
19
+		"log_cleared_token": "Cleared expired tokens"
20
+	}
21 21
 }

+ 18
- 18
locales/fr.json 查看文件

@@ -1,21 +1,21 @@
1 1
 {
2
-    "client": {
3
-        "form_name_label": "Votre nom",
4
-        "form_addr_label": "Votre adresse e-mail",
5
-        "form_subj_label": "Sujet de votre message",
6
-        "form_mesg_label": "Votre message",
7
-        "form_subm_label": "Envoyer",
2
+	"client": {
3
+		"form_name_label": "Votre nom",
4
+		"form_addr_label": "Votre adresse e-mail",
5
+		"form_subj_label": "Sujet de votre message",
6
+		"form_mesg_label": "Votre message",
7
+		"form_subm_label": "Envoyer",
8 8
 		"form_select_header_option": "Sélectionnez une réponse",
9
-        "send_status_success": "Votre message a été envoyé.",
10
-        "send_status_failure": "Une erreur est survenue lors de l'envoi du message, merci de réessayer plus tard.",
11
-        "send_status_progress": "Envoi du message en cours"
12
-    },
13
-    "server": {
14
-        "log_server_start": "Serveur démarré pour",
15
-        "log_sending": "Envoi d'un message de",
16
-        "log_send_success": "Message envoyé à",
17
-        "log_send_failure": "Erreur lors de l'envoi du message à",
18
-        "log_invalid_token": "vient d'essayer d'envoyer un message avec un jeton invalide",
19
-        "log_cleared_token": "Les jetons expirés ont été effacés"
20
-    }
9
+		"send_status_success": "Votre message a été envoyé.",
10
+		"send_status_failure": "Une erreur est survenue lors de l'envoi du message, merci de réessayer plus tard.",
11
+		"send_status_progress": "Envoi du message en cours"
12
+	},
13
+	"server": {
14
+		"log_server_start": "Serveur démarré pour",
15
+		"log_sending": "Envoi d'un message de",
16
+		"log_send_success": "Message envoyé à",
17
+		"log_send_failure": "Erreur lors de l'envoi du message à",
18
+		"log_invalid_token": "vient d'essayer d'envoyer un message avec un jeton invalide",
19
+		"log_cleared_token": "Les jetons expirés ont été effacés"
20
+	}
21 21
 }

+ 16
- 16
server.js 查看文件

@@ -70,24 +70,24 @@ app.get('/register', function(req, res, next) {
70 70
 app.post('/send', function(req, res, next) {
71 71
 	// Response will be JSON
72 72
 	res.header('Access-Control-Allow-Headers', 'Content-Type');
73
-	
73
+
74 74
 	if(!checkBody(req.body)) {
75 75
 		return res.status(400).send();
76 76
 	}
77
-	
77
+
78 78
 	let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
79
-	
79
+
80 80
 	// Token verification
81 81
 	if(!checkToken(ip, req.body.token)) {
82 82
 		return res.status(403).send();
83 83
 	}
84
-	
84
+
85 85
 	// Count the failures
86 86
 	let status = {
87 87
 		failed: 0,
88 88
 		total: settings.recipients.length
89 89
 	};
90
-	
90
+
91 91
 	// params will be used as:
92 92
 	// - values for html generation from the pug template
93 93
 	// - parameters for sending the mail(s)
@@ -100,14 +100,14 @@ app.post('/send', function(req, res, next) {
100 100
 
101 101
 	// Process custom fields to get data we can use in the HTML generation
102 102
 	params.custom = processCustom(req.body.custom);
103
-	
103
+
104 104
 	// Replacing the mail's content with HTML from the pug template
105 105
 	// Commenting the line below will bypass the generation and only user the
106 106
 	// text entered by the user
107 107
 	params.html = pug.renderFile('template.pug', params);
108
-	
108
+
109 109
 	log.info(lang.log_sending, params.replyTo);
110
-	
110
+
111 111
 	// Send the email to all users
112 112
 	sendMails(params, function(err, infos) {
113 113
 		if(err) {
@@ -136,7 +136,7 @@ app.get('/lang', function(req, res, next) {
136 136
 	if(settings.labels !== undefined) {
137 137
 		labels = settings.labels;
138 138
 	}
139
-	
139
+
140 140
 	// Send the infos
141 141
 	res.status(200).send({
142 142
 		'labels': labels,
@@ -152,7 +152,7 @@ app.get('/fields', function(req, res, next) {
152 152
 
153 153
 	// Send an object anyway, its size will determine if we need to display any
154 154
 	let customFields = settings.customFields || {};
155
-	
155
+
156 156
 	// Send custom fields data
157 157
 	res.status(200).send(customFields);
158 158
 });
@@ -223,7 +223,7 @@ function logStatus(infos) {
223 223
 // return: true if the user was registered, false else
224 224
 function checkToken(ip, token) {
225 225
 	let verified = false;
226
-	
226
+
227 227
 	// Check if there's at least one token for this IP
228 228
 	if(tokens[ip] !== undefined) {
229 229
 		if(tokens[ip].length !== 0) {
@@ -239,11 +239,11 @@ function checkToken(ip, token) {
239 239
 			}
240 240
 		} 
241 241
 	}
242
-	
242
+
243 243
 	if(!verified) {
244 244
 		log.warn(ip, lang.log_invalid_token);
245 245
 	}
246
-	
246
+
247 247
 	return verified;
248 248
 }
249 249
 
@@ -285,7 +285,7 @@ function isInvalid(field) {
285 285
 function cleanTokens() {
286 286
 	// Get current time for comparison
287 287
 	let now = new Date().getTime();
288
-	
288
+
289 289
 	for(let ip in tokens) { // Check for each IP in the object
290 290
 		for(let token of tokens[ip]) { // Check for each token of an IP
291 291
 			if(token.expire < now) { // Token has expired
@@ -296,7 +296,7 @@ function cleanTokens() {
296 296
 			delete tokens[ip];
297 297
 		}
298 298
 	}
299
-	
299
+
300 300
 	log.info(lang.log_cleared_token);
301 301
 }
302 302
 
@@ -332,6 +332,6 @@ function processCustom(custom) {
332 332
 			}
333 333
 		}
334 334
 	}
335
-	
335
+
336 336
 	return fields;
337 337
 }

+ 17
- 17
settings.example.json 查看文件

@@ -1,19 +1,19 @@
1 1
 {
2
-    "mailserver": {
3
-        "pool": true,
4
-        "host": "mail.example.tld",
5
-        "port": 465,
6
-        "secure": true,
7
-        "auth": {
8
-            "user": "noreply@example.tld",
9
-            "pass": "hackme"
10
-        }
11
-    },
12
-    "recipients": [
13
-        "you@example.tld",
14
-        "someone.else@example.com"
15
-    ],
16
-    "formOrigin": "https://example.tld",
17
-    "language": "en",
18
-    "labels": true
2
+	"mailserver": {
3
+		"pool": true,
4
+		"host": "mail.example.tld",
5
+		"port": 465,
6
+		"secure": true,
7
+		"auth": {
8
+			"user": "noreply@example.tld",
9
+			"pass": "hackme"
10
+		}
11
+	},
12
+	"recipients": [
13
+		"you@example.tld",
14
+		"someone.else@example.com"
15
+	],
16
+	"formOrigin": "https://example.tld",
17
+	"language": "en",
18
+	"labels": true
19 19
 }

+ 15
- 15
template.example.pug 查看文件

@@ -1,16 +1,16 @@
1 1
 html
2
-    body
3
-        p.subj
4
-            span(style="font-weight:bold") Subject:&nbsp;
5
-            span= subject
6
-        p.from
7
-            span(style="font-weight:bold") Sent from:&nbsp;
8
-            span= replyTo
9
-        each field in custom
10
-            p.custom
11
-                span(style="font-weight:bold")= field.label + ': '
12
-                span= field.value
13
-        p.message
14
-            span(style="font-weight:bold") Message:&nbsp;
15
-        
16
-        p= html
2
+	body
3
+		p.subj
4
+			span(style="font-weight:bold") Subject:&nbsp;
5
+			span= subject
6
+		p.from
7
+			span(style="font-weight:bold") Sent from:&nbsp;
8
+			span= replyTo
9
+		each field in custom
10
+			p.custom
11
+				span(style="font-weight:bold")= field.label + ': '
12
+				span= field.value
13
+		p.message
14
+			span(style="font-weight:bold") Message:&nbsp;
15
+		
16
+		p= html