mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
setted up auth on GitHub
This commit is contained in:
parent
70f648ef16
commit
21e5dae514
5 changed files with 76 additions and 34 deletions
|
|
@ -94,6 +94,8 @@ when CodeMirror is open on the right panel.
|
|||
|
||||
* Function generateHeaders moved to main module.
|
||||
|
||||
* Setted up auth on GitHub thru rest.
|
||||
|
||||
|
||||
2012.10.01, Version 0.1.7
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ var CloudCommander, Util, DOM, $, Github;
|
|||
if ( Util.isContainStr(lCode, '?code=') ){
|
||||
lCode = lCode.replace('?code=','');
|
||||
|
||||
|
||||
$.ajax(
|
||||
{type:'put',
|
||||
url:'/api/v1/auth',
|
||||
data: lCode,
|
||||
success: function(pDate){
|
||||
console.log(pDate);}
|
||||
});
|
||||
|
||||
/*
|
||||
$.post("https://github.com/login/oauth/access_token",{
|
||||
client_id : CLIENT_ID,
|
||||
client_secret : CLIENT_SECRET,
|
||||
|
|
@ -80,6 +90,7 @@ var CloudCommander, Util, DOM, $, Github;
|
|||
//GithubStore.Login(lToken);
|
||||
console.log(pDate);
|
||||
}, "json");
|
||||
*/
|
||||
}
|
||||
else
|
||||
cloudcmd.Auth();
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@
|
|||
* @param pCallBack
|
||||
*/
|
||||
|
||||
exports.auth = function(pCode, pCallBack){
|
||||
pCode = pCode.replace('code=','');
|
||||
exports.auth = function(pCode, pCallBack){
|
||||
pCode = pCode.replace('code=','');
|
||||
|
||||
console.log(pCode);
|
||||
authenticate(pCode, function(token) {
|
||||
var result = { "token": token };
|
||||
console.log(result);
|
||||
|
||||
Util.exec(pCallBack);
|
||||
Util.exec(pCallBack, result);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,20 @@
|
|||
lMethod = lReq.method;
|
||||
|
||||
if( Util.isContainStr(lUrl, APIURL) ){
|
||||
var lCommand = Util.removeStr(lUrl, APIURL),
|
||||
lData = getData(lMethod, lCommand);
|
||||
|
||||
send(lRes, lData);
|
||||
|
||||
lRet = true;
|
||||
|
||||
getBody(lReq, function(pBody){
|
||||
var lCommand = Util.removeStr(lUrl, APIURL),
|
||||
lData = getData({
|
||||
command : lCommand,
|
||||
method : lMethod,
|
||||
body : pBody,
|
||||
response : lRes
|
||||
});
|
||||
|
||||
if(lData)
|
||||
send(lRes, lData);
|
||||
});
|
||||
}
|
||||
|
||||
return lRet;
|
||||
|
|
@ -42,25 +50,31 @@
|
|||
*/
|
||||
function send(pRes, pData){
|
||||
pRes.writeHead(OK, Header);
|
||||
pRes.end( pData.toString() );
|
||||
pRes.end( JSON.stringify(pData) );
|
||||
}
|
||||
|
||||
/**
|
||||
* getting data on method and command
|
||||
*
|
||||
* @param pMethod
|
||||
* @param pCommand
|
||||
* @param pParams {command, method, body, response}
|
||||
*/
|
||||
function getData(pMethod, pCommand){
|
||||
var lResult;
|
||||
function getData(pParams){
|
||||
var lResult,
|
||||
lCmd = pParams.command,
|
||||
lMethod = pParams.method;
|
||||
|
||||
switch(pMethod){
|
||||
if(lCmd[0] === '/'){
|
||||
lCmd = Util.removeStr(lCmd, '/');
|
||||
pParams.command = lCmd;
|
||||
}
|
||||
|
||||
switch(lMethod){
|
||||
case 'GET':
|
||||
lResult = onGET(pCommand);
|
||||
lResult = onGET(pParams);
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
lResult = onPUT(pCommand);
|
||||
lResult = onPUT(pParams);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -70,15 +84,18 @@
|
|||
/**
|
||||
* process data on GET request
|
||||
*
|
||||
* @param pCommand
|
||||
* @param pParams {command, method, body, response}
|
||||
*/
|
||||
function onGET(pCommand){
|
||||
var lResult;
|
||||
function onGET(pParams){
|
||||
var lResult,
|
||||
lCmd = pParams.command;
|
||||
|
||||
switch(pCommand){
|
||||
switch(lCmd){
|
||||
case '':
|
||||
lResult = {info: 'Cloud Commander API v1'};
|
||||
break;
|
||||
case 'kill':
|
||||
process.exit();
|
||||
}
|
||||
|
||||
return lResult;
|
||||
|
|
@ -87,15 +104,35 @@
|
|||
/**
|
||||
* process data on PUT request
|
||||
*
|
||||
* @param pCommand
|
||||
* @param pParams {command, method, body, response}
|
||||
*/
|
||||
function onPUT(pCommand){
|
||||
var lResult;
|
||||
function onPUT(pParams){
|
||||
var lResult,
|
||||
lCmd = pParams.command,
|
||||
lBody = pParams.body,
|
||||
lRes = pParams.response;
|
||||
|
||||
switch(pCommand){
|
||||
switch(lCmd){
|
||||
case 'auth':
|
||||
main.auth(lBody, function(pTocken){
|
||||
send(lRes, pTocken);
|
||||
});
|
||||
lResult = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return lResult;
|
||||
}
|
||||
|
||||
function getBody(pReq, pCallBack){
|
||||
var lBody = '';
|
||||
pReq.on('data', function(chunk) {
|
||||
lBody += chunk.toString();
|
||||
});
|
||||
|
||||
pReq.on('end', function() {
|
||||
Util.exec(pCallBack, lBody);
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
12
server.js
12
server.js
|
|
@ -401,17 +401,9 @@ CloudServer._controller = function(pReq, pRes)
|
|||
|
||||
console.log(DirPath);
|
||||
|
||||
|
||||
/* читаем основные данные о файле */
|
||||
if( lQuery && lQuery.indexOf('code=') === 0){
|
||||
var lAuth = main.auth;
|
||||
|
||||
if( Util.isFunction(lAuth) )
|
||||
lAuth(lQuery, function(){
|
||||
Fs.stat(DirPath, CloudServer._stated);
|
||||
});
|
||||
console.log('***********');
|
||||
}else
|
||||
Fs.stat(DirPath, CloudServer._stated);
|
||||
Fs.stat(DirPath, CloudServer._stated);
|
||||
|
||||
/* если установлено сжатие
|
||||
* меняем название html-файла и
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue