· 7 years ago · Jan 09, 2019, 11:06 AM
1$("#go").click(function () {
2 $('#grupoBotones').parent().hide();
3 $('#console').show();
4 $('#groupWinners').show();
5 participate();
6});
7
8function participate() {
9 var name = randomid();
10 var dominio = '@gmail.com'
11 var email = name + dominio;
12 $('#console').append('Participando con email: ' + email + '\n');
13 postEmail(email, false);
14}
15
16function randomid() {
17 var text = "";
18 var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
19 for (var i = 0; i < 26; i++) {
20 text += possible.charAt(Math.floor(Math.random() * possible.length));
21 }
22 return text;
23}
24
25function postEmail(email, enablePromo) {
26 var delay = $('#tiempo')[0].value * 1000;
27 var data = {
28 email: email,
29 receive_offert: enablePromo,
30 };
31 var url = 'https://www.ganasdetelepizza.es/check-mail';
32 $.ajax({
33 type: "POST",
34 url: url,
35 dataType: 'json',
36 contentType: "application/json",
37 crossDomain: true,
38 data: JSON.stringify(data),
39 success: function (result) {
40 var body = JSON.stringify(JSON.parse(result['body']));
41 var response = JSON.parse(body);
42 switch (response.responseMessage) {
43 case 'EMAIL_SAVED':
44 $('#console').append(' Email válido\n');
45 postUser(email);
46 break;
47 case 'DYNAMO_ERR':
48 $('#console').append(' Error interno\n');
49 setTimeout(participate, 30000);
50 break;
51 case 'USER_HAS_PARTICIPED':
52 $('#console').append(' El usuario ya ha participado con el email: ' + email + '\n');
53 setTimeout(participate, 30000);
54 break;
55 case 'FORBIDDEN':
56 $('#console').append(' IP Bloqueada\n');
57 setTimeout(participate, 30000);
58 break;
59 default:
60 $('#console').append(' Email no válido ' + email + '\n');
61 setTimeout(participate, 30000);
62 break;
63 }
64 },
65 error: function (e) {
66 $('#console').append('ERROR: ' + e.status + ' ' + e.statusText + '\n');
67 }
68 });
69}
70
71function postUser(email) {
72 var delay = $('#tiempo')[0].value * 1000;
73 var data = {
74 email: email
75 };
76 var url = 'https://www.ganasdetelepizza.es/check-prize';
77 $.ajax({
78 type: "POST",
79 url: url,
80 dataType: 'json',
81 contentType: "application/json",
82 crossDomain: true,
83 data: JSON.stringify(data),
84 success: function (result) {
85 var body = JSON.stringify(JSON.parse(result['body']));
86 var response = JSON.parse(body);
87 switch (response.responseMessage) {
88 case 'USER_IS_WINNER':
89 $('#console').append(' GANADOR!! ' + email + '\n\n');
90 $('#consoleWinners').append(email + '\n')
91 alert('El correo ' + email + ' ha sido ganador');
92 setTimeout(participate, delay);
93 break;
94 case 'USER_NOT_WIN':
95 $('#console').append(' No ganador\n\n');
96 setTimeout(participate, delay);
97 break;
98 default:
99 $('#console').append('Error email no válido\n');
100 break;
101 }
102 },
103 error: function (e) {
104 $('#console').append('ERROR: ' + e.status + ' ' + e.statusText + '\n');
105 }
106 });
107}