Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jfoclpf committed Jun 29, 2019
1 parent 6a9f680 commit 77ad9d1
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 200 deletions.
44 changes: 29 additions & 15 deletions www/js/authentication.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint camelcase: off */

/* global app, $, cordova, alert, pdf, Blob, atob, AUTHENTICATION */
/* global app, $, cordova, alert, pdf, Blob, atob, IN_APP_BROWSER_AUTH */

app.authentication = (function (thisModule) {
var inAppBrowserRef
var isAuthenticationWindowClosed = true
var pdfFileCreated = false

// function called by main.js
function startAuthentication () {
if (!AUTHENTICATION) {
if (!IN_APP_BROWSER_AUTH) {
return
}

Expand All @@ -25,13 +26,14 @@ app.authentication = (function (thisModule) {
}

function loadAuthentication () {
if (!AUTHENTICATION) {
if (!IN_APP_BROWSER_AUTH) {
return
}

console.log('loadAuthentication()')

var url = app.main.urls.Chave_Movel_Digital.assinar_pdf
/* var url = app.main.urls.Chave_Movel_Digital.assinar_pdf */
var url = 'https://www.thinkbroadband.com/download'

var target = '_blank'
var options = 'location=no,' +
Expand Down Expand Up @@ -72,17 +74,17 @@ app.authentication = (function (thisModule) {
dataType: 'text',
success: function (JScodeRes) {
// altera o texto quando refere o Documento para assinar
/* var JScode = JScodeRes +
var JScode = JScodeRes +
'(function(){' +
"var textEl = document.getElementById('MainContent_lblTitleChooseDoc');" +
'if(textEl){' +
"textEl.innerHTML = 'Escolha o documento <u>" +
getPdfFileName() + "</u> na pasta <i>Downloads</i> para assinar digitalmente';" +
'}' +
'})();' */
'})();'

inAppBrowserRef.executeScript(
{ code: JScodeRes },
{ code: JScode },
function () {
console.log('authBrowserJSCode.js Inserted Succesfully into inApp Browser Window')
})
Expand Down Expand Up @@ -205,8 +207,11 @@ app.authentication = (function (thisModule) {
file.createWriter(function (fileWriter) {
console.log('Writing content to file')
fileWriter.write(DataBlob)

pdfFileCreated = true
showPDFAuthInfo(folderpath, filename)
}, function () {
pdfFileCreated = false
alert('Não foi possível salvar o ficheiro em ' + folderpath)
})
})
Expand All @@ -217,15 +222,14 @@ app.authentication = (function (thisModule) {
console.log('folderpath : ' + folderpath)
console.log('fileName :' + filename)

if (AUTHENTICATION) {
if (IN_APP_BROWSER_AUTH) {
inAppBrowserRef.hide()
}

var msg = 'Foi criado o ficheiro PDF <span style="color:orange"><b>' + filename + '</b></span>' + ' ' +
'na pasta <i>Downloads</i> ou <i>Documentos/Downloads</i> com a sua denúncia.' + '<br><br>'
msg += ' 1) Salve o rascunho de email que vai ser gerado. Saia depois da APP de email.<br>'
msg += ' 2) Abrir-se-á depois uma janela para assinar o PDF fazendo uso da sua Chave Móvel Digital.<br>'
msg += ' 3) Volte à sua APP de email ao rascunho que guardou e anexe o PDF assinado. Garanta que o PDF anexo está digitalmente assinado.'
msg += ' Abrir-se-á de seguida uma janela para assinar o PDF fazendo uso da sua Chave Móvel Digital. Guarde o PDF gerado com a sua assinatura digital<br><br>'
msg += ' Abrir-se-á depois a sua APP de email onde poderá anexar o PDF assinado. Garanta que anexa apenas o PDF que está digitalmente assinado.'

$.jAlert({
'title': 'Criação de ficheiro PDF',
Expand All @@ -237,18 +241,28 @@ app.authentication = (function (thisModule) {
'theme': 'green',
'class': 'jButtonAlert',
'onClick': function () {
if (AUTHENTICATION) {
if (IN_APP_BROWSER_AUTH) {
// tries to use internal browser plugin to sign the pdf document
inAppBrowserRef.show()
} else {
sendMailMessage()
window.location.replace(app.main.urls.Chave_Movel_Digital.assinar_pdf)
}
}
}
]
})
}

function onAppResume () {
if (IN_APP_BROWSER_AUTH) {
return
}

if (pdfFileCreated) {
sendMailMessage()
}
}

function sendMailMessage () {
var mainMessage = 'Exmos. Srs.,<br><br>'
mainMessage += 'Envio em anexo ficheiro PDF com uma denúncia de estacionamento ao abrigo do n.º 5 do art. 170.º do Código da Estrada.<br><br>'
Expand All @@ -272,15 +286,15 @@ app.authentication = (function (thisModule) {
body: mainMessage, // email body (for HTML, set isHtml to true)
isHtml: true // indicats if the body is HTML or plain text
}, function () {
// callback: forward to oficial website for signing pdf
console.log('email view dismissed')
window.location.replace(app.main.urls.Chave_Movel_Digital.assinar_pdf)
pdfFileCreated = false
}, this)
}

/* === Public methods to be returned === */
thisModule.startAuthentication = startAuthentication
thisModule.savePDF = savePDF
thisModule.onAppResume = onAppResume

return thisModule
})(app.authentication || {})
16 changes: 10 additions & 6 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

var DEBUG = false

/* uses built-in browser plugin to authentication;
when false uses OS default brower with a simple url link */
var AUTHENTICATION = true
/* tries to use built-in browser plugin to authentication;
when false uses OS default browser with a simple url link;
option `true` is not working, check:
https://github.com/apache/cordova-plugin-inappbrowser/issues/498 */
var IN_APP_BROWSER_AUTH = false

/* for any type of authentication this must be true */
var SAVE_PDF = true

console.log('DEBUG: ', DEBUG)
console.log('AUTHENTICATION: ', AUTHENTICATION)
console.log('IN_APP_BROWSER_AUTH: ', IN_APP_BROWSER_AUTH)

var app = {}

Expand Down Expand Up @@ -93,6 +95,8 @@ app.main = (function (thisModule) {
}

function onResume () {
console.log('onResume')
app.authentication.onAppResume()
app.localization.loadMapsApi()
}

Expand Down Expand Up @@ -187,7 +191,7 @@ app.main = (function (thisModule) {
return
}

if (AUTHENTICATION || SAVE_PDF) {
if (IN_APP_BROWSER_AUTH || SAVE_PDF) {
var mensagem = 'A Autoridade Nacional de Segurança Rodoviária (ANSR), num parecer enviado às polícias a propósito desta APP, refere que as polícias devem de facto proceder à emissão efetiva da multa, perante as queixas dos cidadãos por esta via. Todavia, refere a ANSR, que os denunciantes deverão posteriormente dirigir-se às instalações da polícia respetiva, para se identificarem presencialmente.<br><br>Caso não se queira dirigir à polícia, terá de se autenticar fazendo uso da <b>Chave Móvel Digital</b> emitida pela Administração Pública. Caso não tenha uma, veja ' +
'<u><a href="' + app.main.urls.Chave_Movel_Digital.aderir + '">aqui</a></u> como pedi-la.'

Expand All @@ -201,7 +205,7 @@ app.main = (function (thisModule) {
'theme': 'green',
'class': 'jButtonAlert',
'onClick': function () {
if (AUTHENTICATION) {
if (IN_APP_BROWSER_AUTH) {
app.authentication.startAuthentication()
} else {
app.authentication.savePDF()
Expand Down
Loading

0 comments on commit 77ad9d1

Please sign in to comment.