Changeset 452668a in firmaeventos


Ignore:
Timestamp:
Nov 27, 2017, 10:46:54 AM (6 years ago)
Author:
rudmanmrrod <rudman22@…>
Branches:
master
Children:
163d273
Parents:
2b66ea3
Message:

Ajustada validación para un firmante a la vez por documento

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • base/templates/base.vars.javascript.html

    r5d88f36 r452668a  
    99    // URL para comprobar si el firmante es el último
    1010    var URL_ULTIMO_FIRMANTE = "{% url 'participantes:participante_restante_evento_nid' %}";
     11   
     12    // URL para comprobar si el documento esta siendo firmado
     13    var URL_COMPROBAR_FIRMA = "{% url 'events:comprobar_evento_nid' %}";
     14
    1115           
    1216</script>
  • eventos/urls.py

    r2b66ea3 r452668a  
    1313    url(r'^detail-evento/(?P<pk>\d+)$', DetailEvent.as_view(),
    1414        name='detail_event'),
     15    url(r'^comprobar-evento/(?P<event_id>\d+)$', EventoProcesado.as_view(),
     16        name='comprobar_evento'),
    1517    url(r'^comprobar-evento/$', EventoProcesado.as_view(),
    16         name='comprobar_evento'),
     18        name='comprobar_evento_nid'),
    1719]
  • eventos/views.py

    r3ae7c21 r452668a  
    1010from django.core.urlresolvers import reverse_lazy
    1111from django.http import JsonResponse
     12from django.utils.decorators import method_decorator
     13from django.views.decorators.csrf import csrf_exempt
    1214from django.shortcuts import (
    1315    redirect
     
    184186        return context
    185187
    186 
     188@method_decorator(csrf_exempt, name='dispatch')
    187189class EventoProcesado(View):
    188190    """!
     
    196198    model = Evento
    197199
    198     def get(self, request):
     200    def get(self, request, event_id):
    199201        """!
    200202        Metodo que permite verificar si el documento esta procesado
     
    206208        @return Retorna un Json con la respuesta
    207209        """
    208         evento_id = request.GET.get('event_id', None)
    209210        mensaje = ''
    210211        procesando = False
    211         if evento_id is not None:
     212        if event_id is not None:
    212213            try:
    213                 evento_pro = self.model.objects.get(pk=evento_id)
     214                evento_pro = self.model.objects.get(pk=event_id)
    214215            except:
    215216                print(e)
     
    231232        return JsonResponse(data, safe=False)
    232233
    233     def post(self, request):
     234    def post(self, request, event_id):
    234235        """!
    235236        Metodo que permite cambiar el valor procesado al  evento
     
    241242        @return Retorna un Json con la respuesta
    242243        """
    243         evento_id = request.POST.get('event_id', None)
    244         if evento_id is not None:
     244        if event_id is not None:
    245245            try:
    246                 evento = self.model.objects.get(pk=evento_id)
     246                evento = self.model.objects.get(pk=event_id)
    247247                evento.procesando = not evento.procesando
    248248                evento.save()
     
    251251                print(e)
    252252                validado = False
    253         return JsonResponse(validado, safe=False)
     253        return JsonResponse({'validate': validado}, safe=False)
  • static/js/funciones.js

    r3ae7c21 r452668a  
    8080    }
    8181    else{
    82         html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick="ObtenerCertificadoFirmanteMultiples(\''+data.documento+'\')">';
     82        html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick="comprobarFirma(\''+data.documento+'\')">';
    8383        html += '<i class="material-icons left">mode_edit</i> Firmar</a>';   
    8484    }
     
    8787
    8888/**
     89 * Función para comprobar firma
     90 * @param fileId Recibe el id del documento
     91*/
     92function comprobarFirma(fileId){
     93    var routes = $(location).attr('pathname').split('/');
     94    var pk = routes[routes.length-1];
     95    $.ajax({
     96                type: 'GET',
     97        async: false,
     98                url:URL_COMPROBAR_FIRMA+pk,
     99                success: function(datos){
     100            if (datos.validate==true) {
     101                simple_modal(datos.mensaje);
     102            }
     103            else{
     104                $.ajax({
     105                    type: 'POST',
     106                    async: false,
     107                    url:URL_COMPROBAR_FIRMA+pk,
     108                    success: function(datos){
     109                        if (datos.validate==true) {
     110                            ObtenerCertificadoFirmanteMultiples(fileId,pk);
     111                        }
     112                        else{
     113                            simple_modal("Ocurrió un error al actualizar los datos");
     114                        }
     115                    },
     116                    error: function(jqXHR, textStatus, errorThrown){
     117                        console.log('error: ' + textStatus);
     118                    }
     119                });
     120            }
     121        },
     122                error: function(jqXHR, textStatus, errorThrown){
     123                        console.log('error: ' + textStatus);
     124                }
     125        });
     126}
     127
     128/**
    89129 * Función para obtener el certificado del participante
    90130 * @param fileId Recibe el id del documento
    91 */
    92 function ObtenerCertificadoFirmanteMultiples(fileId){
     131 * @param pk Recibe el id del evento
     132*/
     133function ObtenerCertificadoFirmanteMultiples(fileId,pk){
    93134    var xPos = yPos= signaturePage = "";
    94135    var lastSignature = false;
    95     var routes = $(location).attr('pathname').split('/');
    96     var pk = routes[routes.length-1];
    97136   
    98137    $.ajax({
     
    125164       
    126165                    // ahora llamar al ajax de obtener la resena del pdf
    127                     ObtenerHashPDFServerMultiples(parameters, cert);   
     166                    ObtenerHashPDFServerMultiples(parameters, cert, pk);       
    128167       
    129168                },
     
    139178                         error = "No hay soporte para el manejo del certificado";
    140179                    }
     180                    $.ajax({
     181                        type: 'POST',
     182                        async: false,
     183                        url:URL_COMPROBAR_FIRMA+pk,
     184                        success: function(datos){
     185                            console.log(datos);
     186                        },
     187                        error: function(jqXHR, textStatus, errorThrown){
     188                            console.log('error: ' + textStatus);
     189                        }
     190                    });
    141191                    simple_modal(error);
    142192                }
     
    155205 * @param parameters Recibe los parametros
    156206 * @param cert Recibe los certificados
    157 */
    158 function ObtenerHashPDFServerMultiples(parameters,cert){
     207 * @param pk Recibe el id del evento
     208*/
     209function ObtenerHashPDFServerMultiples(parameters,cert,pk){
    159210
    160211        $.ajax({
     
    175226                        window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(
    176227                                function(signature) {
    177                                         FinalizarFirmaMultiples(signature.hex);
     228                                        FinalizarFirmaMultiples(signature.hex, pk);
    178229                        },
    179230                        function(err) {
     
    188239                         error = "No hay soporte para el manejo del certificado";
    189240                     }
     241                    $.ajax({
     242                        type: 'POST',
     243                        async: false,
     244                        url:URL_COMPROBAR_FIRMA+pk,
     245                        success: function(datos){
     246                            console.log(datos);
     247                        },
     248                        error: function(jqXHR, textStatus, errorThrown){
     249                            console.log('error: ' + textStatus);
     250                        }
     251                    });
    190252                    simple_modal(error);
    191253                });
     
    202264 * Función para enviar la firma al servidor
    203265 * @param signature Recibe la firma
    204 */
    205 function FinalizarFirmaMultiples(signature){
     266 * @param pk Recibe el id del evento
     267*/
     268function FinalizarFirmaMultiples(signature, pk){
    206269
    207270        $.ajax({
     
    215278                success: function(data, textStatus, jqXHR){
    216279            actualizar_participante(data['signedFileId']);
     280            $.ajax({
     281                type: 'POST',
     282                async: false,
     283                url:URL_COMPROBAR_FIRMA+pk,
     284                success: function(datos){
     285                    console.log(datos);
     286                },
     287                error: function(jqXHR, textStatus, errorThrown){
     288                    console.log('error: ' + textStatus);
     289                }
     290            });
    217291                },
    218292                error: function(jqXHR, textStatus, errorThrown){
    219293                        console.log('error en pdfs/resenas: ' + textStatus);
     294            $.ajax({
     295                type: 'POST',
     296                async: false,
     297                url:URL_COMPROBAR_FIRMA+pk,
     298                success: function(datos){
     299                    console.log(datos);
     300                },
     301                error: function(jqXHR, textStatus, errorThrown){
     302                    console.log('error: ' + textStatus);
     303                }
     304            });
    220305                }
    221306        });
Note: See TracChangeset for help on using the changeset viewer.