1 | $("#Form-Format-Visible").on('submit', function() { |
---|
2 | //var formData = new FormData(document.getElementById("form")); |
---|
3 | var formData = new FormData(); |
---|
4 | |
---|
5 | formData.append("upload", $("#file-sign-ft_Vble")[0].files[0]); |
---|
6 | |
---|
7 | $.ajax({ |
---|
8 | //url: "https://192.168.12.125:8443/Murachi/0.1/archivos", |
---|
9 | url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos", |
---|
10 | type: "post", |
---|
11 | dataType: "json", |
---|
12 | data: formData, |
---|
13 | cache: false, |
---|
14 | contentType: false, |
---|
15 | processData: false, |
---|
16 | xhrFields: {withCredentials: true}, |
---|
17 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
18 | success: function(response) { |
---|
19 | //alert(JSON.stringify(response)); |
---|
20 | var html = manejoJsonPDF(JSON.stringify(response)); |
---|
21 | document.getElementById("respuesta").innerHTML = html; |
---|
22 | |
---|
23 | // identificador del archivo en el servidor |
---|
24 | var fileId = response.fileId.toString(); |
---|
25 | var cert; |
---|
26 | |
---|
27 | window.hwcrypto.getCertificate({lang: "en"}).then(function(response) { |
---|
28 | var cert = response; |
---|
29 | |
---|
30 | var parameters = JSON.stringify({ |
---|
31 | "fileId":fileId, |
---|
32 | "certificate":cert.hex, |
---|
33 | "reason":"Certificado", |
---|
34 | "location":"CENDITEL", |
---|
35 | "contact":"582746574336", |
---|
36 | "signatureVisible":"true" |
---|
37 | //"page": VALOR_PAGE, |
---|
38 | //"coord_x": VALOR_X, |
---|
39 | //"coord_y": VALOR_Y |
---|
40 | }); |
---|
41 | |
---|
42 | // ahora llamar al ajax de obtener la resena del pdf |
---|
43 | $.ajax({ |
---|
44 | type: 'POST', |
---|
45 | contentType: 'application/json', |
---|
46 | //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs", |
---|
47 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs", |
---|
48 | dataType: "json", |
---|
49 | data: parameters, |
---|
50 | xhrFields: {withCredentials: true}, |
---|
51 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
52 | success: function(data, textStatus, jqXHR){ |
---|
53 | var json_x = data; |
---|
54 | var hash = json_x['hash']; |
---|
55 | //alert("hash recibido del servidor "+hash); |
---|
56 | |
---|
57 | var hashtype = "SHA-256"; |
---|
58 | var lang = "eng"; |
---|
59 | |
---|
60 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(function(signature) { |
---|
61 | |
---|
62 | $.ajax({ |
---|
63 | type: 'POST', |
---|
64 | contentType: 'application/json', |
---|
65 | //url:"https://192.168.12.125:8443/Murachi/0.1/archivos/pdfs/resenas", |
---|
66 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", |
---|
67 | dataType: 'json', |
---|
68 | data: JSON.stringify({"signature":signature.hex}), |
---|
69 | xhrFields: {withCredentials: true}, |
---|
70 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
71 | success: function(data, textStatus, jqXHR){ |
---|
72 | |
---|
73 | alert('Archivo firmado correctamente: ' + data['signedFileId']); |
---|
74 | |
---|
75 | var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\">descargar archivo firmado</a>"; |
---|
76 | //alert(linkToDownload); |
---|
77 | document.getElementById("respuesta").innerHTML = linkToDownload; |
---|
78 | |
---|
79 | }, |
---|
80 | error: function(jqXHR, textStatus, errorThrown){ |
---|
81 | alert('error en pdfs/resenas: ' + textStatus); |
---|
82 | $("#respuesta").html("error en pdfs/resenas: " + textStatus); |
---|
83 | } |
---|
84 | }); |
---|
85 | |
---|
86 | }, function(err) { |
---|
87 | log_text("sign() failed: " + err); |
---|
88 | |
---|
89 | var error; |
---|
90 | log_text("sign() failed: " + err); |
---|
91 | if(err == "Error: user_cancel") { |
---|
92 | alert("sign() failed: El usuario cancelo la operación"); |
---|
93 | error = "El usuario cancelo la operación"; |
---|
94 | } |
---|
95 | else if(err == "Error: no_certificates") { |
---|
96 | alert("sign() failed: No hay certificado disponible"); |
---|
97 | error = "No hay certificado disponible"; |
---|
98 | } |
---|
99 | else if(err == "Error: no_implementation") { |
---|
100 | alert("sign() failed: No hay soporte para el manejo del certificado"); |
---|
101 | error = "No hay soporte para el manejo del certificado"; |
---|
102 | } |
---|
103 | |
---|
104 | //alert("sign() failed: " + err); |
---|
105 | $("#respuesta").html("sign() failed: " + error); |
---|
106 | }); |
---|
107 | |
---|
108 | }, |
---|
109 | error: function(jqXHR, textStatus, errorThrown){ |
---|
110 | //alert('error: ' + textStatus); |
---|
111 | //var responseText = jQuery.parseJSON(jqXHR.responseText); |
---|
112 | alert('ajax error function: ' + jqXHR.responseText); |
---|
113 | $("#respuesta").html("error function: " + jqXHR.responseText); |
---|
114 | } |
---|
115 | |
---|
116 | }); |
---|
117 | |
---|
118 | }, function(err) { |
---|
119 | log_text("getCertificate() failed: " + err); |
---|
120 | var error; |
---|
121 | if(err == "Error: user_cancel") { |
---|
122 | alert("getCertificate() failed: El usuario cancelo la operación" ); |
---|
123 | error = "El usuario cancelo la operación"; |
---|
124 | } |
---|
125 | else if(err == "Error: no_certificates") { |
---|
126 | alert("getCertificate() failed: No hay certificado disponible") ; |
---|
127 | error = "No hay certificado disponible"; |
---|
128 | } |
---|
129 | else if(err == "Error: no_implementation") { |
---|
130 | alert("getCertificate() failed: No hay soporte para el manejo del certificado"); |
---|
131 | error = "No hay soporte para el manejo del certificado"; |
---|
132 | } |
---|
133 | //alert("getCertificate() failed: " + err); |
---|
134 | $("#respuesta").html("getCertificate() failed: " + error); |
---|
135 | }); |
---|
136 | |
---|
137 | }, |
---|
138 | error: function(response) { |
---|
139 | //Que se ejecuta cuando finalice la petición de con error |
---|
140 | $("#respuesta").html('Error...!!!'); |
---|
141 | alert("ocurrio un error") |
---|
142 | } |
---|
143 | }); |
---|
144 | |
---|
145 | }); |
---|