mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 18:23:35 +00:00
refactor(github) auth
This commit is contained in:
parent
6d84f734d2
commit
8ac1cc5837
4 changed files with 36 additions and 29 deletions
|
|
@ -7,8 +7,11 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
|
||||
function GitHubProto(callback) {
|
||||
var GitHub = this,
|
||||
Storage = DOM.Storage,
|
||||
|
||||
Popup,
|
||||
|
||||
Storage = DOM.Storage,
|
||||
Events = DOM.Events,
|
||||
GH,
|
||||
User;
|
||||
|
||||
|
|
@ -22,6 +25,13 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
Util.exec.ret(callback)
|
||||
]);
|
||||
|
||||
Events.add('message', function(event) {
|
||||
if (event.origin === document.location.origin) {
|
||||
Popup.close();
|
||||
GitHub.autorize(event.data);
|
||||
}
|
||||
});
|
||||
|
||||
GitHub.callback = function() {
|
||||
Util.exec.series([
|
||||
GitHub.getUserData,
|
||||
|
|
@ -31,8 +41,8 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
}
|
||||
|
||||
function load(callback) {
|
||||
var dir = CloudCmd.LIBDIRCLIENT + 'storage/github/',
|
||||
url = join([
|
||||
var dir = CloudCmd.LIBDIRCLIENT + 'storage/github/',
|
||||
url = CloudCmd.join([
|
||||
dir + 'lib/underscore.js',
|
||||
dir + 'lib/base64.js',
|
||||
dir + 'github.js'
|
||||
|
|
@ -51,7 +61,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
|
||||
GitHub.autorize = function(callback, code) {
|
||||
Storage.get('token', function(error, token) {
|
||||
var isContain,
|
||||
var isContain, popup,
|
||||
apiURL = CloudFunc.apiURL,
|
||||
URL = '//' + window.location.host + '/auth/github';
|
||||
|
||||
|
|
@ -64,9 +74,11 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
|
||||
isContain = ~code.indexOf('?code=');
|
||||
|
||||
if (!isContain)
|
||||
DOM.openWindow(URL);
|
||||
else
|
||||
if (!isContain) {
|
||||
Popup = DOM.openWindow(URL);
|
||||
if (Popup)
|
||||
Popup.postMessage('', window.location.origin);
|
||||
} else {
|
||||
DOM.load.ajax({
|
||||
type : 'put',
|
||||
url : apiURL + '/auth',
|
||||
|
|
@ -82,6 +94,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
Util.log('Worning: token not getted...');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue