Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified images/press.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
},
"devDependencies": {
"babel-eslint": "=4.0.10",
"electron-packager": "=5.0.2",
"electron-prebuilt": "=0.31.0",
"electron-packager": "=5.1.0",
"electron-prebuilt": "=0.32.3",
"eslint": "=1.2.1",
"grunt": "=0.4.5",
"grunt-contrib-clean": "=0.6.0",
Expand Down
22 changes: 22 additions & 0 deletions src/js/__tests__/components/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ describe('Test for Login Component', function () {
);
}

if (event == 'did-get-redirect-request') {
callback(
'did-get-redirect-request',
'http://www.github.com/?code=123123123',
'http://www.github.com/?code=123123123'
);
}

}
},
on: function () {
return;
},
close: function () {
return;
},
destroy: function () {
return;
}
};
};
Expand Down Expand Up @@ -141,13 +152,24 @@ describe('Test for Login Component - Callback with Error', function () {
);
}

if (event == 'did-get-redirect-request') {
callback(
'did-get-redirect-request',
'http://www.github.com/?error=FAILURE',
'http://www.github.com/?error=FAILURE'
);
}

}
},
on: function (event, callback) {
callback();
},
close: function () {
return;
},
destroy: function (argument) {
return;
}
};
};
Expand Down
21 changes: 15 additions & 6 deletions src/js/components/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@ var Login = React.createClass({
width: 800,
height: 600,
show: true,
'node-integration': false
'web-preferences': {
'node-integration': false
}
});
var githubUrl = 'https://github.com/login/oauth/authorize?';
var authUrl = githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scope;
authWindow.loadUrl(authUrl);

authWindow.webContents.on('will-navigate', function (event, url) {
handleCallback(url);
});

authWindow.webContents.on('did-get-redirect-request', function (event, oldUrl, newUrl) {
handleCallback(newUrl);
});

function handleCallback (url) {
var raw_code = /code=([^&]*)/.exec(url) || null;
var code = (raw_code && raw_code.length > 1) ? raw_code[1] : null;
var error = /\?error=(.+)$/.exec(url);

if (code || error) {
// Close the browser if code found or error
authWindow.close();
authWindow.destroy();
}

// If there is a code, proceed to get token from github
Expand All @@ -50,13 +60,12 @@ var Login = React.createClass({
alert('Oops! Something went wrong and we couldn\'t' +
'log you in using Github. Please try again.');
}

});
}

// If "Done" button is pressed, hide "Loading"
authWindow.on('close', function () {
authWindow = null;
}, false);
authWindow.destroy();
});

},

Expand Down