feature(storage) change to async

This commit is contained in:
coderaiser 2014-02-18 04:51:57 -05:00
parent 059b2f054b
commit 961584ba65
4 changed files with 106 additions and 102 deletions

View file

@ -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) {