issue #126 [WIP]

This commit is contained in:
Lplenka
2017-04-17 12:15:07 +05:30
parent 61a429365b
commit 468e9d539b
3 changed files with 55 additions and 5 deletions

View File

@@ -248,10 +248,31 @@ function createMainWindow() {
// app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
// For self-signed certificate
ipc.on('certificate-err', (e, domain) => {
var detail = `URL: ${domain} \n Error: Self-Signed Certificate`;
dialog.showMessageBox( mainWindow, {
title: 'Certificate error',
message: `Do you trust certificate from ${domain}?`,
detail: detail,
type: 'warning',
buttons: [
'Yes',
'No'
],
cancelId: 1
}, (response) => {
if (response === 0) {
db.push("/certifiedURL", [{domain:domain}], false);
db.push('/domain', domain);
mainWindow.loadURL(domain);
}
});
});
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
console.log("warning: ", url, " certificate-error");
event.preventDefault()
callback(true)
event.preventDefault();
callback(true);
});
app.on('window-all-closed', () => {

View File

@@ -20,8 +20,7 @@
Zulip Server URL
</label>
<input type="text" id="url" autofocus="autofocus" spellcheck="false" placeholder="Server URL">
<button type="submit" id="main" class="btn-primary btn-large" value="Submit"
onclick="addDomain();">Connect</button>
<button type="submit" id="main" class="btn-primary btn-large" value="Submit">Connect</button>
<p id="error"></p>
</form>
</div>

View File

@@ -4,6 +4,27 @@ const JsonDB = require('node-json-db');
const request = require('request');
const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
const data = db.getData('/');
if(!data.certifiedURL) {
db.push("/certifiedURL",[]);
}
let URL_List = db.getData('/certifiedURL');
let URL_Length = URL_List.length;
const checkURL = domain => {
for ( var i = 0; i < URL_Length; i++) {
if (URL_List[i].domain === domain);
return true;
break;
}
return false;
};
window.addDomain = function () {
const el = sel => {
@@ -59,6 +80,15 @@ window.addDomain = function () {
$el.main.innerHTML = 'Connect';
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
if(checkURL(domain)) {
$el.main.innerHTML = 'Connect';
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else {
$el.main.innerHTML = 'Connect';
ipcRenderer.send('certificate-err', domain);
}
} else {
$el.main.innerHTML = 'Connect';
displayError('Not a valid Zulip server');