mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-25 08:54:10 +00:00
feature(storage) change to async
This commit is contained in:
parent
059b2f054b
commit
961584ba65
4 changed files with 106 additions and 102 deletions
|
|
@ -51,40 +51,42 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb;
|
|||
}
|
||||
|
||||
|
||||
GitHub.autorize = function(pCallBack, pCode) {
|
||||
var lCode, lToken = Storage.get('token');
|
||||
|
||||
if (lToken) {
|
||||
GitHub.Login(lToken);
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
else {
|
||||
lCode = pCode || window.location.search;
|
||||
|
||||
if (lCode || Util.isContainStr(lCode, '?code=') )
|
||||
CloudCmd.getConfig(function(pConfig) {
|
||||
DOM.ajax({
|
||||
type : 'put',
|
||||
url : pConfig && pConfig.apiURL + '/auth',
|
||||
data : Util.removeStr(lCode, '?code='),
|
||||
success : function(pData) {
|
||||
if (pData && pData.token) {
|
||||
lToken = pData.token;
|
||||
|
||||
GitHub.Login(lToken);
|
||||
Storage.set('token', lToken);
|
||||
Util.exec(pCallBack);
|
||||
GitHub.autorize = function(callback, code) {
|
||||
Storage.get('token', function(token) {
|
||||
var code, isContain,
|
||||
URL = '//' + window.location.host + '/auth/github';
|
||||
|
||||
if (token) {
|
||||
GitHub.Login(token);
|
||||
Util.exec(callback);
|
||||
} else {
|
||||
if (!code)
|
||||
code = window.location.search;
|
||||
|
||||
isContain = Util.isContainStr(code, '?code=');
|
||||
|
||||
if (!isContain)
|
||||
DOM.openWindow(URL);
|
||||
else
|
||||
CloudCmd.getConfig(function(config) {
|
||||
DOM.ajax({
|
||||
type : 'put',
|
||||
url : config && config.apiURL + '/auth',
|
||||
data : Util.removeStr(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...');
|
||||
}
|
||||
else
|
||||
Util.log('Worning: token not getted...');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
else{
|
||||
var lUrl = '//' + window.location.host + '/auth/github';
|
||||
DOM.openWindow(lUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GitHub.getUserData = function(pCallBack) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue