mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(github) athorize
This commit is contained in:
parent
9ee13cfbbf
commit
7feadb6207
2 changed files with 20 additions and 44 deletions
|
|
@ -3,12 +3,13 @@
|
|||
<head></head>
|
||||
<body>
|
||||
<script>
|
||||
(function(){
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.addEventListener('message', function(event) {
|
||||
event.source.postMessage(window.location.search, event.origin);
|
||||
});
|
||||
window.opener
|
||||
.CloudCmd
|
||||
.GitHub
|
||||
.authorize(window.location.search);
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
function GitHubProto(callback) {
|
||||
var GitHub = this,
|
||||
|
||||
Popup,
|
||||
|
||||
Storage = DOM.Storage,
|
||||
Events = DOM.Events,
|
||||
GH,
|
||||
User;
|
||||
|
||||
|
|
@ -20,22 +17,9 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
function init(callback) {
|
||||
Util.exec.series([
|
||||
load,
|
||||
GitHub.autorize,
|
||||
GitHub.getUserData,
|
||||
GitHub.authorize,
|
||||
Util.exec.ret(callback)
|
||||
]);
|
||||
|
||||
Events.add('message', function(event) {
|
||||
if (event.origin === document.location.origin) {
|
||||
Popup.close();
|
||||
GitHub.autorize(function() {
|
||||
Util.exec.series([
|
||||
GitHub.getUserData,
|
||||
Util.exec.ret(callback)
|
||||
]);
|
||||
}, event.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function load(callback) {
|
||||
|
|
@ -56,48 +40,39 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
GitHub.autorize = function(callback, code) {
|
||||
GitHub.authorize = function(code) {
|
||||
Storage.get('token', function(error, token) {
|
||||
var isContain,
|
||||
var is = Util.type.string(code),
|
||||
apiURL = CloudFunc.apiURL,
|
||||
URL = '//' + window.location.host + '/auth/github';
|
||||
|
||||
|
||||
if (token) {
|
||||
GitHub.Login(token);
|
||||
Util.exec(callback);
|
||||
} else {
|
||||
if (!code)
|
||||
code = window.location.search;
|
||||
is = is && ~code.indexOf('?code=');
|
||||
|
||||
isContain = ~code.indexOf('?code=');
|
||||
|
||||
if (!isContain) {
|
||||
Popup = DOM.openWindow(URL);
|
||||
if (Popup)
|
||||
Popup.postMessage('', window.location.origin);
|
||||
} else {
|
||||
if (!is)
|
||||
DOM.openWindow(URL);
|
||||
else
|
||||
DOM.load.ajax({
|
||||
type : 'put',
|
||||
url : apiURL + '/auth',
|
||||
data : Util.rmStr(code, '?code='),
|
||||
success : function(data) {
|
||||
if (data && data.token) {
|
||||
token = data.token;
|
||||
|
||||
GitHub.Login(token);
|
||||
Storage.set('token', token);
|
||||
Util.exec(callback);
|
||||
} else
|
||||
Util.log('Worning: token not getted...');
|
||||
var token = Util.json.parse(data).data.token;
|
||||
|
||||
GitHub.Login(token);
|
||||
Storage.set('token', token);
|
||||
|
||||
GitHub.getUserData(callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GitHub.getUserData = function(callback) {
|
||||
GitHub.getUserData = function(callback) {
|
||||
User.show(null, function(error, data) {
|
||||
var name;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue