Changeset bc1e568 in firmaeventos


Ignore:
Timestamp:
Nov 22, 2017, 10:50:29 AM (6 years ago)
Author:
lhernandez <lhernandez@…>
Branches:
master
Children:
9add819, 6312fce
Parents:
ad59aa1 (diff), 287657f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/cenditel-desarrollo/FirmaEventos

Files:
1 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • base/templates/base.template.html

    rb84cfca ra1de3f1  
    1414        <script src="{% static "plugins/material-dialog/material-dialog.min.js" %}"></script>
    1515        <script src="{% static "js/funciones.js" %}"></script>
    16         <script src="{% static "js/MultipleSign.js" %}"></script>
    1716        {% block headScript %}{%endblock%}
    1817    </head>
  • base/templates/base.vars.javascript.html

    rae65f8e ra1de3f1  
    22<script type="text/javascript">
    33    // URL para obtener data de usuario en evento
    4     var URL_USUARIO_EVENTO = "{% url 'participantes:search_participante_nid' %}" ;
     4    var URL_USUARIO_EVENTO = "{% url 'participantes:search_participante_nid' %}";
     5   
     6    // URUL para actualizar la firma de un participante
     7    var URL_ACTUALIZAR_PARTICIPACION = "{% url 'participantes:update_participante_evento' %}";
    58       
    69</script>
  • eventos/forms.py

    ra4764f9 rad59aa1  
    4444             'placeholder': 'Subir Archivo',
    4545             'accept': '.pdf'})
     46        self.fields['pos_x'].widget = forms.HiddenInput()
     47        self.fields['pos_y'].widget = forms.HiddenInput()
    4648
    4749class FirmaEventoForm(forms.Form):
  • eventos/models.py

    r61f3a75 rad59aa1  
    1414    fecha = models.DateField(null=False)
    1515    serial = models.CharField(max_length=128)
     16    pos_x = models.CharField(max_length=32)
     17    pos_y = models.CharField(max_length=32)
    1618    activo = models.BooleanField(default=True)
    1719
  • participantes/views.py

    r27c0bd4 rd17da63  
    22from django.http import JsonResponse
    33from django.views import View
     4from django.utils.decorators import method_decorator
     5from django.views.decorators.csrf import csrf_exempt
    46
    57from .models import (
     
    4143        return JsonResponse(data,safe=False)
    4244
    43 
     45@method_decorator(csrf_exempt, name='dispatch')
    4446class AjaxParticipanteFirmaEvento(View):
    4547    """!
     
    6971        serial = request.POST.get('serial', None)
    7072        pasaporte = request.POST.get('pasaporte', None)
     73        pasaporte = request.POST.get('pasaporte', None)
    7174        if evento_id is not None and pasaporte is not None:
    7275            if serial is not None:
    7376                try:
    74                     update_evento = self.model.object.get(pk=evento_id)
     77                    update_evento = self.model.objects.get(pk=evento_id)
    7578                    update_evento.serial = serial
    7679                    update_evento.save()
     
    8184                    mensaje += 'No existe el evento que desea actualizar \n'
    8285            try:
    83                 participante = Participante.object.get(pasaporte=pasaporte)
     86                participante = Participante.objects.get(pasaporte=pasaporte)
    8487            except Exception as e:
    8588                print (e)
     
    8891                            participantes que se ecuentran registrados \n'
    8992            try:
    90                 update_parti_event = self.model_participante.object.get(
     93                update_parti_event = self.model_participante.objects.get(
    9194                                    fk_participante=participante.pk,
    9295                                    fk_evento=evento_id)
  • static/js/funciones.js

    rb84cfca ra1de3f1  
    2828        $.getJSON(url, function(data){
    2929            if (Object.keys(data).length > 0) {
    30                 construir_datos(data.datos);
     30                construir_datos(data);   
    3131            }
    3232            else{
     
    6565*/
    6666function construir_datos(data) {
     67    firma = data.firmo;
     68    data = data.datos;
    6769    $('#datos_paricipante').html('');
    6870    html = '<ul class="collection">'
     
    7274    html += '<li class="collection-item"><b>Correo: </b>'+data.correo+'</li>';
    7375    html += '</ul>';
    74     html += '<iframe width="700px" height="600px" src="https://192.168.12.154:8443/Murachi/0.1/archivos/listadopdf/cbcd0924-bbfe-49dc-afc8-f32348f20350.pdf">';
     76    html += '<iframe width="700px" height="600px" src="https://192.168.12.154:8443/Murachi/0.1/archivos/listadopdf/'+data.documento+'">';
    7577    html += '</iframe><br/>';
    76     html += '<a type="button" class="btn waves-effect blue darken-1" onclick="ObtenerCertificadoFirmanteMultiples(\''+data.documento+'\')">';
    77     html += '<i class="material-icons left">mode_edit</i> Firmar</a>';
     78    if (firma==true) {
     79        html += '<h4 class="red-text center">Ya firmó este documento</h4>'
     80    }
     81    else{
     82        html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick="ObtenerCertificadoFirmanteMultiples(\''+data.documento+'\')">';
     83        html += '<i class="material-icons left">mode_edit</i> Firmar</a>';   
     84    }
    7885    $('#datos_paricipante').html(html);
    7986}
     87
     88/**
     89 * Función para obtener el certificado del participante
     90 * @param fileId Recibe el id del documento
     91*/
     92function ObtenerCertificadoFirmanteMultiples(fileId){
     93
     94        // identificador del archivo en el servidor
     95        window.hwcrypto.getCertificate({lang: "en"}).then(
     96                function(response) {
     97                        var cert = response;
     98                        var parameters = "";
     99                        parameters = JSON.stringify({
     100                                "fileId":fileId,
     101                                "certificate":cert.hex,
     102                                "reason":"Certificado",
     103                                "location":"RedGealc",
     104                                "contact":"RedGealc",
     105                                "signatureVisible":"false",
     106                                "signaturePage": "",
     107                                "xPos": "",
     108                                "yPos": ""
     109                                });                             
     110
     111                        // ahora llamar al ajax de obtener la resena del pdf
     112                        ObtenerHashPDFServerMultiples(parameters, cert);       
     113
     114                },
     115                function(err) {
     116            var error;
     117            if(err == "Error: user_cancel") {
     118                error = "El usuario cancelo la operación";
     119             }     
     120             else if(err == "Error: no_certificates") {
     121                 error = "No hay certificado disponible";
     122             }
     123             else if(err == "Error: no_implementation") {
     124                 error = "No hay soporte para el manejo del certificado";
     125                        }
     126            simple_modal(error);
     127                }
     128
     129        );
     130}
     131
     132
     133/**
     134 * Función para obtener el hash y procesar la informacion
     135 * @param parameters Recibe los parametros
     136 * @param cert Recibe los certificados
     137*/
     138function ObtenerHashPDFServerMultiples(parameters,cert){
     139
     140        $.ajax({
     141                type: 'POST',
     142                contentType: 'application/json',                               
     143                url:"https://192.168.12.154:8443/Murachi/0.1/archivos/pdfs2",
     144                //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
     145        //url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados/pdfs",
     146                dataType: "json",
     147                data: parameters,               
     148                xhrFields: {withCredentials: true},
     149                headers: {"Authorization":"Basic YWRtaW46YWRtaW4="},
     150                success: function(data, textStatus, jqXHR){
     151                        var json_x = data;
     152                        var hash = json_x['hash'];             
     153                        var hashtype = "SHA-256";
     154                        var lang = "eng";
     155                       
     156                        //Procesa la información
     157                        window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(
     158                                function(signature) {
     159                                        FinalizarFirmaMultiples(signature.hex);
     160                        },
     161                        function(err) {
     162                                        var error;
     163                    if(err == "Error: user_cancel") {
     164                        error = "El usuario cancelo la operación";
     165                     }     
     166                     else if(err == "Error: no_certificates") {
     167                         error = "No hay certificado disponible";
     168                     }
     169                     else if(err == "Error: no_implementation") {
     170                         error = "No hay soporte para el manejo del certificado";
     171                     }
     172                    simple_modal(error);
     173                });
     174                       
     175                },                                                             
     176                error: function(jqXHR, textStatus, errorThrown){
     177                        console.log('ajax error function: ' + jqXHR.responseText);
     178                }
     179               
     180        });     
     181}
     182
     183/**
     184 * Función para enviar la firma al servidor
     185 * @param signature Recibe la firma
     186*/
     187function FinalizarFirmaMultiples(signature){
     188
     189        $.ajax({
     190                type: 'POST',
     191                contentType: 'application/json',
     192                url:"https://192.168.12.154:8443/Murachi/0.1/archivos/pdfs/resenas",
     193                //url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas",
     194                dataType: 'json',
     195                data: JSON.stringify({"signature":signature}),
     196                xhrFields: {withCredentials: true},
     197                headers: {"Authorization":"Basic YWRtaW46YWRtaW4="},
     198                success: function(data, textStatus, jqXHR){
     199            actualizar_participante(data['signedFileId']);
     200                },
     201                error: function(jqXHR, textStatus, errorThrown){
     202                        console.log('error en pdfs/resenas: ' + textStatus);
     203                }
     204        });
     205
     206}
     207
     208/**
     209 * Función para actualizar los datos del participante
     210 * @param id_documento Recibe el id del documento
     211*/
     212function actualizar_participante(id_documento) {
     213    var pasaporte = $('#id_pasaporte').val();
     214    var routes = $(location).attr('pathname').split('/');
     215    var pk = routes[routes.length-1];
     216   
     217    $.post(URL_ACTUALIZAR_PARTICIPACION,{'event_id':pk,'pasaporte':pasaporte,'serial':id_documento})
     218    .done(function(data){
     219        if (data.validate==true) {
     220            simple_modal(data.mensaje);
     221            $('#firmar').remove();
     222        }
     223        else{
     224            simple_modal(data.mensaje);
     225        }
     226    })
     227    .fail(function(err){
     228        console.log(err);
     229    });
     230}
Note: See TracChangeset for help on using the changeset viewer.