Skip to content

Commit

Permalink
add appkey
Browse files Browse the repository at this point in the history
  • Loading branch information
caihuiji committed Sep 25, 2015
1 parent 551be9c commit f38e06b
Showing 22 changed files with 1,188 additions and 1,128 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015
Copyright (c) 2015 , imweb(http://imweb.io/)
Copyright (c) 2015 , chriscai([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
2 changes: 2 additions & 0 deletions controller/action/ApplyAction.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
var log4js = require('log4js'),
logger = log4js.getLogger(),
_ = require('underscore'),
crypto = require('crypto'),
ApplyService = require('../../service/ApplyService'),
isError = function (res , error){
if(error){
@@ -56,6 +57,7 @@ var applyAction = {
});
}else {
apply.createTime = new Date();
apply.appkey = crypto.createHash("md5").update(new Date-0 + "badjsappkey" +params.user.loginName).digest('hex');
applyService.add(apply,function(err, items){
if(isError(res, err)){
return;
1 change: 1 addition & 0 deletions dao/ApplyDao.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ module.exports = function (db){
userName : String,
status : Number,
name : String,
appkey : String,
url : String,
description : String,
mail : String,
1 change: 1 addition & 0 deletions db/create.sql
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ CREATE TABLE `b_apply` (
`userName` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`status` int(11) NOT NULL,
`name` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`appkey` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci,
`mail` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
"orm-transaction": "0.0.2",
"passport": "^0.2.1",
"passport-local": "^1.0.0",
"request": "^2.63.0",
"serve-static": "^1.7.1",
"socket.io": "^1.2.0",
"underscore": "1.5.2",
3 changes: 3 additions & 0 deletions project.debug.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@
"acceptor": {
"pushProjectUrl" : "http://127.0.0.1:9001/getProjects"
},
"open": {
"pushProjectUrl" : "http://127.0.0.1:9002/getProjects"
},
"zmq" : {
"url" : "tcp://127.0.0.1:10000",
"subscribe" : "badjs"
2 changes: 1 addition & 1 deletion service/ApplyService.js
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ ApplyService.prototype = {
update : function(target, callback){
this.applyDao.one({id: target.id }, function (err, apply) {
// SQL: "SELECT * FROM b_apply WHERE name = 'xxxx'"
for(key in target){
for(var key in target){
apply[key] = target[key];
};
apply.save(function (err) {
2 changes: 1 addition & 1 deletion service/BusinessService.js
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ BusinessService.prototype = {

findBusiness : function ( callback){

var string = "select a.id, u.loginName, u.chineseName , a.name "+
var string = "select a.id , a.appkey, u.loginName, u.chineseName , a.name "+
"from b_apply a join b_user u on (a.userName=u.loginName) "+
"where a.status=? ";
var condition = [Apply.STATUS_PASS ];
49 changes: 31 additions & 18 deletions service/LogService.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ var log4js = require('log4js'),
_ = require('underscore'),
logger = log4js.getLogger();

var request = require("request");



var LogService = function (){
@@ -22,6 +24,7 @@ var LogService = function (){

this.queryUrl = GLOBAL.pjconfig.storage.queryUrl;
this.pushProjectUrl = GLOBAL.pjconfig.acceptor.pushProjectUrl;
this.pushProjectUrl2 = GLOBAL.pjconfig.open.pushProjectUrl;

logger.debug('query url : ' + this.queryUrl)
// this.url = 'http://127.0.0.1:9000/query';
@@ -67,43 +70,53 @@ LogService.prototype = {

var businessService = new BusinessService();

var tryTimes = 0;
var push = function (){

businessService.findBusiness(function (err , item){

var strParams = '';

_.each( item , function (value , ke){
strParams+=value.id+"_";
strParams+=value.id+"|"+value.appkey+"_";
});

if(strParams.length >0){
strParams = "projectsId="+strParams.substring(0 , strParams.length-1 ) + "&";
strParams = strParams.substring(0 , strParams.length-1 ) ;
}

strParams +="auth=badjsAccepter";
//strParams +="auth=badjsAccepter";

var result = [0,0]
var resultCall = function (){
if(result[0] < 0 && result[1] <0){
callback(new Error("error"))
}else if(result[0] > 0 && result[1] > 0) {
callback()
}

}

http.get( self.pushProjectUrl + '?' + strParams , function (res){
res
.on('data' , function (){})
.on('end' , function (){
callback();
})
request.post(self.pushProjectUrl , {form:{projectsId : strParams, auth : "badjsAccepter"}} , function (err ){
if(err){
logger.warn('push projectIds to acceptor error :' + err);
result[0] = -1
}else {
result[0] = 1;
}
resultCall();
});

}).on('error' , function (err){
if(tryTimes <=3 ){
tryTimes++;
logger.warn('push project error and try:' + err);
push();
request.post(self.pushProjectUrl2 , {form:{projectsId : strParams , auth : "badjsOpen"}} , function (err ){
if(err){
logger.warn('push projectIds to open error :' + err);
result[1] = -1;
}else {
logger.warn('push project error :' + err);
callback(err)
result[1] = 1;
}

resultCall();
});

})
});
}

Loading
Oops, something went wrong.

0 comments on commit f38e06b

Please sign in to comment.