提交 873fca7aa92af8cf1055c14fdbd60d0ce820c83c

作者 juvenile
0 个父辈

first commit

  1 +node_modules
  2 +*.lock
  3 +*.*.lock
  4 +.vscode
  5 +.idea
... ...
  1 +// # app
  2 +
  3 +var path = require('path');
  4 +var IoC = require('electrolyte');
  5 +var bootable = require('bootable');
  6 +var express = require('express');
  7 +
  8 +// change the working directory to the root directory
  9 +
  10 +process.chdir(__dirname);
  11 +
  12 +// dependency injection
  13 +
  14 +IoC.loader(IoC.node(path.join(__dirname, 'boot')));
  15 +IoC.loader('igloo', require('igloo'));
  16 +IoC.loader('controllers', IoC.node(path.join(__dirname, 'controllers')));
  17 +IoC.loader('services', IoC.node(path.join(__dirname, 'services')));
  18 +IoC.loader('models', IoC.node(path.join(__dirname, 'models')));
  19 +IoC.loader('utils',IoC.node(path.join(__dirname, 'utils')));
  20 +
  21 +// phases
  22 +
  23 +var app = bootable(express());
  24 +
  25 +
  26 +app.phase(bootable.di.initializers());
  27 +app.phase(bootable.di.routes('./routes/bootstarp.js'));
  28 +app.phase(IoC.create('igloo/server'));
  29 +
  30 +// boot
  31 +
  32 +var logger = IoC.create('igloo/logger');
  33 +var settings = IoC.create('igloo/settings');
  34 +
  35 +app.boot(function(err) {
  36 +
  37 + if (err) {
  38 + logger.error(err.message);
  39 +
  40 + if (settings.showStack) {
  41 + logger.error(err.stack);
  42 + }
  43 +
  44 + process.exit(-1);
  45 + return;
  46 + }
  47 +
  48 + logger.info('app booted');
  49 +
  50 +});
  51 +
  52 +exports = module.exports = app;
... ...
  1 +// # config
  2 +
  3 +var path = require('path');
  4 +
  5 +var parentDir = path.join(__dirname, '..');
  6 +console.log(parentDir,'reacasjdjsakfkjaskjfnasjdflkjas')
  7 +var appDir = path.join(parentDir, 'server');
  8 +
  9 +var pkg = require(path.join(parentDir, 'package'));
  10 +
  11 +var assetsDir = path.join(parentDir, 'build');
  12 +var publicDir = path.join(assetsDir, 'public');
  13 +var templatesDir = path.join(assetsDir, 'emails');
  14 +var viewsDir = path.join(appDir, 'views');
  15 +
  16 +var maxAge = 24 * 60 * 60 * 1000;//60 * 60 * 1000;
  17 +
  18 +exports = module.exports = function () {
  19 +
  20 + return {
  21 + defaults: {
  22 + basicAuth: {
  23 + enabled: false,
  24 + name: 'admin',
  25 + pass: 'password'
  26 + },
  27 + facebook: {
  28 + enabled: false,
  29 + appID: '',
  30 + appSecret: '',
  31 + scope: ['email']
  32 + },
  33 + google: {
  34 + enabled: false,
  35 + scope: [
  36 + 'https://www.googleapis.com/auth/userinfo.profile',
  37 + 'https://www.googleapis.com/auth/userinfo.email'
  38 + ],
  39 + clientID: '',
  40 + clientSecret: ''
  41 + },
  42 + pkg: pkg,
  43 + cache: false,
  44 + showStack: true,
  45 + assetsDir: assetsDir,
  46 + publicDir: publicDir,
  47 + views: {
  48 + dir: viewsDir,
  49 + engine: 'ejs'
  50 + },
  51 + password: {
  52 + minStrength: 0,
  53 + limitAttempts: false
  54 + },
  55 + email: {
  56 + templates: {
  57 + dir: templatesDir,
  58 + options: {
  59 + }
  60 + },
  61 + // <https://github.com/andris9/Nodemailer>
  62 + transport: {
  63 + service: 'gmail',
  64 + auth: {
  65 + user: 'hi@eskimo.io',
  66 + pass: 'abc123'
  67 + }
  68 + },
  69 + headers: {
  70 + from: 'hi@eskimo.io'
  71 + }
  72 + },
  73 + hipchat: {
  74 + level: 'error',
  75 + silent: false,
  76 + token: '',
  77 + notify: false,
  78 + color: 'yellow',
  79 + room: '',
  80 + from: '',
  81 + messageFormat: 'text'
  82 + },
  83 + session: {
  84 + secret: 'igloo-change-me',
  85 + key: 'igloo',
  86 + cookie: {
  87 + path: '/',
  88 + httpOnly: true,
  89 + secure: false,
  90 + sameSite: 'strict',
  91 + maxAge: maxAge
  92 + },
  93 + resave: true,
  94 + saveUninitialized: true
  95 + },
  96 + trustProxy: true,
  97 + updateNotifier: {
  98 + enabled: true,
  99 + dependencies: {},
  100 + updateCheckInterval: 1000 * 60 * 60,
  101 + updateCheckTimeout: 1000 * 20
  102 + },
  103 + staticServer: {
  104 + maxAge: maxAge
  105 + },
  106 + server: {
  107 + host: 'localhost',
  108 + cluster: false,
  109 + ssl: {
  110 + enabled: false,
  111 + options: {}
  112 + }
  113 + },
  114 + cookieParser: 'igloo-change-me',
  115 + csrf: {
  116 + enabled: false,
  117 + options: {
  118 + cookie: {
  119 + maxAge: maxAge
  120 + }
  121 + }
  122 + },
  123 + mongo: {
  124 + host: 'localhost',
  125 + port: 27017,
  126 + opts: {},
  127 + // faster - don't perform 2nd request to verify
  128 + // log message was received/saved
  129 + safe: false
  130 + },
  131 + knex: {
  132 + client: 'mysql'
  133 + },
  134 + redis: {
  135 + host: '192.168.2.70',
  136 + port: 38888,
  137 + pass: 'Q*Kr4?#Rg!',
  138 + maxAge: maxAge
  139 + },
  140 + output: {
  141 + handleExceptions: false,
  142 + colorize: true,
  143 + prettyPrint: false
  144 + },
  145 + logger: {
  146 + 'console': true,
  147 + requests: true,
  148 + mongo: false,
  149 + file: false,
  150 + hipchat: false,
  151 + slack: false
  152 + },
  153 + less: {
  154 + path: publicDir,
  155 + options: {
  156 + force: true
  157 + }
  158 + },
  159 + jade: {
  160 + amd: {
  161 + path: '/js/tmpl/',
  162 + options: {}
  163 + }
  164 + },
  165 + liveReload: {
  166 + port: 35729
  167 + },
  168 + restful: {
  169 + // url: 'http://154.8.229.55:20000/',
  170 + // url:'http://192.144.144.220:20000/',
  171 + //url:'http://127.0.0.1:20000/',
  172 + url: 'http://47.110.250.177:20000',
  173 + // url:'http://140.143.196.80:20000/',
  174 + ossUrl: 'http://192.168.2.72:20000/',
  175 + version: '/v1'
  176 + },
  177 + prefix: '/',
  178 + localStrategy: {
  179 + usernameField: 'username',
  180 + passwordField: 'password',
  181 + // session: false,
  182 + passReqToCallback: true
  183 + }
  184 + },
  185 + test: {
  186 + cache: true,
  187 + url: 'http://localhost:5999',
  188 + showStack: false,
  189 + updateNotifier: {
  190 + enabled: false,
  191 + },
  192 + restful: {
  193 + url: 'http://172.21.0.8:20000/',
  194 + ossUrl: 'http://172.21.0.8:10001/v1/',
  195 + version: '/v1'
  196 + },
  197 + server: {
  198 + host: '0.0.0.0',
  199 + env: 'production',
  200 + port: 5999,
  201 + cluster: false
  202 + },
  203 + redis: {
  204 + prefix: 'igloo_production_test_develop',
  205 + host: '172.21.0.8',
  206 + port: 38888,
  207 + pass: 'Q*Kr4?#Rg!'
  208 + },
  209 + logger: {
  210 + 'console': true,
  211 + requests: true,
  212 + mongo: false,
  213 + file: {
  214 + filename: '/opt/work/hro/frontend/hro-develop/igloo.log',
  215 + timestamp: true
  216 + }
  217 + }
  218 + },
  219 + development: {
  220 + cache: true,
  221 + url: 'http://localhost:3000',
  222 + server: {
  223 + env: 'development',
  224 + port: 3000,
  225 + },
  226 + mongo: {
  227 + dbname: 'igloo-development',
  228 + db: 'igloo-development' // keep for winston logger
  229 + },
  230 + knex: {
  231 + debug: true,
  232 + connection: {
  233 + host: '127.0.0.1',
  234 + user: 'root',
  235 + password: '',
  236 + database: 'igloo_development'
  237 + }
  238 + },
  239 + redis: {
  240 + prefix: 'igloo-development',
  241 + host: '127.0.0.1',
  242 + port: 6379,
  243 + pass: '',
  244 + }
  245 + },
  246 + production: {
  247 + cache: false,
  248 + url: 'http://localhost:6868',
  249 + views: {
  250 + dir: viewsDir,
  251 + },
  252 + publicDir: publicDir,
  253 + showStack: false,
  254 + updateNotifier: {
  255 + enabled: false,
  256 + },
  257 + restful: {
  258 + url: 'http://192.168.2.72:20000/',
  259 + ossUrl: 'http://192.168.2.72:20000/',
  260 + version: '/v1',
  261 + host: '192.168.2.72',
  262 + port: 20000
  263 + },
  264 + server: {
  265 + host: '0.0.0.0',
  266 + env: 'production',
  267 + port: 6868,
  268 + cluster: false
  269 + },
  270 + mongo: {
  271 + dbname: 'igloo-production',
  272 + db: 'igloo-production' // keep for winston logger
  273 + },
  274 + knex: {
  275 + connection: {
  276 + host: '127.0.0.1',
  277 + user: 'root',
  278 + password: '',
  279 + database: 'igloo_production'
  280 + }
  281 + },
  282 + redis: {
  283 + prefix: 'igloo_production',
  284 + host: '127.0.0.1',
  285 + port: 38888,
  286 + pass: 'Q*Kr4?#Rg!'
  287 + },
  288 + csrf: {
  289 + enabled: true,
  290 + options: {
  291 + cookie: {
  292 + maxAge: maxAge,
  293 + sameSite: 'strict',
  294 + path: '/',
  295 + key: '_csrf',
  296 + httpOnly: true
  297 + }
  298 + }
  299 + },
  300 + output: {
  301 + colorize: false
  302 + },
  303 + logger: {
  304 + 'console': true,
  305 + requests: true,
  306 + mongo: false,
  307 + file: {
  308 + filename: '/opt/work/hro/frontend/hro/igloo.log',
  309 + timestamp: true
  310 + }
  311 + }
  312 + },
  313 + recruitIterative: {
  314 + cache: true,
  315 + url: 'http://localhost:6200',
  316 + showStack: false,
  317 + updateNotifier: {
  318 + enabled: false,
  319 + },
  320 + restful: {
  321 + url: 'http://47.110.158.110:20000/',
  322 + // url: 'http://47.110.250.177:20000/',
  323 + // url: 'http://39.104.52.206:20000/',
  324 + ossUrl: 'http://47.110.158.110:20000/v1/',
  325 + version: '/v1',
  326 + host: '47.110.158.110',
  327 + // host: '47.110.250.177',
  328 + // host: '39.104.52.206',
  329 + port: 20000
  330 + },
  331 + server: {
  332 + host: '0.0.0.0',
  333 + env: 'production',
  334 + port: 6200,
  335 + cluster: false
  336 + },
  337 + redis: {
  338 + prefix: 'igloo_production_recruitIterative',
  339 + host: '127.0.0.1',
  340 + port: 38888,
  341 + pass: 'Q*Kr4?#Rg!'
  342 + },
  343 + csrf: {
  344 + enabled: true,
  345 + options: {
  346 + cookie: {
  347 + maxAge: maxAge,
  348 + sameSite: 'strict',
  349 + path: '/',
  350 + key: '_csrf',
  351 + httpOnly: true
  352 + }
  353 + }
  354 + },
  355 + logger: {
  356 + 'console': true,
  357 + requests: true,
  358 + mongo: false,
  359 + file: {
  360 + filename: '/opt/work/hro/frontend/hro-recruit-iterative/igloo.log',
  361 + timestamp: true
  362 + }
  363 + }
  364 + },
  365 + hroRecruit: {
  366 + cache: true,
  367 + url: 'http://localhost:6100',
  368 + showStack: false,
  369 + updateNotifier: {
  370 + enabled: false,
  371 + },
  372 + restful: {
  373 + // url: 'http://47.110.158.110:20000/',
  374 + url: 'http://47.110.250.177:20000/',
  375 + ossUrl: 'http://140.143.196.80:10001/v1/',
  376 + version: '/v1',
  377 + // host: '47.110.158.110',
  378 + host: '47.110.250.177',
  379 + port: 20000
  380 + },
  381 + server: {
  382 + host: '0.0.0.0',
  383 + env: 'production',
  384 + port: 6100,
  385 + cluster: false
  386 + },
  387 + redis: {
  388 + prefix: 'igloo_production_hroRecruit',
  389 + host: '127.0.0.1',
  390 + port: 38888,
  391 + pass: 'Q*Kr4?#Rg!'
  392 + },
  393 + csrf: {
  394 + enabled: true,
  395 + options: {
  396 + cookie: {
  397 + maxAge: maxAge,
  398 + sameSite: 'strict',
  399 + path: '/',
  400 + key: '_csrf',
  401 + httpOnly: true
  402 + }
  403 + }
  404 + },
  405 + logger: {
  406 + 'console': true,
  407 + requests: true,
  408 + mongo: false,
  409 + file: {
  410 + filename: '/opt/work/hro/frontend/hro-tax/igloo.log',
  411 + timestamp: true
  412 + }
  413 + }
  414 + },
  415 + hroTax: {
  416 + cache: true,
  417 + url: 'http://localhost:6100',
  418 + showStack: false,
  419 + updateNotifier: {
  420 + enabled: false,
  421 + },
  422 + restful: {
  423 + url: 'http://47.110.158.110:20000/',
  424 + // url: 'http://47.110.250.177:20000/',
  425 + ossUrl: 'http://140.143.196.80:10001/v1/',
  426 + version: '/v1',
  427 + host: '47.110.158.110',
  428 + // host: '47.110.250.177',
  429 + port: 20000
  430 + },
  431 + server: {
  432 + host: '0.0.0.0',
  433 + env: 'production',
  434 + port: 6100,
  435 + cluster: false
  436 + },
  437 + redis: {
  438 + prefix: 'igloo_production_hroSalary',
  439 + host: '172.26.212.124', //外服环境
  440 + // host: '127.0.0.1',
  441 + port: 38888,
  442 + pass: 'Q*Kr4?#Rg!'
  443 + },
  444 + csrf: {
  445 + enabled: true,
  446 + options: {
  447 + cookie: {
  448 + maxAge: maxAge,
  449 + sameSite: 'strict',
  450 + path: '/',
  451 + key: '_csrf',
  452 + httpOnly: true
  453 + }
  454 + }
  455 + },
  456 + logger: {
  457 + 'console': true,
  458 + requests: true,
  459 + mongo: false,
  460 + file: {
  461 + filename: '/opt/work/hro/frontend/hro-salary/igloo.log',
  462 + timestamp: true
  463 + }
  464 + }
  465 + },
  466 + hroSalary: {
  467 + cache: true,
  468 + url: 'http://localhost:6200',
  469 + showStack: false,
  470 + updateNotifier: {
  471 + enabled: false,
  472 + },
  473 + restful: {
  474 + // url: 'http://47.110.158.110:20000/',
  475 + url: 'http://47.110.250.177:20000/',
  476 + ossUrl: 'http://140.143.196.80:10001/v1/',
  477 + version: '/v1',
  478 + // host: '47.110.158.110',
  479 + host: '47.110.250.177',
  480 + port: 20000
  481 + },
  482 + server: {
  483 + host: '0.0.0.0',
  484 + env: 'production',
  485 + port: 6200,
  486 + cluster: false
  487 + },
  488 + redis: {
  489 + prefix: 'igloo_production_hroSalary',
  490 + host: '172.26.212.124',
  491 + port: 38888,
  492 + pass: 'Q*Kr4?#Rg!'
  493 + },
  494 + csrf: {
  495 + enabled: true,
  496 + options: {
  497 + cookie: {
  498 + maxAge: maxAge,
  499 + sameSite: 'strict',
  500 + path: '/',
  501 + key: '_csrf',
  502 + httpOnly: true
  503 + }
  504 + }
  505 + },
  506 + logger: {
  507 + 'console': true,
  508 + requests: true,
  509 + mongo: false,
  510 + file: {
  511 + filename: '/opt/work/hro/frontend/hro-salary/igloo.log',
  512 + timestamp: true
  513 + }
  514 + }
  515 + },
  516 + sipolicyIterative: {
  517 + cache: true,
  518 + url: 'http://localhost:8200',
  519 + showStack: false,
  520 + updateNotifier: {
  521 + enabled: false,
  522 + },
  523 + restful: {
  524 + url: 'http://47.110.250.177:20000/',
  525 + ossUrl: 'http://172.21.0.8:10001/v1/',
  526 + version: '/v1',
  527 + host: '47.110.250.177',
  528 + port: 20000
  529 + },
  530 + server: {
  531 + host: '0.0.0.0',
  532 + env: 'production',
  533 + port: 8200,
  534 + cluster: false
  535 + },
  536 + redis: {
  537 + prefix: 'igloo_production_sipolicyIterative',
  538 + host: '127.0.0.1',
  539 + port: 38888,
  540 + pass: 'Q*Kr4?#Rg!'
  541 + },
  542 + logger: {
  543 + 'console': true,
  544 + requests: true,
  545 + mongo: false,
  546 + file: {
  547 + filename: '/opt/work/hro/frontend/hro-sipolicy-iterative/igloo.log',
  548 + timestamp: true
  549 + }
  550 + }
  551 + },
  552 + hroSipolicy: {
  553 + cache: true,
  554 + url: 'http://localhost:8100',
  555 + showStack: false,
  556 + updateNotifier: {
  557 + enabled: false,
  558 + },
  559 + restful: {
  560 + url: 'http://47.110.250.177:20000/',
  561 + ossUrl: 'http://172.21.0.8:10001/v1/',
  562 + host: '47.110.250.177',
  563 + version: '/v1'
  564 + },
  565 + server: {
  566 + host: '0.0.0.0',
  567 + env: 'production',
  568 + port: 8100,
  569 + cluster: false
  570 + },
  571 + redis: {
  572 + prefix: 'igloo_production_hroSipolicy',
  573 + host: '127.0.0.1',
  574 + port: 38888,
  575 + pass: 'Q*Kr4?#Rg!'
  576 + },
  577 + logger: {
  578 + 'console': true,
  579 + requests: true,
  580 + mongo: false,
  581 + file: {
  582 + filename: '/opt/work/hro/frontend/hro-sipolicy/igloo.log',
  583 + timestamp: true
  584 + }
  585 + }
  586 + },
  587 + settlemgmIterative: {
  588 + cache: true,
  589 + url: 'http://localhost:9200',
  590 + showStack: false,
  591 + updateNotifier: {
  592 + enabled: false,
  593 + },
  594 + restful: {
  595 + url: 'http://47.110.158.110:20000/',
  596 + // url: 'http://47.110.250.177:20000/',
  597 + // url: 'http://39.104.52.206:20000/',
  598 + ossUrl: 'http://172.21.0.8:10001/v1/',
  599 + version: '/v1',
  600 + host: '47.110.158.110',
  601 + // host: '47.110.250.177',
  602 + // host: '39.104.52.206',
  603 + port: 20000
  604 + },
  605 +
  606 + server: {
  607 + host: '0.0.0.0',
  608 + env: 'production',
  609 + port: 9200,
  610 + cluster: false
  611 + },
  612 + redis: {
  613 + prefix: 'igloo_production_settlemgmIterative',
  614 + host: '127.0.0.1',
  615 + // host: '172.26.212.124',
  616 + port: 38888,
  617 + pass: 'Q*Kr4?#Rg!'
  618 +
  619 + },
  620 + logger: {
  621 + 'console': true,
  622 + requests: true,
  623 + mongo: false,
  624 + file: {
  625 + filename: '/opt/work/hro/frontend/hro-settlemgm-iterative/igloo.log',
  626 + timestamp: true
  627 + }
  628 + },
  629 + csrf: {
  630 + enabled: true,
  631 + options: {
  632 + cookie: {
  633 + maxAge: maxAge,
  634 + sameSite: 'strict',
  635 + path: '/',
  636 + key: '_csrf',
  637 + httpOnly: true
  638 + }
  639 + }
  640 + },
  641 + },
  642 + hroSettlemgm: {
  643 + cache: true,
  644 + url: 'http://localhost:9100',
  645 + showStack: false,
  646 + updateNotifier: {
  647 + enabled: false,
  648 + },
  649 + restful: {
  650 + // url: 'http://47.110.158.110:20000/',
  651 + // url: 'http://47.110.250.177:20000/',
  652 + url: 'http://39.104.52.206:20000/',
  653 + ossUrl: 'http://140.143.196.80:10001/v1/',
  654 + version: '/v1',
  655 + // host: '47.110.158.110',
  656 + // host: '47.110.250.177',
  657 + host: '39.104.52.206',
  658 + port: 20000
  659 + },
  660 + server: {
  661 + host: '0.0.0.0',
  662 + env: 'production',
  663 + port: 9100,
  664 + cluster: false
  665 + },
  666 + redis: {
  667 + prefix: 'igloo_production_hroSettlemgm',
  668 + // host: '127.0.0.1',
  669 + host: '172.26.212.124',
  670 + port: 38888,
  671 + pass: 'Q*Kr4?#Rg!'
  672 + },
  673 + logger: {
  674 + 'console': true,
  675 + requests: true,
  676 + mongo: false,
  677 + file: {
  678 + filename: '/opt/work/hro/frontend/hro-settlemgm/igloo.log',
  679 + timestamp: true
  680 + }
  681 + },
  682 + csrf: {
  683 + enabled: true,
  684 + options: {
  685 + cookie: {
  686 + maxAge: maxAge,
  687 + sameSite: 'strict',
  688 + path: '/',
  689 + key: '_csrf',
  690 + httpOnly: true
  691 + }
  692 + }
  693 + },
  694 + },
  695 + hroTemp: {
  696 + cache: true,
  697 + url: 'http://localhost:8777',
  698 + showStack: false,
  699 + updateNotifier: {
  700 + enabled: false,
  701 + },
  702 + restful: {
  703 + // url:'http://140.143.196.80:20000/',
  704 + url: 'http://154.8.229.55:20000/',
  705 + ossUrl: 'http://154.8.229.55:10001/v1/',
  706 + version: '/v1'
  707 + },
  708 + server: {
  709 + host: '0.0.0.0',
  710 + env: 'production',
  711 + port: 8777,
  712 + cluster: false
  713 + },
  714 + redis: {
  715 + prefix: 'igloo_production_hroTemp',
  716 + host: '172.21.0.8',
  717 + port: 38888,
  718 + pass: 'Q*Kr4?#Rg!'
  719 + },
  720 + logger: {
  721 + 'console': true,
  722 + requests: true,
  723 + mongo: false,
  724 + file: {
  725 + filename: '/opt/work/hro/frontend/hro-temp/igloo.log',
  726 + timestamp: true
  727 + }
  728 + }
  729 + },
  730 + hroOddjobs: {
  731 + cache: true,
  732 + url: 'http://localhost:8899',
  733 + showStack: false,
  734 + updateNotifier: {
  735 + enabled: false,
  736 + },
  737 + restful: {
  738 + url: 'http://47.110.250.177:20000/',
  739 + ossUrl: 'http://154.8.229.55:10001/v1/',
  740 + version: '/v1',
  741 + host: '47.110.250.177',
  742 + port: 20000
  743 + },
  744 + server: {
  745 + host: '0.0.0.0',
  746 + env: 'production',
  747 + port: 8899,
  748 + cluster: false
  749 + },
  750 + redis: {
  751 + prefix: 'igloo_production_hroOddjobs',
  752 + host: '192.168.12.188',
  753 + port: 38888,
  754 + pass: 'Q*Kr4?#Rg!'
  755 + },
  756 + logger: {
  757 + 'console': true,
  758 + requests: true,
  759 + mongo: false,
  760 + file: {
  761 + filename: '/opt/work/hro/frontend/hro-oddjobs/igloo.log',
  762 + timestamp: true
  763 + }
  764 + }
  765 + }
  766 + };
  767 +};
  768 +
  769 +exports['@singleton'] = true;
\ No newline at end of file
... ...
  1 +/*
  2 + * @Descripttion:
  3 + * @version:
  4 + * @Author: sueRimn
  5 + * @Date: 2020-06-28 15:34:13
  6 + * @LastEditors: genglw
  7 + * @LastEditTime: 2021-12-23 14:56:59
  8 + */
  9 +
  10 +// # local config (make sure it is ignored by git)
  11 +//
  12 +// This configuration file is specific to each developer's environment,
  13 +// and will merge on top of all other settings from ./config.js
  14 +// (but only will merge in development environment)
  15 +//
  16 +var maxAge = 60 * 60 * 1000 * 25;
  17 +exports = module.exports = function () {
  18 + return {
  19 + cache: false,
  20 + server: {
  21 + host: '0.0.0.0',
  22 + port: 3000
  23 + },
  24 + email: {
  25 + // <https://github.com/andris9/Nodemailer>
  26 + transport: {
  27 + service: 'gmail',
  28 + auth: {
  29 + user: 'user@gmail.com',
  30 + pass: 'abc123'
  31 + }
  32 + }
  33 + },
  34 + restful: {
  35 + // url: 'http://118.178.181.180:20000/',
  36 + // url: 'http://47.110.250.177:20000/',
  37 + url: 'http://47.110.158.110:20000/',
  38 + // url:'http://120.27.220.60:20000/',
  39 + // url: 'http://39.104.52.206:20000/',
  40 + // url: 'http://47.99.189.12:20000/',
  41 + ossUrl: 'http://47.110.250.177:20000/',
  42 + version: '/v1',
  43 + // host: '47.110.250.177',
  44 + host: '47.110.158.110',
  45 + // host: '120.27.220.60',
  46 + // host: '39.104.52.206',
  47 + port: 20000
  48 + },
  49 + csrf: {
  50 + enabled: true,
  51 + options: {
  52 + cookie: {
  53 + maxAge: maxAge,
  54 + key: '_csrf',
  55 + path: '/',
  56 + httpOnly: true,
  57 + sameSite: 'strict',
  58 + },
  59 + ignoreMethods: ['HEAD', 'OPTIONS', 'GET']
  60 + }
  61 + },
  62 + liveReload: {
  63 + enabled: true,
  64 + port: 35729
  65 + }
  66 + };
  67 +};
  68 +
  69 +exports['@singleton'] = true;
... ...
  1 +
  2 +// app - policies
  3 +
  4 +var connectEnsureLogin = require('connect-ensure-login');
  5 +// var auth = require('basic-auth');
  6 +var _ = require('underscore');
  7 +
  8 +exports = module.exports = function(IoC, User) {
  9 +
  10 + // policy/middleware helpers
  11 + var ensureLoggedIn = connectEnsureLogin.ensureLoggedIn;
  12 + // var ensureLoggedOut = connectEnsureLogin.ensureLoggedOut;
  13 +
  14 + // since there are issues with `passport-http` right now
  15 + // this is implemented as a temporary solution
  16 + function ensureApiToken(req, res, next) {
  17 + // var creds = auth(req);
  18 +
  19 + // if (!creds || !_.isString(creds.name)) {
  20 + // res.statusCode = 401;
  21 + // return next({
  22 + // message: 'API token missing',
  23 + // param: 'username'
  24 + // });
  25 + // }
  26 +
  27 + // User.findOne({
  28 + // api_token: creds.name
  29 + // }, function(err, user) {
  30 + // if (err) return next(err);
  31 + // if (!user) {
  32 + // return next({
  33 + // message: 'Invalid API token provided',
  34 + // param: 'username'
  35 + // });
  36 + // }
  37 + // req.user = user;
  38 + // next();
  39 + // });
  40 + if(req.session.passport&&req.session.passport.user&&req.session.passport.user.token)
  41 + next();
  42 + else{
  43 + res.statusCode = 401;
  44 + return next({ message: 'API token missing',param: 'username'});
  45 + }
  46 +
  47 + }
  48 +
  49 + function ensureLoggedOut(options){
  50 + if (typeof options == 'string') {
  51 + options = { redirectTo: options }
  52 + }
  53 + options = options || {};
  54 +
  55 + var url = options.redirectTo || '/signIn';
  56 + var setReturnTo = (options.setReturnTo === undefined) ? true : options.setReturnTo;
  57 + return function(req, res, next) {
  58 + if (!(req.session.passport&&req.session.passport.user&&req.session.passport.user.token)) {
  59 + if (setReturnTo && req.session) {
  60 + req.session.returnTo = req.originalUrl || req.url;
  61 + }
  62 + res.statusCode=302;
  63 + return res.send({redirect:'/'});
  64 + // return res.redirect(url);
  65 + }
  66 + next();
  67 + }
  68 + }
  69 +
  70 +
  71 + var policies = {
  72 + ensureLoggedIn: ensureLoggedIn,
  73 + ensureLoggedOut: ensureLoggedOut,
  74 + ensureApiToken: ensureApiToken,
  75 + notApiRouteRegexp: /^(?!\/__webpack_hmr\/)|(?!\/*.ico).*$/
  76 + };
  77 +
  78 + return policies;
  79 +
  80 +};
  81 +
  82 +exports['@singleton'] = true;
  83 +exports['@require'] = [ '$container', 'models/user' ];
... ...
  1 +
  2 +// # cluster
  3 +
  4 +var recluster = require('recluster');
  5 +var path = require('path');
  6 +var IoC = require('electrolyte');
  7 +
  8 +var cluster = recluster(path.join(__dirname, 'app.js'));
  9 +
  10 +IoC.loader(IoC.node(path.join(__dirname, 'boot')));
  11 +IoC.loader('igloo', require('igloo'));
  12 +var logger = IoC.create('igloo/logger');
  13 +
  14 +cluster.run();
  15 +
  16 +process.on('SIGUSR2', function() {
  17 + // reloading cluster
  18 + logger.info('received SIGUSR2, reloading cluster...');
  19 + cluster.reload();
  20 +});
  21 +
  22 +// spawned cluster process.id
  23 +// run kill -s SIGUSR2 to reload
  24 +logger.info('spawned cluster, `kill -s SIGUSR2 %d` to reload', process.pid);
... ...
  1 +var urlencode = require('urlencode');
  2 +exports = module.exports = function (logger, rest, settings) {
  3 + function getOptions(url, type) {
  4 + var catalog = url.substring(1, url.indexOf('/', 1));
  5 + var pathUrl = url.substring(url.indexOf('/', 1));
  6 + var fullPath = '/' + catalog + settings.restful.version + pathUrl;
  7 + return {
  8 + 'host': settings.restful.host, //后台请求地址
  9 + 'port': settings.restful.port,
  10 + 'path': fullPath,
  11 + 'method': type,
  12 + 'agent': false,
  13 + 'headers': {
  14 + "Accept": "application/json",
  15 + "Content-Type": "application/json",
  16 + 'User-Agent': 'Request for Express'
  17 + }
  18 + };
  19 + }
  20 +
  21 + function addToken(options, req) {
  22 + if (req.session.passport && req.session.passport.user && req.session.passport.user && req.session.passport.user.token) {
  23 + options.headers['Authorization'] = "Bearer " + req.session.passport.user.token;
  24 + }
  25 + if (req.headers['device-id']) {
  26 + options.headers['Device-Id'] = req.headers['device-id']
  27 + }
  28 + if (req.ip) {
  29 + options.headers['Client-Ip'] = req.ip
  30 + }
  31 + return options;
  32 + }
  33 +
  34 + function addParams(options, req) {
  35 + var postData = !req.body ? '' : JSON.stringify(req.body || {});
  36 + // options.headers['Content-Length'] = postData.length;
  37 + options.params = postData;
  38 + }
  39 +
  40 + function addContentLength(options) {
  41 + if (options.params) {
  42 + options.headers['Content-Length'] = options.params.length;
  43 + }
  44 + }
  45 +
  46 + function encodeUrl(url) {
  47 + return urlencode(url);
  48 + }
  49 +
  50 + function encodePamars(params) {
  51 + var temp = [];
  52 + for (var i = 0; i < params.length; i++) {
  53 + var param = params[i];
  54 + var tempParam = param.split("=")
  55 + tempParam[1] = urlencode.decode(tempParam[1], 'utf8');
  56 + tempParam[1] = tempParam[1].replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  57 + console.log(tempParam[1]);
  58 + if (i < (params.length - 1)) {
  59 + if (/[:&+/?%#=]/g.test(tempParam[1])) {
  60 + temp.push(tempParam[0] + "=" + encodeUrl(tempParam[1]) + "&");
  61 + } else {
  62 + temp.push(tempParam[0] + "=" + tempParam[1] + "&");
  63 + }
  64 + } else {
  65 + if (/[:&+/?%#=]/g.test(tempParam[1])) {
  66 + temp.push(tempParam[0] + "=" + encodeUrl(tempParam[1]));
  67 + } else {
  68 + temp.push(tempParam[0] + "=" + tempParam[1]);
  69 + }
  70 + }
  71 + }
  72 + return temp.join("");
  73 + }
  74 +
  75 + function handlePamars(url) {
  76 + var tempUrl = url;
  77 + // if(url.indexOf("?")!=-1){
  78 + // var temp=url.split("?");
  79 + // var params="";
  80 + // if(temp[1]&&temp[1].indexOf("&")!=-1){
  81 + // params=encodePamars(temp[1].split("&"));
  82 + // }else{
  83 + // params=encodePamars([temp[1]]);
  84 + // }
  85 + // return temp[0]+"?"+params;
  86 + // }else {
  87 + // return tempUrl;
  88 + // }
  89 + return tempUrl;
  90 + }
  91 +
  92 + function splitServiceFromUrl(url) {
  93 + var catalog = url.substring(1, url.indexOf('/', 1));
  94 + var pathUrl = url.substring(url.indexOf('/', 1));
  95 + var fullPath = settings.restful.url + catalog + settings.restful.version + pathUrl;
  96 + return fullPath
  97 + }
  98 +
  99 + function splitUrl(fullUrl) {
  100 + if (settings.prefix && settings.prefix.length > 1) {
  101 + fullUrl = fullUrl.substring(settings.prefix.length - 1);
  102 + }
  103 + var url = fullUrl.substring(4);
  104 + return url;
  105 + }
  106 +
  107 + function searchService(services, name) {
  108 + if (services[name]) {
  109 + console.log(services[name]);
  110 + return false;
  111 + } else {
  112 + return true;
  113 + }
  114 + }
  115 +
  116 + function checkReq(req, res) {
  117 + var flag = true;
  118 + // if(flag&&req.headers&&!req.headers['service-catalog']){
  119 + // res.status(400);
  120 + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"});
  121 + // flag=false;
  122 + // }
  123 + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){
  124 + // res.status(404);
  125 + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"});
  126 + // flag=false;
  127 + // }
  128 + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){
  129 + // res.status(404);
  130 + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"});
  131 + // flag=false;
  132 + // }
  133 + return flag;
  134 + }
  135 +
  136 + function checkJson(req) {
  137 + if (req.headers && req.headers['content-type'] == 'application/json') {
  138 + return true;
  139 + } else {
  140 + return false;
  141 + }
  142 + }
  143 +
  144 + function get(req, res, next) {
  145 + var url = splitUrl(req.originalUrl);
  146 + var options = getOptions(url, 'GET');
  147 + addToken(options, req);
  148 + function _success(data, response) {
  149 + if (response.statusCode >= 400 || !data) {
  150 + logger.error(options, data);
  151 + res.status(response.statusCode);
  152 + res.send(data);
  153 + } else {
  154 + res.send(data);
  155 + }
  156 + }
  157 + function _fail(err) {
  158 + logger.error(options, err);
  159 + res.send(err);
  160 + }
  161 + rest.restClient(options, _success, _fail);
  162 + }
  163 +
  164 + function post(req, res, next) {
  165 + var url = splitUrl(req.originalUrl);
  166 + var options = getOptions(url, 'POST');
  167 + addToken(options, req);
  168 + addParams(options, req);
  169 + function _success(data, response) {
  170 + if (response.statusCode >= 400) {
  171 + logger.error(options, data);
  172 + res.status(response.statusCode);
  173 + res.send(data);
  174 + } else if (!data || 'null' == data || "null\n" == data || '{}' == data) {
  175 + res.send({
  176 + code: 200,
  177 + message: '操作成功!'
  178 + });
  179 + } else {
  180 + res.send(data);
  181 + }
  182 + }
  183 + function _fail(err) {
  184 + logger.error(options, err);
  185 + res.send(err);
  186 + }
  187 + rest.restClient(options, _success, _fail);
  188 + }
  189 +
  190 + function put(req, res, next) {
  191 + var url = splitUrl(req.originalUrl);
  192 + var options = getOptions(url, 'PUT');
  193 + addToken(options, req);
  194 + addParams(options, req);
  195 + function _success(data, response) {
  196 + if (response.statusCode >= 400) {
  197 + logger.error(options, data);
  198 + res.status(response.statusCode);
  199 + res.send(data);
  200 + } else if (!data || 'null' == data || "null\n" == data || '{}' == data) {
  201 + res.send({
  202 + code: 200,
  203 + message: '操作成功!'
  204 + });
  205 + } else {
  206 + res.send(data);
  207 + }
  208 + }
  209 + function _fail(err) {
  210 + logger.error(options, err);
  211 + res.send(err);
  212 + }
  213 + rest.restClient(options, _success, _fail);
  214 + }
  215 +
  216 + function patch(req, res, next) {
  217 + var url = splitUrl(req.originalUrl);
  218 + var options = getOptions(url, 'PATCH');
  219 + addToken(options, req);
  220 + addParams(options, req);
  221 + function _success(data, response) {
  222 + if (response.statusCode >= 400) {
  223 + logger.error(options, data);
  224 + res.send(data);
  225 + } else if (!data) {
  226 + res.send({
  227 + code: 200,
  228 + message: '操作成功!'
  229 + });
  230 + } else {
  231 + res.send(data);
  232 + }
  233 + }
  234 + function _fail(err) {
  235 + logger.error(options, err);
  236 + res.send(err);
  237 + }
  238 + rest.restClient(options, _success, _fail);
  239 + }
  240 +
  241 + function head(req, res, next) {
  242 + var url = splitUrl(req.originalUrl);
  243 + var options = getOptions(url, 'HEAD');
  244 + addToken(options, req);
  245 + addParams(options, req);
  246 + function _success(data, response) {
  247 + if (response.statusCode >= 400) {
  248 + logger.error(options, data);
  249 + res.send(data);
  250 + } else if (!data) {
  251 + res.send({
  252 + code: 200,
  253 + message: '操作成功!'
  254 + });
  255 + } else {
  256 + res.send(data);
  257 + }
  258 + }
  259 + function _fail(err) {
  260 + logger.error(options, err);
  261 + res.send(err);
  262 + }
  263 + rest.restClient(options, _success, _fail);
  264 + }
  265 +
  266 + function del(req, res, next) {
  267 + var url = splitUrl(req.originalUrl);
  268 + var options = getOptions(url, 'DELETE');
  269 + addToken(options, req);
  270 + addParams(options, req);
  271 + addContentLength(options);
  272 + function _success(data, response) {
  273 + if (response.statusCode >= 400) {
  274 + logger.error(options, data);
  275 + res.status(response.statusCode);
  276 + res.send(data);
  277 + } else if (!data || (data && !data.message)) {
  278 + res.send({
  279 + code: 200,
  280 + action: "delete",
  281 + message: '删除成功'
  282 + });
  283 + } else {
  284 + res.send(data);
  285 + }
  286 + }
  287 + function _fail(err) {
  288 + logger.error(options, err);
  289 + res.send(err);
  290 + }
  291 + rest.restClient(options, _success, _fail);
  292 + }
  293 +
  294 + return {
  295 + 'get': get,
  296 + 'post': post,
  297 + 'put': put,
  298 + 'patch': patch,
  299 + 'head': head,
  300 + 'delete': del
  301 + };
  302 +};
  303 +
  304 +exports['@singleton'] = true;
  305 +exports['@require'] = ['igloo/logger', 'utils/rest', 'igloo/settings'];
... ...
  1 +const passport = require("passport");
  2 +const urlencode = require("urlencode");
  3 +const async = require("async");
  4 +const crypto = require("crypto");
  5 +
  6 +exports = module.exports = function (logger, rest, settings) {
  7 + function index(req, res, next) {
  8 + logger.info(req.user);
  9 + res.redirect("https://www.baidu.com");
  10 + }
  11 +
  12 + function indexPrefix(req, res) {
  13 + logger.info(req.user);
  14 + if (req.csrfToken) {
  15 + if (settings.prefix && settings.prefix.length > 1) {
  16 + res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
  17 + } else {
  18 + res.render("index", { csrfToken: req.csrfToken() });
  19 + }
  20 + } else res.render("index", { csrfToken: "" });
  21 + }
  22 +
  23 + function productDes(req, res, next) {
  24 + if (req.csrfToken)
  25 + res.render("chat/new-chat", { csrfToken: req.csrfToken() });
  26 + else res.render("chat/new-chat", { csrfToken: "" });
  27 + }
  28 +
  29 + function recharge(req, res) {
  30 + var params = JSON.parse(urlencode.decode(req.query.params));
  31 + console.log(params);
  32 + if (req.csrfToken)
  33 + res.render("recharge", { recharge: params, csrfToken: req.csrfToken() });
  34 + else res.render("recharge", { recharge: params, csrfToken: "" });
  35 + }
  36 +
  37 + function register(req, res, next) {
  38 + if (req.csrfToken)
  39 + res.render("newRegister", { csrfToken: req.csrfToken() });
  40 + else res.render("newRegister", { csrfToken: "" });
  41 + }
  42 +
  43 + function mobileRegister(req, res) {
  44 + if (req.csrfToken)
  45 + res.render("registerMobile", { csrfToken: req.csrfToken() });
  46 + else res.render("registerMobile", { csrfToken: "" });
  47 + }
  48 +
  49 + function mobileRegisterSuccess(req, res) {
  50 + if (req.csrfToken)
  51 + res.render("registerMobileSuccess", { csrfToken: req.csrfToken() });
  52 + else res.render("registerMobileSuccess", { csrfToken: "" });
  53 + }
  54 +
  55 + function signIn(req, res, next) {
  56 + // console.log(req);
  57 + if (req.csrfToken) res.render("newLogin", { csrfToken: req.csrfToken() });
  58 + else res.render("newLogin", { csrfToken: "" });
  59 + }
  60 +
  61 + function doLogin(req, res, next) {
  62 + passport.authenticate("local", function (err, user, info) {
  63 + console.log("doLogin:", err, user, info);
  64 + if (err) {
  65 + return next(err);
  66 + }
  67 + if (!user) {
  68 + return res.send(info);
  69 + }
  70 + req.logIn(user, function (err) {
  71 + if (err) {
  72 + return next(err);
  73 + }
  74 + return res.send({
  75 + ok: "登录成功",
  76 + user_info: req.session.passport.user.user_info,
  77 + });
  78 + });
  79 + })(req, res, next);
  80 + }
  81 +
  82 + function signOut(req, res, next) {
  83 + if (
  84 + req.session.passport &&
  85 + req.session.passport.user &&
  86 + req.session.passport.user.user_info &&
  87 + req.session.passport.user.user_info.user
  88 + )
  89 + logger.info(
  90 + req.session.passport.user.user_info.user,
  91 + "You have successfully logged out"
  92 + );
  93 + req.logout();
  94 + req.flash("success", "You have successfully logged out");
  95 + res.redirect("/");
  96 + }
  97 +
  98 + function smsCodes(req, res, next) {
  99 + rest.postJson({
  100 + baseUrl: "url",
  101 + url: "auth/smscodes",
  102 + params: req.body,
  103 + callback: _cb,
  104 + req: req,
  105 + res: res,
  106 + options: {},
  107 + excludeToken: true,
  108 + });
  109 + function _cb(data, response) {
  110 + logger.info("back data:", data);
  111 + if (response.statusCode < 300) {
  112 + res.send({ code: 200, message: "发送成功" });
  113 + } else {
  114 + res.send(data);
  115 + }
  116 + }
  117 + }
  118 +
  119 + function tenants(req, res, next) {
  120 + rest.register({
  121 + baseUrl: "url",
  122 + url: "tenants",
  123 + params: req.body,
  124 + callback: _cb,
  125 + req: req,
  126 + res: res,
  127 + options: {},
  128 + excludeToken: true,
  129 + });
  130 + function _cb(data, response) {
  131 + logger.info("back data:", data);
  132 + res.send(data);
  133 + }
  134 + }
  135 +
  136 + function resetPass(req, res) {
  137 + rest.putJson({
  138 + baseUrl: "url",
  139 + url: "auth/user",
  140 + params: {
  141 + user: req.body.user,
  142 + password: req.body.password,
  143 + again_password: req.body.again_password,
  144 + },
  145 + callback: _cb,
  146 + req: req,
  147 + res: res,
  148 + options: {},
  149 + });
  150 + function _cb(data, response) {
  151 + logger.info("back data:", data);
  152 + res.send(data);
  153 + }
  154 + }
  155 +
  156 + function updatePassword(req, res) {
  157 + rest.patchJson({
  158 + baseUrl: "url",
  159 + url: "users/" + req.body.userId,
  160 + params: {
  161 + password: req.body.password,
  162 + },
  163 + callback: _cb,
  164 + req: req,
  165 + res: res,
  166 + options: {},
  167 + });
  168 + function _cb(data, response) {
  169 + logger.info("back data:", data);
  170 + res.send(data);
  171 + }
  172 + }
  173 +
  174 + function loadUserInfo(req, res) {
  175 + settings;
  176 + if (req.session.passport.user && req.session.passport.user.user_info) {
  177 + res.send({
  178 + user_info: req.session.passport.user.user_info,
  179 + prefix: settings.prefix,
  180 + });
  181 + } else {
  182 + res.send({ user_info: null, prefix: settings.prefix });
  183 + }
  184 + }
  185 +
  186 + function getUploaderToken(req, res) {
  187 + rest.postJson({
  188 + baseUrl: "ossUrl",
  189 + url: "inits",
  190 + params: req.body,
  191 + callback: _cb,
  192 + req: req,
  193 + res: res,
  194 + options: {},
  195 + });
  196 + function _cb(data, response) {
  197 + logger.info("back data:", data);
  198 + res.send(data);
  199 + }
  200 + }
  201 +
  202 + function getObjectTokenByID(req, res) {
  203 + rest.get({
  204 + baseUrl: "ossUrl",
  205 + url: "objects/" + req.body.file_id,
  206 + params: {},
  207 + callback: _cb,
  208 + req: req,
  209 + res: res,
  210 + options: {},
  211 + });
  212 + function _cb(data, response) {
  213 + logger.info("back data:", data);
  214 + res.send(data);
  215 + }
  216 + }
  217 +
  218 + function delOSSObject(req, res) {
  219 + rest.del({
  220 + baseUrl: "ossUrl",
  221 + url:
  222 + "s3objects/" +
  223 + req.body.request_id +
  224 + "?bucket=" +
  225 + req.body.bucket +
  226 + "&file=" +
  227 + req.body.name,
  228 + params: {},
  229 + callback: _cb,
  230 + req: req,
  231 + res: res,
  232 + options: {},
  233 + });
  234 + function _cb(data, response) {
  235 + logger.info("back data:", data);
  236 + console.log(response.statusCode);
  237 + if (response.statusCode < 300) {
  238 + res.send({ delete: "ok" });
  239 + }
  240 + }
  241 + }
  242 +
  243 + function smsVerification(req, res) {
  244 + rest.postJson({
  245 + baseUrl: "url",
  246 + url: "auth/sms_verification",
  247 + params: req.body,
  248 + callback: _cb,
  249 + req: req,
  250 + res: res,
  251 + options: {},
  252 + excludeToken: true,
  253 + });
  254 + function _cb(data, response) {
  255 + logger.info("back data:", data);
  256 + if (response.statusCode < 300) {
  257 + res.send({ code: 200, message: "发送成功" });
  258 + } else {
  259 + res.send({
  260 + code: response.statusCode,
  261 + message: data.message,
  262 + errors: data.errors,
  263 + });
  264 + }
  265 + }
  266 + }
  267 +
  268 + function healthMonitor(res) {
  269 + res.statusCode = 200;
  270 + return res.send("status ok");
  271 + }
  272 +
  273 + function updateUserRoles(req, res) {
  274 + rest.putJson({
  275 + baseUrl: "url",
  276 + url: "user_roles/" + req.body.user_id,
  277 + params: req.body.roles,
  278 + callback: _cb,
  279 + req: req,
  280 + res: res,
  281 + options: {},
  282 + });
  283 + function _cb(data, response) {
  284 + logger.info("back data:", data);
  285 + if (response.statusCode < 300) {
  286 + res.send({ back: "ok" });
  287 + } else {
  288 + res.send(data);
  289 + }
  290 + }
  291 + }
  292 +
  293 + function getRoles(req, res) {
  294 + rest.get({
  295 + baseUrl: "url",
  296 + url: "roles",
  297 + params: {},
  298 + callback: _cb,
  299 + req: req,
  300 + res: res,
  301 + options: {},
  302 + });
  303 + function _cb(data, response) {
  304 + logger.info("back data:", data);
  305 + res.send(data);
  306 + }
  307 + }
  308 +
  309 + function getUserRoles(req, res) {
  310 + rest.get({
  311 + baseUrl: "url",
  312 + url:
  313 + "user_roles?user=" +
  314 + urlencode(req.body.user) +
  315 + "&limit=" +
  316 + req.body.limit +
  317 + "&offset=" +
  318 + req.body.offset,
  319 + params: {},
  320 + callback: _cb,
  321 + req: req,
  322 + res: res,
  323 + options: {},
  324 + });
  325 + function _cb(data, response) {
  326 + logger.info("back data:", data);
  327 + res.send(data);
  328 + }
  329 + }
  330 +
  331 + function getTenant(req, res) {
  332 + rest.get({
  333 + baseUrl: "url",
  334 + url: "tenants/" + req.body.tenant_id,
  335 + params: {},
  336 + callback: _cb,
  337 + req: req,
  338 + res: res,
  339 + options: {},
  340 + });
  341 + function _cb(data, response) {
  342 + logger.info("back data:", data);
  343 + res.send(data);
  344 + }
  345 + }
  346 +
  347 + function updateTenant(req, res) {
  348 + rest.putJson({
  349 + baseUrl: "url",
  350 + url: "tenants/" + req.body.tenant_id,
  351 + params: req.body.tenant,
  352 + callback: _cb,
  353 + req: req,
  354 + res: res,
  355 + options: {},
  356 + });
  357 + function _cb(data, response) {
  358 + logger.info("back data:", data);
  359 + res.send(data);
  360 + }
  361 + }
  362 +
  363 + function offer(req, res) {
  364 + rest.get({
  365 + baseUrl: "hrUrl",
  366 + url:
  367 + "offers/" + req.params.requestId + "?tenant_id=" + req.query.tenant_id,
  368 + params: {},
  369 + callback: _cb,
  370 + req: req,
  371 + res: res,
  372 + options: {},
  373 + excludeToken: true,
  374 + });
  375 + function _cb(data, response) {
  376 + logger.info("back data:", data);
  377 + //res.send(data);
  378 + console.log(data);
  379 + data["offerId"] = req.params.requestId;
  380 + data["tenantId"] = req.query.tenant_id;
  381 + res.render("offer", data);
  382 + }
  383 + }
  384 +
  385 + function onboardStatus(req, res) {
  386 + rest.get({
  387 + baseUrl: "hrUrl",
  388 + url: "onboard-status",
  389 + params: {},
  390 + callback: _cb,
  391 + req: req,
  392 + res: res,
  393 + options: {},
  394 + useUrl: true,
  395 + });
  396 + function _cb(data, response) {
  397 + logger.info("back data:", data);
  398 + res.send(data);
  399 + }
  400 + }
  401 +
  402 + function dowloadApp(req, res) {
  403 + var mobileAgent = req.headers["user-agent"].toLowerCase();
  404 + var agent = {
  405 + android:
  406 + mobileAgent.indexOf("android") > -1 || mobileAgent.indexOf("Adr") > -1,
  407 + iPhone: mobileAgent.indexOf("iphone") > -1,
  408 + iPad: mobileAgent.indexOf("ipad") > -1,
  409 + };
  410 + if (agent.iPhone || agent.iPad) {
  411 + res.redirect(
  412 + 301,
  413 + "https://itunes.apple.com/cn/app/%E8%96%AA%E5%91%97/id1140779439?l=en&mt=8"
  414 + );
  415 + } else if (agent.android) {
  416 + res.redirect(
  417 + 301,
  418 + "http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk"
  419 + );
  420 + } else {
  421 + res.redirect(
  422 + 301,
  423 + "http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk"
  424 + );
  425 + }
  426 + }
  427 +
  428 + function softwareLicense(res) {
  429 + res.render("softwareLicense");
  430 + }
  431 +
  432 + function changePassForRegister(req, res) {
  433 + var options = {
  434 + baseUrl: "url",
  435 + url: "users/" + req.body.user_id,
  436 + params: {
  437 + password: req.body.password,
  438 + },
  439 + callback: _cb,
  440 + req: req,
  441 + res: res,
  442 + options: {},
  443 + };
  444 + if (req.body.access_token) {
  445 + console.log("@@@!!!!!!!!!!!!!!!!");
  446 + options.options = {
  447 + accessToken: req.body.access_token,
  448 + };
  449 + options["excludeToken"] = true;
  450 + }
  451 + rest.patchJson(options);
  452 + function _cb(data, response) {
  453 + logger.info("back data:", data);
  454 + res.send(data);
  455 + }
  456 + }
  457 +
  458 + function changeTenant(req, res) {
  459 + var params = {
  460 + grant_type: "refresh_token",
  461 + scope: "global_access:tenant_admin,tenant:" + req.body.id,
  462 + refresh_token: req.session.passport.user.refreshToken,
  463 + };
  464 + req.session.passport.user.token = "";
  465 + rest.postJson({
  466 + baseUrl: "url",
  467 + url:
  468 + settings.restful.url +
  469 + "uaa" +
  470 + settings.restful.version +
  471 + "/auth/tokens",
  472 + useUrl: true,
  473 + params: params,
  474 + callback: _cb,
  475 + req: req,
  476 + res: res,
  477 + options: {},
  478 + excludeToken: true,
  479 + });
  480 + function _cb(data, response) {
  481 + console.log(data);
  482 + logger.info("back data:", data);
  483 + if (response.statusCode < 300) {
  484 + req.session.passport.user.token = data.access_token;
  485 + req.session.passport.user.refreshToken = data.refresh_token;
  486 + req.session.passport.user.user_info = {
  487 + user: data.user,
  488 + perms: [],
  489 + tenant: data.tenant,
  490 + scope: data.scope,
  491 + oss: req.session.passport.user.user_info.oss,
  492 + };
  493 + req.session.save(function () {
  494 + rest.get({
  495 + baseUrl: "url",
  496 + url:
  497 + settings.restful.url +
  498 + "uaa" +
  499 + settings.restful.version +
  500 + "/perms/detail",
  501 + useUrl: true,
  502 + params: {},
  503 + callback: _scb,
  504 + req: req,
  505 + res: res,
  506 + options: {},
  507 + });
  508 + });
  509 + } else {
  510 + res.send({
  511 + code: response.statusCode,
  512 + message: data.message,
  513 + initialize_done: "n",
  514 + });
  515 + }
  516 + }
  517 + function _scb(data1, response) {
  518 + if (response.statusCode < 300 && data1.items) {
  519 + req.session.passport.user.user_info.perms = data1.items;
  520 + req.session.save(function () {
  521 + // res.send({"code":200,"message":"切换租户成功"});
  522 + rest.get({
  523 + baseUrl: "url",
  524 + url:
  525 + settings.restful.url +
  526 + "filemeta" +
  527 + settings.restful.version +
  528 + "/config",
  529 + useUrl: true,
  530 + params: {},
  531 + callback: _scb1,
  532 + req: req,
  533 + res: res,
  534 + options: {},
  535 + });
  536 + });
  537 + } else {
  538 + res.send({ code: response.statusCode, message: data1.message });
  539 + }
  540 + }
  541 + function _scb1(data2, response) {
  542 + if (response.statusCode < 300 && data2 && data2.bucket) {
  543 + req.session.passport.user.user_info.oss = data2;
  544 + req.session.save(function () {
  545 + res.send({ code: 200, message: "切换租户成功" });
  546 + });
  547 + } else {
  548 + res.send({ code: 200, message: "切换租户失败" });
  549 + }
  550 + }
  551 + }
  552 +
  553 + function sendRejectOffer(req, res) {
  554 + rest.get({
  555 + baseUrl: "hrUrl",
  556 + url: req.body.url, //传一个参数
  557 + params: {},
  558 + callback: _cb,
  559 + req: req,
  560 + res: res,
  561 + options: {},
  562 + excludeToken: true,
  563 + useUrl: true,
  564 + });
  565 + function _cb(data, response) {
  566 + logger.info("back data:", data);
  567 + if (response.statusCode < 300) {
  568 + res.send({ action: "ok" });
  569 + } else {
  570 + res.send(data);
  571 + }
  572 + }
  573 + }
  574 +
  575 + function acceptOffer(req, res) {
  576 + rest.get({
  577 + baseUrl: "hrUrl",
  578 + url: req.body.url, //传一个参数
  579 + params: {},
  580 + callback: _cb,
  581 + req: req,
  582 + res: res,
  583 + options: {},
  584 + excludeToken: true,
  585 + useUrl: true,
  586 + });
  587 + function _cb(data, response) {
  588 + logger.info("back data:", data);
  589 + if (response.statusCode < 300) {
  590 + res.send({ action: "ok" });
  591 + } else {
  592 + res.send(data);
  593 + }
  594 + }
  595 + }
  596 +
  597 + function imTokens(req, res) {
  598 + rest.post({
  599 + url: "auth/im_tokens",
  600 + params: req.body,
  601 + callback: _cb,
  602 + req: req,
  603 + res: res,
  604 + options: {},
  605 + });
  606 + function _cb(data, response) {
  607 + logger.info("back data:", data);
  608 + res.send(data);
  609 + }
  610 + }
  611 +
  612 + function listChannels(req, res) {
  613 + rest.get({
  614 + baseUrl: "chatUrl",
  615 + url: "channels?page_size=10&page=0&status=active",
  616 + params: req.body,
  617 + callback: _cb,
  618 + req: req,
  619 + res: res,
  620 + options: {},
  621 + });
  622 + function _cb(data, response) {
  623 + logger.info("back data:", data);
  624 + res.send(data);
  625 + }
  626 + }
  627 +
  628 + function filemeta(req, res) {
  629 + var fullPath =
  630 + settings.restful.url +
  631 + "filemeta" +
  632 + settings.restful.version +
  633 + "/object-redirect";
  634 + fullPath =
  635 + fullPath +
  636 + "?" +
  637 + "bucket=" +
  638 + req.query.bucket +
  639 + "&object=" +
  640 + encodeURIComponent(req.query.object);
  641 + console.info("fullPath::::::", fullPath);
  642 + var options = {
  643 + service_catalog: "",
  644 + url: fullPath,
  645 + useUrl: true,
  646 + params: req.body,
  647 + callback: _cb,
  648 + req: req,
  649 + res: res,
  650 + options: {},
  651 + };
  652 + rest.get(options);
  653 + function _cb(data, response) {
  654 + if (data && data.download_url) {
  655 + if (req.query.type && "json" == req.query.type) {
  656 + res.send(data);
  657 + } else {
  658 + var url = data.download_url;
  659 + let path = url.split("?")[0];
  660 + let pathArray = path.split("/");
  661 + let result = [];
  662 + for (var i = 0; i < pathArray.length; i++) {
  663 + if (i == pathArray.length - 1) {
  664 + result.push(encodeURIComponent(pathArray[i]));
  665 + } else {
  666 + result.push(pathArray[i]);
  667 + }
  668 + }
  669 + let result1 = result.join("/");
  670 + if (url.indexOf("?") !== -1) {
  671 + result1 += "?" + url.split("?")[1];
  672 + }
  673 + if (req.query.result_callback) {
  674 + res.send(data);
  675 + } else {
  676 + res.redirect(301, result1);
  677 + }
  678 + }
  679 + } else {
  680 + res.send(data);
  681 + }
  682 + }
  683 + }
  684 +
  685 + function getCustomerQrcode(req, res) {
  686 + var fullPath =
  687 + settings.restful.url +
  688 + "crm" +
  689 + settings.restful.version +
  690 + "/customers/" +
  691 + req.query.id +
  692 + "/qrcode";
  693 + var options = {
  694 + service_catalog: "",
  695 + url: fullPath,
  696 + useUrl: true,
  697 + params: req.body,
  698 + callback: _cb,
  699 + req: req,
  700 + res: res,
  701 + options: {},
  702 + };
  703 + rest.get(options);
  704 + function _cb(data, response) {
  705 + if (data && data.url_path) {
  706 + res.redirect(301, data.url_path);
  707 + } else {
  708 + res.send(data);
  709 + }
  710 + }
  711 + }
  712 +
  713 + function getPositionQrcode(req, res) {
  714 + var fullPath =
  715 + settings.restful.url +
  716 + "recruit" +
  717 + settings.restful.version +
  718 + "/positions/" +
  719 + req.query.id +
  720 + "/qrcode";
  721 + var options = {
  722 + service_catalog: "",
  723 + url: fullPath,
  724 + useUrl: true,
  725 + params: req.body,
  726 + callback: _cb,
  727 + req: req,
  728 + res: res,
  729 + options: {},
  730 + };
  731 + rest.get(options);
  732 + function _cb(data, response) {
  733 + if (data && data.url_path) {
  734 + res.redirect(301, data.url_path);
  735 + } else {
  736 + res.send(data);
  737 + }
  738 + }
  739 + }
  740 +
  741 + function getOSSConfig(req, res) {
  742 + var fullPath =
  743 + settings.restful.url + "filemeta" + settings.restful.version + "/config";
  744 + var options = {
  745 + service_catalog: "",
  746 + url: fullPath,
  747 + useUrl: true,
  748 + params: req.body,
  749 + callback: _cb,
  750 + req: req,
  751 + res: res,
  752 + options: {},
  753 + };
  754 + rest.get(options);
  755 + function _cb(data, response) {
  756 + if (data && data.bucket) {
  757 + req.session.passport.user.user_info.oss = data;
  758 + req.session.save(function () {
  759 + res.send({ code: 200, message: "oss配置加载成功" });
  760 + });
  761 + } else {
  762 + res.send({ code: 200, message: "oss配置加载失败" });
  763 + }
  764 + }
  765 + }
  766 +
  767 + function weidianTempLate(req, res) {
  768 + const { params } = req;
  769 + var fullPath =
  770 + settings.restful.url + "socialwork/internal/minishop/" + params.id;
  771 + var options = {
  772 + service_catalog: "",
  773 + url: fullPath,
  774 + useUrl: true,
  775 + params: req.body,
  776 + callback: _cb,
  777 + req: req,
  778 + res: res,
  779 + options: {},
  780 + excludeToken: true,
  781 + };
  782 + rest.get(options);
  783 + function _cb(data, response) {
  784 + logger.info("back data:", data);
  785 + if (response.statusCode < 300) {
  786 + const { shop_logo = [], shop_name = "", shop_comment = "" } = data;
  787 + let imgUrl = "";
  788 + if (shop_logo.length > 0) {
  789 + imgUrl = "http://oss.workai.com.cn/public/" + shop_logo[0].object;
  790 + }
  791 + res.render("template/weiDian", {
  792 + imgUrl: imgUrl,
  793 + shop_name: shop_name,
  794 + shop_comment: shop_comment,
  795 + });
  796 + } else {
  797 + res.render("template/weiDian");
  798 + }
  799 + }
  800 + }
  801 +
  802 + function workaiSecurityOAuth(req, res) {
  803 + var params = req.query;
  804 + if (params.authorization_code) {
  805 + var passport = {
  806 + user: {
  807 + refreshToken: "",
  808 + token: "",
  809 + service_catalog: {},
  810 + user_info: {},
  811 + err: null,
  812 + },
  813 + };
  814 + async.waterfall(
  815 + [
  816 + function (callback) {
  817 + //第三方登录
  818 + var tempParams = {
  819 + grant_type: "authorization_code_v1",
  820 + code: params.authorization_code,
  821 + };
  822 + // var tempParams={
  823 + // "grant_type":"password",
  824 + // "username":"18510929499",
  825 + // "scope":"global_access:tenant_admin",
  826 + // "password":"a123456"
  827 + // };
  828 + logger.info(
  829 + "Third login",
  830 + settings.restful.url + "uaa/v1/auth/tokens",
  831 + tempParams
  832 + );
  833 + rest.restful
  834 + .postJson(
  835 + settings.restful.url + "uaa/v1/auth/tokens",
  836 + tempParams,
  837 + {
  838 + headers: {
  839 + "Content-Type": "application/json",
  840 + Accept: "application/json",
  841 + },
  842 + }
  843 + )
  844 + .on("success", function (data) {
  845 + logger.info("Third login json data:", data);
  846 + if (data.access_token) {
  847 + var scopes = data.scope.split(",");
  848 + passport.user.token = data.access_token;
  849 + passport.user.refreshToken = data.refresh_token;
  850 + passport.user.user_info = data.user || {};
  851 + passport.user.tenant_info = data.tenant;
  852 + passport.user.customer_info = data.customer;
  853 + passport.user.user_info.perms = data.perms;
  854 + passport.user.type = data.user.type;
  855 + passport.user.real_auth_status = data.user.real_auth_status;
  856 + passport.user.credential_status = data.user.credential_status;
  857 + passport.user.user_info.scope = scopes[0];
  858 + callback(null, data);
  859 + } else {
  860 + var err = new Error("Third login err");
  861 + passport.user.err = data.message;
  862 + callback(err, data);
  863 + }
  864 + })
  865 + .on("error", function (err, response) {
  866 + logger.error("Third login error", err);
  867 + var err = new Error("Third login err");
  868 + callback(err, response);
  869 + })
  870 + .on("fail", function (data, response) {
  871 + logger.error("Third login fail", data);
  872 + callback(data, response);
  873 + });
  874 + },
  875 + function (data, callback) {
  876 + //获取机构列表
  877 + var tempHead = {};
  878 + var ip = req.ip.match(/\d+\.\d+\.\d+\.\d+/)[0];
  879 + var user_agent = req.headers["user-agent"] || "";
  880 + tempHead["SXClientIP"] = ip;
  881 + tempHead["User-Agent"] = user_agent;
  882 + logger.info(
  883 + "Third login tenants",
  884 + settings.restful.url + "uaa/v1/tenants?all=true",
  885 + { accessToken: data.access_token, headers: tempHead }
  886 + );
  887 + rest.restful
  888 + .get(settings.restful.url + "uaa/v1/tenants?all=true", {
  889 + accessToken: data.access_token,
  890 + headers: tempHead,
  891 + })
  892 + .on("success", function (data1) {
  893 + logger.info("Third login tenants list:", data1);
  894 + if (data1 && data1.items && data1.items.length > 0) {
  895 + callback(null, data1.items);
  896 + } else {
  897 + var err = new Error("Third login tenants list err");
  898 + passport.user.err = data.message;
  899 + callback(err, data);
  900 + }
  901 + })
  902 + .on("error", function (err, response) {
  903 + var err = new Error("Third login tenants list err");
  904 + callback(err, response);
  905 + })
  906 + .on("fail", function (data, response) {
  907 + callback(data, response);
  908 + });
  909 + },
  910 + function (data, callback) {
  911 + //刷新token
  912 + if (data && data.length == 1) {
  913 + var params = {
  914 + grant_type: "refresh_token",
  915 + scope: "global_access:tenant_admin,tenant:" + data[0].id,
  916 + refresh_token: passport.user.refreshToken,
  917 + };
  918 + passport.user.token = "";
  919 + logger.info(
  920 + "Third login tokens",
  921 + settings.restful.url + "uaa/v1/auth/tokens",
  922 + params
  923 + );
  924 + rest.restful
  925 + .postJson(settings.restful.url + "uaa/v1/auth/tokens", params, {
  926 + headers: {
  927 + "Content-Type": "application/json",
  928 + Accept: "application/json",
  929 + },
  930 + })
  931 + .on("success", function (data2) {
  932 + logger.info("Third login json data2:", data2);
  933 + if (data2.access_token) {
  934 + var scopes = data2.scope.split(",");
  935 + passport.user.token = data2.access_token;
  936 + passport.user.refreshToken = data2.refresh_token;
  937 + passport.user.user_info = data2.user || {};
  938 + passport.user.tenant_info = data2.tenant;
  939 + passport.user.customer_info = data2.customer;
  940 + passport.user.user_info.perms = data2.perms;
  941 + passport.user.type = data2.user.type;
  942 + passport.user.real_auth_status =
  943 + data2.user.real_auth_status;
  944 + passport.user.credential_status =
  945 + data2.user.credential_status;
  946 + passport.user.user_info.scope = scopes[0];
  947 + passport.user.user_info.tenant = data2.tenant;
  948 + passport.user.user_info.user = {
  949 + credential_status: data2.credential_status,
  950 + id: data2.id,
  951 + is_root: data2.is_root,
  952 + mobile: data2.mobile,
  953 + name: data2.name,
  954 + real_auth_status: data2.real_auth_status,
  955 + status: data2.status,
  956 + type: data2.type,
  957 + wx_open_id: data2.wx_open_id,
  958 + };
  959 + callback(null, data2);
  960 + } else {
  961 + var err = new Error("Third login err");
  962 + passport.user.err = data2.message;
  963 + callback(err, data2);
  964 + }
  965 + })
  966 + .on("error", function (err, response) {
  967 + logger.error("Third login error", err);
  968 + var err = new Error("Third login err");
  969 + callback(err, response);
  970 + })
  971 + .on("fail", function (data2, response) {
  972 + logger.error("Third login fail", data2);
  973 + callback(data2, response);
  974 + });
  975 + } else if (data && data.length > 1) {
  976 + // #/login/choose-tenant
  977 + callback(null, data);
  978 + } else {
  979 + var err = new Error("Third login tenants list item error");
  980 + callback(err, data);
  981 + }
  982 + },
  983 + ],
  984 + function (err, result) {
  985 + if (err) {
  986 + //登陆失败跳转失败页
  987 + res.render("loginerr", { err: err });
  988 + } else if (result instanceof Array && result.length > 1) {
  989 + //登陆成功跳转选择机构页
  990 + req.session.passport = passport;
  991 + req.session.save(function () {
  992 + res.redirect(301, settings.prefix + "#login/choose-tenant");
  993 + });
  994 + } else {
  995 + req.session.passport = passport;
  996 + req.session.save(function () {
  997 + rest.get({
  998 + baseUrl: "url",
  999 + url:
  1000 + settings.restful.url +
  1001 + "uaa" +
  1002 + settings.restful.version +
  1003 + "/perms/detail",
  1004 + useUrl: true,
  1005 + params: {},
  1006 + callback: _scb,
  1007 + req: req,
  1008 + res: res,
  1009 + options: {},
  1010 + });
  1011 + });
  1012 + function _scb(data1, response) {
  1013 + if (response.statusCode < 300 && data1.items) {
  1014 + req.session.passport.user.user_info.perms = data1.items;
  1015 + req.session.save(function () {
  1016 + if (params.redirect_page) {
  1017 + res.redirect(
  1018 + 301,
  1019 + settings.prefix + "#" + params.redirect_page
  1020 + ); //登陆成功跳转首页
  1021 + } else {
  1022 + res.redirect(301, settings.prefix + "#container/home"); //登陆成功跳转首页
  1023 + }
  1024 + });
  1025 + } else {
  1026 + if (params.redirect_page) {
  1027 + res.redirect(
  1028 + 301,
  1029 + settings.prefix + "#" + params.redirect_page
  1030 + ); //登陆成功跳转首页
  1031 + } else {
  1032 + res.redirect(301, settings.prefix + "#container/home"); //登陆成功跳转首页
  1033 + }
  1034 + }
  1035 + }
  1036 + }
  1037 + }
  1038 + );
  1039 + }
  1040 + }
  1041 +
  1042 + function getTastLink(req, res) {
  1043 + var url = crypto.createHash("md5").update(req.body.id).digest("hex");
  1044 + if (settings.prefix && settings.prefix.length > 1) {
  1045 + res.send(
  1046 + req.protocol +
  1047 + "://" +
  1048 + req.get("host") +
  1049 + settings.prefix.substring(0, settings.prefix.length - 1) +
  1050 + "/socialwork/freedom-jobs/emps/" +
  1051 + req.body.id +
  1052 + "/" +
  1053 + url
  1054 + );
  1055 + } else {
  1056 + res.send({
  1057 + url:
  1058 + req.protocol +
  1059 + "://" +
  1060 + req.get("host") +
  1061 + "/socialwork/freedom-jobs/emps/" +
  1062 + req.body.id +
  1063 + "/" +
  1064 + url,
  1065 + });
  1066 + }
  1067 + }
  1068 +
  1069 + function freedomJobsEmp(req, res) {
  1070 + var id = req.params.id;
  1071 + // var url = crypto.createHash('md5').update(id).digest('hex');
  1072 + if (false) {
  1073 + //验证未通过verification != url
  1074 + if (settings.prefix && settings.prefix.length > 1) {
  1075 + res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
  1076 + } else {
  1077 + res.redirect("/");
  1078 + }
  1079 + } else {
  1080 + //验证通过跳转,获取token存到session里
  1081 + var passport = {
  1082 + user: {
  1083 + refreshToken: "",
  1084 + token: "",
  1085 + service_catalog: {},
  1086 + user_info: {},
  1087 + err: null,
  1088 + },
  1089 + };
  1090 + var tempParams = {
  1091 + grant_type: "client_credential",
  1092 + client_id: "340161778618994688", //多宝鱼环境
  1093 + client_secret: "0f8c30aa3d15332652f62c3eaf22fdea",
  1094 + };
  1095 + rest.restful
  1096 + .postJson(settings.restful.url + "uaa/v1/auth/tokens", tempParams, {
  1097 + headers: {
  1098 + "Content-Type": "application/json",
  1099 + Accept: "application/json",
  1100 + },
  1101 + })
  1102 + .on("success", function (data) {
  1103 + if (data.access_token) {
  1104 + var scopes = data.scope.split(",");
  1105 + passport.user.token = data.access_token;
  1106 + passport.user.refreshToken = data.refresh_token;
  1107 + passport.user.user_info = data.user;
  1108 + passport.user.tenant_info = data.tenant;
  1109 + passport.user.customer_info = data.customer;
  1110 + passport.user.user_info.perms = data.perms;
  1111 + passport.user.type = data.user.type;
  1112 + passport.user.real_auth_status = data.user.real_auth_status;
  1113 + passport.user.credential_status = data.user.credential_status;
  1114 + passport.user.user_info.scope = scopes[0];
  1115 + req.session.passport = passport;
  1116 + req.session.save(function () {
  1117 + if (settings.prefix && settings.prefix.length > 1) {
  1118 + res.redirect(
  1119 + 301,
  1120 + settings.prefix.substring(0, settings.prefix.length - 1) +
  1121 + "/#task_assign/" +
  1122 + id
  1123 + );
  1124 + } else {
  1125 + res.redirect(301, "/#task_assign/" + id);
  1126 + }
  1127 + });
  1128 + } else {
  1129 + passport.user.err = data.message;
  1130 + }
  1131 + })
  1132 + .on("error", function (err, response) {
  1133 + logger.error("Third login error", err);
  1134 + var err = new Error("Third login err");
  1135 + callback(err, response);
  1136 + })
  1137 + .on("fail", function (data) {
  1138 + logger.error("Third login fail", data);
  1139 + });
  1140 + }
  1141 + }
  1142 +
  1143 + function getShortToken(req, res) {
  1144 + var params = {
  1145 + grant_type: "refresh_token",
  1146 + scope: req.session.passport.user.scope,
  1147 + refresh_token: req.session.passport.user.refreshToken,
  1148 + };
  1149 + logger.info("getShortToken:", params);
  1150 + rest.postJson({
  1151 + baseUrl: "url",
  1152 + url:
  1153 + settings.restful.url +
  1154 + "uaa" +
  1155 + settings.restful.version +
  1156 + "/auth/tokens",
  1157 + useUrl: true,
  1158 + params: params,
  1159 + callback: _cb,
  1160 + req: req,
  1161 + res: res,
  1162 + options: {},
  1163 + excludeToken: true,
  1164 + });
  1165 + function _cb(data, response) {
  1166 + console.log(data);
  1167 + logger.info("back data:", data);
  1168 + res.send({ code: response.statusCode, access_token: data.access_token });
  1169 + }
  1170 + }
  1171 +
  1172 + return {
  1173 + index: index,
  1174 + indexPrefix,
  1175 + register: register,
  1176 + signIn: signIn,
  1177 + doLogin: doLogin,
  1178 + signOut: signOut,
  1179 + smsCodes: smsCodes,
  1180 + tenants: tenants,
  1181 + productDes: productDes,
  1182 + resetPass: resetPass,
  1183 + updatePassword: updatePassword,
  1184 + loadUserInfo: loadUserInfo,
  1185 + getUploaderToken: getUploaderToken,
  1186 + getObjectTokenByID,
  1187 + delOSSObject: delOSSObject,
  1188 + healthMonitor,
  1189 + smsVerification,
  1190 + updateUserRoles,
  1191 + getRoles,
  1192 + getUserRoles,
  1193 + getTenant,
  1194 + updateTenant,
  1195 + offer,
  1196 + onboardStatus,
  1197 + dowloadApp,
  1198 + mobileRegister,
  1199 + mobileRegisterSuccess,
  1200 + softwareLicense,
  1201 + recharge,
  1202 + changePassForRegister,
  1203 + changeTenant,
  1204 + sendRejectOffer,
  1205 + acceptOffer,
  1206 + imTokens,
  1207 + listChannels,
  1208 + filemeta,
  1209 + getCustomerQrcode,
  1210 + getPositionQrcode,
  1211 + getOSSConfig,
  1212 + weidianTempLate,
  1213 + workaiSecurityOAuth,
  1214 + getTastLink,
  1215 + freedomJobsEmp,
  1216 + getShortToken,
  1217 + };
  1218 +};
  1219 +
  1220 +exports["@singleton"] = true;
  1221 +exports["@require"] = ["igloo/logger", "utils/rest", "igloo/settings"];
... ...
  1 +var urlencode = require('urlencode');
  2 +var passport = require('passport');
  3 +
  4 +exports=module.exports=function(logger,rest,settings){
  5 + function encodeUrl(url){
  6 + return urlencode(url);
  7 + }
  8 +
  9 + function encodePamars(params){
  10 + var temp=[];
  11 + for(var i=0;i<params.length;i++){
  12 + var param=params[i];
  13 + var tempParam=param.split("=")
  14 + tempParam[1]=urlencode.decode(tempParam[1], 'utf8');
  15 + tempParam[1]=tempParam[1].replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  16 + console.log(tempParam[1]);
  17 + if(i<(params.length-1)){
  18 + if(/[:&+/?%#=]/g.test(tempParam[1])){
  19 + temp.push(tempParam[0]+"="+encodeUrl(tempParam[1])+"&");
  20 + }else{
  21 + temp.push(tempParam[0]+"="+tempParam[1]+"&");
  22 + }
  23 + }else{
  24 + if(/[:&+/?%#=]/g.test(tempParam[1])){
  25 + temp.push(tempParam[0]+"="+encodeUrl(tempParam[1]));
  26 + }else{
  27 + temp.push(tempParam[0]+"="+tempParam[1]);
  28 + }
  29 + }
  30 + }
  31 + return temp.join("");
  32 + }
  33 +
  34 + function handlePamars(url){
  35 + var tempUrl=url;
  36 + // if(url.indexOf("?")!=-1){
  37 + // var temp=url.split("?");
  38 + // var params="";
  39 + // if(temp[1]&&temp[1].indexOf("&")!=-1){
  40 + // params=encodePamars(temp[1].split("&"));
  41 + // }else{
  42 + // params=encodePamars([temp[1]]);
  43 + // }
  44 + // return temp[0]+"?"+params;
  45 + // }else {
  46 + // return tempUrl;
  47 + // }
  48 + return tempUrl;
  49 + }
  50 +
  51 + function splitServiceFromUrl(url){
  52 + var catalog=url.substring(1,url.indexOf('/',1));
  53 + var pathUrl=url.substring(url.indexOf('/',1));
  54 + var fullPath=settings.restful.url+catalog+settings.restful.version+pathUrl;
  55 + return fullPath
  56 + }
  57 +
  58 + function splitUrl(fullUrl){
  59 + if(settings.prefix&&settings.prefix.length>1){
  60 + fullUrl=fullUrl.substring(settings.prefix.length-1);
  61 + }
  62 + var url=fullUrl.substring(9);
  63 + return url;
  64 + }
  65 +
  66 + function searchService(services,name){
  67 + if(services[name]){
  68 + console.log(services[name]);
  69 + return false;
  70 + }else{
  71 + return true;
  72 + }
  73 + }
  74 +
  75 + function checkReq(req,res){
  76 + var flag=true;
  77 + // if(flag&&req.headers&&!req.headers['service-catalog']){
  78 + // res.status(400);
  79 + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"});
  80 + // flag=false;
  81 + // }
  82 + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){
  83 + // res.status(404);
  84 + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"});
  85 + // flag=false;
  86 + // }
  87 + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){
  88 + // res.status(404);
  89 + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"});
  90 + // flag=false;
  91 + // }
  92 + return flag;
  93 + }
  94 +
  95 + function checkJson(req){
  96 + if(req.headers&&req.headers['content-type']=='application/json'){
  97 + return true;
  98 + }else{
  99 + return false;
  100 + }
  101 + }
  102 +
  103 + function get(req,res,next){
  104 + var url=splitUrl(req.originalUrl);
  105 + url=handlePamars(url);
  106 + url=splitServiceFromUrl(url);
  107 + if(checkReq(req,res)){
  108 + var options={
  109 + 'service_catalog':'',
  110 + 'url': url,
  111 + 'useUrl':true,
  112 + 'params':req.body,
  113 + 'callback':_cb,
  114 + 'req':req,
  115 + 'res':res,
  116 + 'options':{},
  117 + 'excludeToken':true
  118 + };
  119 + // if(checkJson(req)){
  120 + // rest.json(options);
  121 + // }else{
  122 + // rest.get(options);
  123 + // }
  124 + rest.get(options);
  125 + }
  126 + function _cb(data,response){
  127 + logger.info('back data:',data);
  128 + if(response.statusCode<300&&!data){
  129 + res.send({
  130 + code:200,
  131 + message:'操作成功!'
  132 + });
  133 + }else {
  134 + res.send(data);
  135 + }
  136 + }
  137 + }
  138 +
  139 + function post(req,res,next){
  140 + var url=splitUrl(req.originalUrl);
  141 + url=splitServiceFromUrl(url);
  142 + if(checkReq(req,res)){
  143 + var options={
  144 + 'service_catalog':'',
  145 + 'url': url,
  146 + 'useUrl':true,
  147 + 'params':req.body,
  148 + 'callback':_cb,
  149 + 'req':req,
  150 + 'res':res,
  151 + 'options':{},
  152 + 'excludeToken':true
  153 + };
  154 + if(checkJson(req)){
  155 + rest.postJson(options);
  156 + }else{
  157 + rest.post(options);
  158 + }
  159 + }
  160 + function _cb(data,response){
  161 + logger.info('back data:',data);
  162 + if(response.statusCode<300&&!data){
  163 + res.send({
  164 + code:200,
  165 + message:'操作成功!'
  166 + });
  167 + }else{
  168 + res.send(data);
  169 + }
  170 + }
  171 + }
  172 +
  173 + function put(req,res,next){
  174 + var url=splitUrl(req.originalUrl);
  175 + url=splitServiceFromUrl(url);
  176 + if(checkReq(req,res)){
  177 + var options={
  178 + 'service_catalog':'',
  179 + 'url':url,
  180 + 'useUrl':true,
  181 + 'params':req.body,
  182 + 'callback':_cb,
  183 + 'req':req,
  184 + 'res':res,
  185 + 'options':{},
  186 + 'excludeToken':true
  187 + };
  188 + if(checkJson(req)){
  189 + rest.putJson(options);
  190 + }else{
  191 + rest.put(options);
  192 + }
  193 + }
  194 + function _cb(data,response){
  195 + logger.info('back data:',data);
  196 + if(response.statusCode<300&&!data){
  197 + res.send({
  198 + code:200,
  199 + message:'操作成功!'
  200 + });
  201 + }else{
  202 + res.send(data);
  203 + }
  204 + }
  205 + }
  206 +
  207 + function patch(req,res,next){
  208 + var url=splitUrl(req.originalUrl);
  209 + url=splitServiceFromUrl(url);
  210 + if(checkReq(req,res)){
  211 + var options={
  212 + 'service_catalog':'',
  213 + 'url': url,
  214 + 'useUrl':true,
  215 + 'params':req.body,
  216 + 'callback':_cb,
  217 + 'req':req,
  218 + 'res':res,
  219 + 'options':{},
  220 + 'excludeToken':true
  221 + };
  222 + if(checkJson(req)){
  223 + rest.patchJson(options);
  224 + }else{
  225 + rest.patch(options);
  226 + }
  227 + }
  228 + function _cb(data,response){
  229 + logger.info('back data:',data);
  230 + res.send(data);
  231 + }
  232 + }
  233 +
  234 + function head(req,res,next){
  235 + var url=splitUrl(req.originalUrl);
  236 + url=splitServiceFromUrl(url);
  237 + if(checkReq(req,res)){
  238 + var options={
  239 + 'service_catalog':'',
  240 + 'url': url,
  241 + 'useUrl':true,
  242 + 'params':req.body,
  243 + 'callback':_cb,
  244 + 'req':req,
  245 + 'res':res,
  246 + 'options':{},
  247 + 'excludeToken':true
  248 + };
  249 + rest.get(options);
  250 + }
  251 + function _cb(data,response){
  252 + logger.info('back data:',data);
  253 + res.send(data);
  254 + }
  255 + }
  256 +
  257 + function del(req,res,next){
  258 + var url=splitUrl(req.originalUrl);
  259 + url=splitServiceFromUrl(url);
  260 + if(checkReq(req,res)){
  261 + var options={
  262 + 'service_catalog':'',
  263 + 'url': url,
  264 + 'useUrl':true,
  265 + 'params':req.body,
  266 + 'callback':_cb,
  267 + 'req':req,
  268 + 'res':res,
  269 + 'options':{},
  270 + 'excludeToken':true
  271 + };
  272 + rest.del(options);
  273 + }
  274 + function _cb(data,response){
  275 + logger.info('back data:',data);
  276 + if(response.statusCode<300){
  277 + res.send({'action':'delete',"message":"删除成功"});
  278 + }else{
  279 + res.send(data);
  280 + }
  281 + }
  282 + }
  283 +
  284 + function doLogin(req,res,next){
  285 + passport.authenticate('local', function(err, user, info) {
  286 + if (err) { return next(err); }
  287 + if (!user) { return res.send({'error':'用户名或密码错误!'}); }
  288 + req.logIn(user, function(err) {
  289 + if (err) { return next(err); }
  290 + return res.send({'ok':'登录成功',user_info:req.session.passport.user.user_info});
  291 + });
  292 + })(req, res, next);
  293 + }
  294 +
  295 + return {
  296 + 'get':get,
  297 + 'post':post,
  298 + 'put':put,
  299 + 'patch':patch,
  300 + 'head':head,
  301 + 'delete':del
  302 + };
  303 +};
  304 +
  305 +exports['@singleton']=true;
  306 +exports['@require']=['igloo/logger','utils/rest','igloo/settings'];
... ...
  1 +var urlencode = require('urlencode');
  2 +exports=module.exports=function(logger,rest,settings){
  3 + function encodeUrl(url){
  4 + return urlencode(url);
  5 + }
  6 +
  7 + function encodePamars(params){
  8 + var temp=[];
  9 + for(var i=0;i<params.length;i++){
  10 + var param=params[i];
  11 + var tempParam=param.split("=")
  12 + tempParam[1]=urlencode.decode(tempParam[1], 'utf8');
  13 + tempParam[1]=tempParam[1].replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  14 + console.log(tempParam[1]);
  15 + if(i<(params.length-1)){
  16 + if(/[:&+/?%#=]/g.test(tempParam[1])){
  17 + temp.push(tempParam[0]+"="+encodeUrl(tempParam[1])+"&");
  18 + }else{
  19 + temp.push(tempParam[0]+"="+tempParam[1]+"&");
  20 + }
  21 + }else{
  22 + if(/[:&+/?%#=]/g.test(tempParam[1])){
  23 + temp.push(tempParam[0]+"="+encodeUrl(tempParam[1]));
  24 + }else{
  25 + temp.push(tempParam[0]+"="+tempParam[1]);
  26 + }
  27 + }
  28 + }
  29 + return temp.join("");
  30 + }
  31 +
  32 + function handlePamars(url){
  33 + var tempUrl=url;
  34 + // if(url.indexOf("?")!=-1){
  35 + // var temp=url.split("?");
  36 + // var params="";
  37 + // if(temp[1]&&temp[1].indexOf("&")!=-1){
  38 + // params=encodePamars(temp[1].split("&"));
  39 + // }else{
  40 + // params=encodePamars([temp[1]]);
  41 + // }
  42 + // return temp[0]+"?"+params;
  43 + // }else {
  44 + // return tempUrl;
  45 + // }
  46 + return tempUrl;
  47 + }
  48 +
  49 + function splitServiceFromUrl(url){
  50 + var catalog=url.substring(1,url.indexOf('/',1));
  51 + var pathUrl=url.substring(url.indexOf('/',1));
  52 + var fullPath=settings.restful.url+catalog+settings.restful.version+pathUrl;
  53 + if(pathUrl&&pathUrl.indexOf('inits')!=-1){
  54 + fullPath=settings.restful.url+catalog+'/v2'+pathUrl;
  55 + }
  56 + return fullPath
  57 + }
  58 +
  59 + function splitUrl(fullUrl){
  60 + if(settings.prefix&&settings.prefix.length>1){
  61 + fullUrl=fullUrl.substring(settings.prefix.length-1);
  62 + }
  63 + var url=fullUrl.substring(9);
  64 + return url;
  65 + }
  66 +
  67 + function searchService(services,name){
  68 + if(services[name]){
  69 + console.log(services[name]);
  70 + return false;
  71 + }else{
  72 + return true;
  73 + }
  74 + }
  75 +
  76 + function checkReq(req,res){
  77 + var flag=true;
  78 + // if(flag&&req.headers&&!req.headers['service-catalog']){
  79 + // res.status(400);
  80 + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"});
  81 + // flag=false;
  82 + // }
  83 + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){
  84 + // res.status(404);
  85 + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"});
  86 + // flag=false;
  87 + // }
  88 + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){
  89 + // res.status(404);
  90 + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"});
  91 + // flag=false;
  92 + // }
  93 + return flag;
  94 + }
  95 +
  96 + function checkJson(req){
  97 + if(req.headers&&req.headers['content-type']=='application/json'){
  98 + return true;
  99 + }else{
  100 + return false;
  101 + }
  102 + }
  103 +
  104 + function get(req,res,next){
  105 + var url=splitUrl(req.originalUrl);
  106 + url=handlePamars(url);
  107 + url=splitServiceFromUrl(url);
  108 + if(checkReq(req,res)){
  109 + var options={
  110 + 'service_catalog':'',
  111 + 'url':url,
  112 + 'useUrl':true,
  113 + 'params':req.body,
  114 + 'callback':_cb,
  115 + 'req':req,
  116 + 'res':res,
  117 + 'options':{}
  118 + };
  119 + rest.get(options);
  120 + }
  121 + function _cb(data,response){
  122 + logger.info('back data:',data);
  123 + if(response.statusCode<300&&!data){
  124 + res.send({
  125 + code:200,
  126 + message:'操作成功!'
  127 + });
  128 + }else {
  129 + res.send(data);
  130 + }
  131 + }
  132 + }
  133 +
  134 + function post(req,res,next){
  135 + var url=splitUrl(req.originalUrl);
  136 + url=splitServiceFromUrl(url);
  137 + if(checkReq(req,res)){
  138 + var options={
  139 + 'service_catalog':'services[catalog].public_endpoint',
  140 + 'url':url,
  141 + 'useUrl':true,
  142 + 'params':req.body,
  143 + 'callback':_cb,
  144 + 'req':req,
  145 + 'res':res,
  146 + 'options':{}
  147 + };
  148 + if(checkJson(req)){
  149 + rest.postJson(options);
  150 + }else{
  151 + rest.post(options);
  152 + }
  153 + }
  154 + function _cb(data,response){
  155 + logger.info('back data:',data);
  156 + if(response.statusCode<300&&!data){
  157 + res.send({
  158 + code:200,
  159 + message:'操作成功!'
  160 + });
  161 + }else{
  162 + res.send(data);
  163 + }
  164 + }
  165 + }
  166 +
  167 + function put(req,res,next){
  168 + var url=splitUrl(req.originalUrl);
  169 + url=splitServiceFromUrl(url);
  170 + if(checkReq(req,res)){
  171 + var options={
  172 + 'service_catalog':'services[catalog].public_endpoint',
  173 + 'url': url,
  174 + 'useUrl':true,
  175 + 'params':req.body,
  176 + 'callback':_cb,
  177 + 'req':req,
  178 + 'res':res,
  179 + 'options':{}
  180 + };
  181 + if(checkJson(req)){
  182 + rest.putJson(options);
  183 + }else{
  184 + rest.put(options);
  185 + }
  186 + }
  187 + function _cb(data,response){
  188 + logger.info('back data:',data);
  189 + if(response.statusCode<300&&!data){
  190 + res.send({
  191 + code:200,
  192 + message:'操作成功!'
  193 + });
  194 + }else{
  195 + res.send(data);
  196 + }
  197 + }
  198 + }
  199 +
  200 + function patch(req,res,next){
  201 + var url=splitUrl(req.originalUrl);
  202 + url=splitServiceFromUrl(url);
  203 + if(checkReq(req,res)){
  204 + var options={
  205 + 'service_catalog':'services[catalog].public_endpoint',
  206 + 'url': url,
  207 + 'useUrl':true,
  208 + 'params':req.body,
  209 + 'callback':_cb,
  210 + 'req':req,
  211 + 'res':res,
  212 + 'options':{}
  213 + };
  214 + if(checkJson(req)){
  215 + rest.patchJson(options);
  216 + }else{
  217 + rest.patch(options);
  218 + }
  219 + }
  220 + function _cb(data,response){
  221 + logger.info('back data:',data);
  222 + res.send(data);
  223 + }
  224 + }
  225 +
  226 + function head(req,res,next){
  227 + var url=splitUrl(req.originalUrl);
  228 + url=splitServiceFromUrl(url);
  229 + if(checkReq(req,res)){
  230 + var options={
  231 + 'service_catalog':'services[catalog].public_endpoint',
  232 + 'url': url,
  233 + 'useUrl':true,
  234 + 'params':req.body,
  235 + 'callback':_cb,
  236 + 'req':req,
  237 + 'res':res,
  238 + 'options':{}
  239 + };
  240 + rest.get(options);
  241 + }
  242 + function _cb(data,response){
  243 + logger.info('back data:',data);
  244 + res.send(data);
  245 + }
  246 + }
  247 +
  248 + function del(req,res,next){
  249 + var url=splitUrl(req.originalUrl);
  250 + url=splitServiceFromUrl(url);
  251 + if(checkReq(req,res)){
  252 + var options={
  253 + 'service_catalog':'services[catalog].public_endpoint',
  254 + 'url': url,
  255 + 'useUrl':true,
  256 + 'params':req.body,
  257 + 'callback':_cb,
  258 + 'req':req,
  259 + 'res':res,
  260 + 'options':{}
  261 + };
  262 + rest.del(options);
  263 + }
  264 + function _cb(data,response){
  265 + logger.info('back data:',data);
  266 + if(response.statusCode<300){
  267 + res.send({'action':'delete',"message":"删除成功"});
  268 + }else{
  269 + res.send(data);
  270 + }
  271 + }
  272 + }
  273 +
  274 + return {
  275 + 'get':get,
  276 + 'post':post,
  277 + 'put':put,
  278 + 'patch':patch,
  279 + 'head':head,
  280 + 'delete':del
  281 + };
  282 +};
  283 +
  284 +exports['@singleton']=true;
  285 +exports['@require']=['igloo/logger','utils/rest','igloo/settings'];
... ...
  1 +var urlencode = require('urlencode');
  2 +var mockData = require('../json/mockDate.json');
  3 +exports=module.exports=function(logger,rest,settings){
  4 +
  5 + function getJson(url,method){
  6 + var backData={};
  7 + for(var i=0;i<mockData.length;i++){
  8 + var urlRegex=new RegExp(mockData[i].url,'g');
  9 + if(urlRegex.test(url)){
  10 + backData=mockData[i][method+'_data'];
  11 + return backData;
  12 + }
  13 + }
  14 + return backData;
  15 + }
  16 +
  17 + function get(req,res,next){
  18 + console.log(req.path);
  19 + res.send(getJson(req.path,'get'));
  20 + }
  21 +
  22 + function post(req,res,next){
  23 + console.log(req.path);
  24 + res.send(getJson(req.path,'post'));
  25 + }
  26 +
  27 + function put(req,res,next){
  28 + console.log(req.path);
  29 + res.send(getJson(req.path,'put'));
  30 + }
  31 +
  32 + function patch(req,res,next){
  33 + console.log(req.path);
  34 + res.send(getJson(req.path,'patch'));
  35 + }
  36 +
  37 + function head(req,res,next){
  38 + console.log(req.path);
  39 + res.send(getJson(req.path,'head'));
  40 + }
  41 +
  42 + function del(req,res,next){
  43 + console.log(req.path);
  44 + res.send(getJson(req.path,'del'));
  45 + }
  46 +
  47 + return {
  48 + 'get':get,
  49 + 'post':post,
  50 + 'put':put,
  51 + 'patch':patch,
  52 + 'head':head,
  53 + 'delete':del
  54 + };
  55 +};
  56 +
  57 +exports['@singleton']=true;
  58 +exports['@require']=['igloo/logger','utils/rest','igloo/settings'];
... ...
  1 +var urlencode= require('urlencode');
  2 +
  3 +exports=module.exports=function(logger,rest,settings){
  4 + var api_service_endpoint = 'http://47.98.198.227:59000/v1';
  5 +
  6 + function index(req,res,next){
  7 + logger.info(req.user);
  8 + res.render('robotMobile',{title:'外呼机器人'});
  9 + }
  10 +
  11 + function splitUrl(fullUrl){
  12 + if(settings.prefix&&settings.prefix.length>1){
  13 + fullUrl=fullUrl.substring(settings.prefix.length-1);
  14 + }
  15 + var url=fullUrl.substring(9);
  16 + return url;
  17 + }
  18 +
  19 + function get(req,res,next){
  20 + var url=splitUrl(req.originalUrl);
  21 + rest.get({
  22 + 'baseUrl':'url',
  23 + 'url':api_service_endpoint+url,
  24 + 'useUrl':true,
  25 + 'params':req.body,
  26 + 'callback':_cb,
  27 + 'req':req,
  28 + 'res':res,
  29 + 'options':{},
  30 + 'excludeToken':true
  31 + });
  32 + function _cb(data,response){
  33 + console.log(data);
  34 + res.send(data);
  35 + }
  36 + // res.send({
  37 + // "total_count":20,
  38 + // "items":[{
  39 + // "id":'001',
  40 + // "call_out_number":'18501068035',
  41 + // "call_out_time":2022222,
  42 + // "status":"4",
  43 + // "record_url":'xxxx'
  44 + // }]
  45 + // })
  46 + }
  47 +
  48 + function post(req,res,next){
  49 + var url=splitUrl(req.originalUrl);
  50 + rest.postJson({
  51 + 'baseUrl':'url',
  52 + 'url':api_service_endpoint+url,
  53 + 'useUrl':true,
  54 + 'params':req.body,
  55 + 'callback':_cb,
  56 + 'req':req,
  57 + 'res':res,
  58 + 'options':{},
  59 + 'excludeToken':true
  60 + });
  61 + function _cb(data,response){
  62 + console.log(data);
  63 + res.send(data);
  64 + }
  65 + }
  66 +
  67 + function put(req,res,next){
  68 + var url=splitUrl(req.originalUrl);
  69 + rest.putJson({
  70 + 'baseUrl':'url',
  71 + 'url':api_service_endpoint+url,
  72 + 'useUrl':true,
  73 + 'params':req.body,
  74 + 'callback':_cb,
  75 + 'req':req,
  76 + 'res':res,
  77 + 'options':{},
  78 + 'excludeToken':true
  79 + });
  80 + function _cb(data,response){
  81 + res.send(data);
  82 + }
  83 + }
  84 +
  85 + function patch(req,res,next){
  86 + var url=splitUrl(req.originalUrl);
  87 + rest.patchJson({
  88 + 'baseUrl':'url',
  89 + 'url':api_service_endpoint+url,
  90 + 'useUrl':true,
  91 + 'params':req.body,
  92 + 'callback':_cb,
  93 + 'req':req,
  94 + 'res':res,
  95 + 'options':{},
  96 + 'excludeToken':true
  97 + });
  98 + function _cb(data,response){
  99 + res.send(data);
  100 + }
  101 + }
  102 +
  103 + function head(req,res,next){
  104 + var url=splitUrl(req.originalUrl);
  105 + rest.get({
  106 + 'baseUrl':'url',
  107 + 'url':api_service_endpoint+url,
  108 + 'useUrl':true,
  109 + 'params':req.body,
  110 + 'callback':_cb,
  111 + 'req':req,
  112 + 'res':res,
  113 + 'options':{},
  114 + 'excludeToken':true
  115 + });
  116 + function _cb(data,response){
  117 + res.send(data);
  118 + }
  119 + }
  120 +
  121 + function del(req,res,next){
  122 + var url=splitUrl(req.originalUrl);
  123 + rest.del({
  124 + 'baseUrl':'url',
  125 + 'url':api_service_endpoint+url,
  126 + 'useUrl':true,
  127 + 'params':req.body,
  128 + 'callback':_cb,
  129 + 'req':req,
  130 + 'res':res,
  131 + 'options':{},
  132 + 'excludeToken':true
  133 + });
  134 + function _cb(data,response){
  135 + res.send(data);
  136 + }
  137 + }
  138 +
  139 + return {
  140 + 'index':index,
  141 + 'get':get,
  142 + 'post':post,
  143 + 'put':put,
  144 + 'patch':patch,
  145 + 'head':head,
  146 + 'delete':del
  147 + };
  148 +};
  149 +
  150 +exports['@singleton']=true;
  151 +exports['@require']=['igloo/logger','utils/rest','igloo/settings'];
... ...
  1 +
  2 +// # settings
  3 +
  4 +var compress = require('compression');
  5 +var https = require('https');
  6 +var http = require('http');
  7 +
  8 +exports = module.exports = function(IoC, settings) {
  9 +
  10 + var app = this;
  11 +
  12 + // set the environment
  13 + app.set('env', settings.server.env);
  14 +
  15 + // set the default views directory
  16 + // app.set('views', settings.views.dir);
  17 +
  18 + // set the default view engine
  19 + // app.set('view engine', settings.views.engine);
  20 +
  21 +
  22 +
  23 + if (settings.server.env === 'development') {
  24 +
  25 + // make view engine output pretty
  26 + app.locals.pretty = true;
  27 +
  28 + }
  29 +
  30 + if (settings.server.env === 'production') {
  31 +
  32 + // enable view caching
  33 + // app.enable('view cache');
  34 +
  35 + // compress response data with gzip/deflate
  36 + // this overwrites res.write and res.end functions
  37 + app.use(compress());
  38 +
  39 + }
  40 +
  41 + if (settings.server.ssl.enabled) {
  42 + this.server = https.createServer(settings.server.ssl.options, this);
  43 + } else {
  44 + this.server = http.createServer(this);
  45 + }
  46 +
  47 +};
  48 +
  49 +exports['@require'] = [ '$container', 'igloo/settings' ];
... ...
  1 +
  2 +// # middleware
  3 +
  4 +
  5 +var serveFavicon = require('serve-favicon');
  6 +var path = require('path');
  7 +var winstonRequestLogger = require('winston-request-logger');
  8 +var methodOverride = require('method-override');
  9 +var bodyParser = require('body-parser');
  10 +var responseTime = require('response-time');
  11 +// var busboy = require('connect-busboy');
  12 +
  13 +
  14 +exports = module.exports = function (IoC, logger, settings, policies) {
  15 +
  16 + var app = this;
  17 +
  18 + // ignore GET /favicon.ico
  19 + // app.use(serveFavicon(path.join(settings.publicDir, 'favicon.ico')));
  20 +
  21 + if (settings.server.env === 'development') {
  22 +
  23 + }
  24 +
  25 + // static server (always keep this first)
  26 + // <http://goo.gl/j2BEl5>
  27 +
  28 + // adds X-Response-Time header
  29 + app.use(responseTime({
  30 + digits: 5
  31 + }));
  32 +
  33 + // prepare req.log for error handler
  34 + app.use(function (req, res, next) {
  35 + req.log = {
  36 + response_time: new Date().getTime(),
  37 + path: req.path,
  38 + query: req.query,
  39 + body: req.body,
  40 + params: req.params
  41 + };
  42 + next();
  43 + });
  44 +
  45 + app.use((req, res, next) => {//跨域OPTIONS
  46 + if (req.path !== '/' && !req.path.includes('.')) {
  47 + res.set({
  48 + 'Access-Control-Allow-Credentials': true, //允许后端发送cookie
  49 + 'Access-Control-Allow-Origin': req.headers.origin || '*', //任意域名都可以访问,或者基于我请求头里面的域
  50 + 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', //设置请求头格式和类型
  51 + 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',//允许支持的请求方式
  52 + 'Content-Type': 'application/json; charset=utf-8',//默认与允许的文本格式json和编码格式
  53 + });
  54 + }
  55 + req.method === 'OPTIONS' ? res.status(204).end() : next();
  56 + });
  57 +
  58 + if (settings.server.env === 'production') {//production 生产环境
  59 + app.use((req, res, next) => {
  60 + //script-src: 外部脚本
  61 + //style-src: 样式表
  62 + //img-src: 图像
  63 + //media-src: 媒体文件(音频和视频)
  64 + //font-src: 字体文件
  65 + //object-src: 插件(比如:flash)
  66 + //child-src: 框架
  67 + //frame-ancestor: 嵌入的外部资源(比如:<frame> <iframe> <embed> <appled>)
  68 + //connect-src: http链接(通过XHR、WebSockets、EventSource等)
  69 + //worker-src: worker脚本
  70 + //manifest-src: manifest文件
  71 + let other_origins = [
  72 + 'cdn.ronghub.com',
  73 + 'at.alicdn.com',
  74 + 'gosspublic.alicdn.com',
  75 + 'webapi.amap.com',
  76 + 's22.cnzz.com',
  77 + ];
  78 + const getKeys = () => {
  79 +
  80 + let str = [], base_str = "'self' " + other_origins.join(' ') + " https: http: filesystem: blob:";
  81 + let obj = {
  82 + 'child-src': base_str,
  83 + 'connect-src': base_str,
  84 + 'font-src': base_str + " data:",
  85 + 'frame-src': base_str + " data:",
  86 + 'img-src': base_str + " data:",
  87 + 'media-src': base_str + " data:",
  88 + 'object-src': base_str + " data:",
  89 + 'worker-src': base_str + " 'unsafe-inline' 'unsafe-eval'",
  90 + 'script-src': base_str + " 'unsafe-inline' 'unsafe-eval'",
  91 + 'style-src': base_str + " 'unsafe-inline'",
  92 + }
  93 +
  94 + for (var key in obj) {
  95 + str.push(key + ' ' + obj[key] + ';');
  96 + }
  97 +
  98 + return str.join('');
  99 +
  100 + }
  101 +
  102 + res.set({
  103 + 'Content-Security-Policy': "default-src 'self' https: http:;" + getKeys()
  104 + });
  105 + next();
  106 + });
  107 +
  108 + }
  109 +
  110 +
  111 + // winston request logger before everything else
  112 + // but only if it was enabled in settings
  113 + if (settings.logger.requests) {
  114 + app.use(winstonRequestLogger.create(logger));
  115 + }
  116 +
  117 + // parse request bodies
  118 + // support _method (PUT in forms etc)
  119 + app.use(
  120 + bodyParser.json({ limit: '50mb' }),
  121 + bodyParser.urlencoded({
  122 + limit: '50mb',
  123 + extended: true
  124 + }),
  125 + methodOverride('_method')
  126 + );
  127 + //support "application/x-www-formurlencoded" or starts with "multipart/*"
  128 + // app.use(busboy({
  129 + // limits: {
  130 + // fileSize: 10 * 1024 * 1024
  131 + // }
  132 + // }))
  133 +
  134 +};
  135 +
  136 +exports['@require'] = ['$container', 'igloo/logger', 'igloo/settings', 'policies'];
... ...
  1 +
  2 +// # sessions
  3 +
  4 +var flash = require('connect-flash');
  5 +var session = require('express-session');
  6 +var cookieParser = require('cookie-parser');
  7 +var passport = require('passport');
  8 +var LocalStrategy = require('passport-local').Strategy;
  9 +var validator = require('validator');
  10 +var _ = require('underscore');
  11 +
  12 +exports = module.exports = function(IoC, settings,authenticate, sessions, User, policies) {
  13 +
  14 + var app = this;
  15 + // pass a secret to cookieParser() for signed cookies
  16 + app.all(policies.notApiRouteRegexp, cookieParser(settings.cookieParser));
  17 +
  18 + // add req.session cookie support
  19 + settings.session.store = sessions;
  20 + app.all(policies.notApiRouteRegexp, session(settings.session));
  21 +
  22 +
  23 + // add flash message support
  24 + app.use(session(settings.session));
  25 + app.use(flash());
  26 + app.use(passport.initialize());
  27 + app.use(passport.session());
  28 + app.all(policies.notApiRouteRegexp, flash());
  29 +
  30 + //// add passport strategies
  31 + passport.use(new LocalStrategy(settings.localStrategy,authenticate.strategy));
  32 + passport.serializeUser(authenticate.serializeUser);
  33 + passport.deserializeUser(authenticate.deserializeUser);
  34 +
  35 +};
  36 +
  37 +exports['@require'] = [ '$container', 'igloo/settings','utils/authenticate', 'igloo/sessions', 'models/user', 'policies' ];
... ...
  1 +
  2 +// # security
  3 +
  4 +var helmet = require('helmet');
  5 +var csrf = require('csurf');
  6 +
  7 +exports = module.exports = function(IoC, settings, policies) {
  8 +
  9 + var app = this;
  10 +
  11 + // trust proxy
  12 + if (settings.trustProxy) {
  13 + app.enable('trust proxy');
  14 + }
  15 +
  16 + // use helmet for security
  17 + app.use(helmet());
  18 +
  19 + // cross site request forgery prevention (csrf)
  20 + // (disabled for /api endpoints)
  21 + if (settings.csrf.enabled) {
  22 + app.all(policies.notApiRouteRegexp, function(req, res, next) {
  23 + if (req.xhr) return next();
  24 + csrf(settings.csrf.options)(req, res, next);
  25 + });
  26 + }
  27 +
  28 +};
  29 +
  30 +exports['@require'] = [ '$container', 'igloo/settings', 'policies' ];
... ...
  1 +
  2 +// # caching
  3 +
  4 +var path = require('path');
  5 +var helmet = require('helmet');
  6 +
  7 +exports = module.exports = function(IoC, settings) {
  8 +
  9 + var app = this;
  10 +
  11 + // Disable cache if settings say so
  12 + if (!settings.cache) {
  13 + app.use(helmet.nocache());
  14 + } else {
  15 + // Enable cache if NOT an XHR (AJAX) request
  16 + app.use(function(req, res, next) {
  17 + if (req.xhr) return next();
  18 + res.setHeader('Cache-Control', 'public');
  19 + res.setHeader('Pragma', '');
  20 + res.setHeader('Expires', settings.staticServer.maxAge);
  21 + // res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
  22 + // res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
  23 + // res.setHeader("Expires", "0"); // Proxies.
  24 + next();
  25 + });
  26 + }
  27 +
  28 +};
  29 +
  30 +exports['@require'] = [ '$container', 'igloo/settings' ];
... ...
  1 +
  2 +// # views
  3 +
  4 +var moment = require('moment');
  5 +
  6 +exports = module.exports = function(IoC, settings) {
  7 +
  8 + var app = this;
  9 +
  10 + // add dynamic helpers for views
  11 + app.use(function(req, res, next) {
  12 +
  13 + res.locals.settings = settings;
  14 + res.locals.req = req;
  15 + res.locals.messages = {
  16 + success: req.flash('success'),
  17 + error: req.flash('error'),
  18 + info: req.flash('info'),
  19 + warning: req.flash('warning')
  20 + };
  21 +
  22 + res.locals.moment = moment;
  23 +
  24 + if (settings.csrf.enabled)
  25 + res.locals.csrf = req.csrfToken();
  26 +
  27 + next();
  28 +
  29 + });
  30 +
  31 +};
  32 +
  33 +exports['@require'] = [ '$container', 'igloo/settings' ];
... ...
  1 +[{
  2 + "url":"/psiorder/customer-other-fee",
  3 + "get_data":{
  4 + "total_count": 1,
  5 + "items": [
  6 + {
  7 + "id": "79287340000",
  8 + "customer": "我是客户",
  9 + "customer_id": "023984029348",
  10 + "service_contract": "我是服务合同",
  11 + "service_contract_id": "6263492374090",
  12 + "person_count": 100,
  13 + "total_amount": 5555,
  14 + "op_month": 1520309847
  15 + }
  16 + ]
  17 + }
  18 +},{
  19 + "url":"/psiorder/person-other-fee",
  20 + "get_data":{
  21 + "total_count": 1,
  22 + "items":[{
  23 + "id": "79287340000",
  24 + "name": "张三",
  25 + "id_num": "130928198007010098",
  26 + "subject": "制卡费",
  27 + "total_amount": 300,
  28 + "comment": "我是备注"
  29 + }]
  30 + },
  31 + "put_data":{
  32 + "total_count": 1,
  33 + "items": {
  34 + "id": "749283740900028",
  35 + "total_amount": 200,
  36 + "comment": "修改后的备注"
  37 + }
  38 + }
  39 +},{
  40 + "url":"/psiorder/import-other-fee",
  41 + "post_data":{
  42 + "customer_id": "2992839100001993",
  43 + "service_contract_id": "747738820019918838",
  44 + "op_month": 1520309847,
  45 + "object_path": "hro/29384029384.xls"
  46 + }
  47 +},{
  48 + "url":"/psiorder/customer-other-fee/[\\W\\w]+",
  49 + "del_data":{
  50 + "message": "成功"
  51 + }
  52 +},{
  53 + "url":"/psiorder/front-reals",
  54 + "get_data":{
  55 + "total_count": 1,
  56 + "items": [{
  57 + "customer": "我是客户",
  58 + "customer_id": "8888292910839900",
  59 + "service_contract": "我是服务合同",
  60 + "service_contract_id": "77773889200288388",
  61 + "op_month": 1520309847,
  62 + "person_count": 555,
  63 + "person_amount": 10000,
  64 + "ent_amount": 8000,
  65 + "total_amount": 18000,
  66 + "status": "normal"
  67 + }]
  68 + }
  69 +},{
  70 + "url":"/psiorder/front-real-details",
  71 + "get_data":{
  72 + "total_count": 1,
  73 + "head": {
  74 + "customer": "我是客户",
  75 + "customer_id": "8888292910839900",
  76 + "service_contract": "我是服务合同",
  77 + "service_contract_id": "77773889200288388",
  78 + "op_month": 1520309847,
  79 + "person_count": 555,
  80 + "person_amount": 10000,
  81 + "ent_amount": 8000,
  82 + "total_amount": 18000,
  83 + "status": "normal"
  84 + },
  85 + "items": [{
  86 + "name": "张三",
  87 + "id_num": "130928199008020082",
  88 + "pay_type": "正常应缴",
  89 + "ent_amount": 1000,
  90 + "person_amount": 2000,
  91 + "total_amount": 3000,
  92 + "op_type":"renew",
  93 + "status": "normal"
  94 + }]
  95 + }
  96 +},{
  97 + "url":"/psiorder/real-handle-invalid/[\\W\\w]+",
  98 + "get_data":{
  99 + "result":"SUCCESS"
  100 + }
  101 +},{
  102 + "url":"/psiorder/real/[\\W\\w]+",
  103 + "get_data":{
  104 + "id": "170636915266031616",
  105 + "pay_type": "正常应缴",
  106 + "target_type": "ent",
  107 + "target_id": "152534304117755904",
  108 + "op_type": "payback",
  109 + "target_amount": 8594.91,
  110 + "target_service_fee": 0,
  111 + "insured_name": "噗噗测试",
  112 + "insured_person_id": "170621814383316992",
  113 + "insured_mobile": "18613850761",
  114 + "id_type": "身份证",
  115 + "id_num": "123456789098765001",
  116 + "ext_info": "[]",
  117 + "pay_start_month": 1509465600,
  118 + "pay_end_month": 1512057600,
  119 + "policy_infos": [{
  120 + "person_fee": 1234.1,
  121 + "ent_fee": 1234.1,
  122 + "total_fee": 1234.1,
  123 + "id": "170636914414587904",
  124 + "policy_category": "0",
  125 + "policy_name": "林州太行山",
  126 + "hhr_type": "城镇",
  127 + "province": "河南省",
  128 + "province_code": "410000",
  129 + "city": "安阳市",
  130 + "city_code": "410500",
  131 + "district": "林州市",
  132 + "district_code": "410581",
  133 + "total_amount": 27142.84,
  134 + "insurances": [{
  135 + "id": "170636914469113856",
  136 + "base": 1000,
  137 + "pay_start_month": 1509465600,
  138 + "pay_end_month": 1512057600,
  139 + "abort_month": -62135596800,
  140 + "back_admin": "aaa",
  141 + "back_admin_id": "143359863278276608",
  142 + "back_admin_mobile": "13691224345",
  143 + "datum_check_status": "init",
  144 + "op_progress": "0",
  145 + "op_result": "init",
  146 + "next_op": "",
  147 + "insurance": "黑玉断续膏",
  148 + "account": "255668797",
  149 + "service_start_month": 1509465600,
  150 + "pay_rate": 0.4523,
  151 + "fixed_amount": 500,
  152 + "insurance_category": "3",
  153 + "total_amount": 0,
  154 + "created_at": 1515485899,
  155 + "updated_at": 1515485899,
  156 + "tenant_id": "122371433052508160",
  157 + "payback_source": "manual",
  158 + "fee_per_month": 5427.64,
  159 + "op_month": 1514736000,
  160 + "relation_payback_ids": null,
  161 + "policy_category": "0",
  162 + "insured_person_id": "170621814383316992",
  163 + "person_amount": 1379.4,
  164 + "ent_amount": 1334.42,
  165 + "person_fixed_amount": 300,
  166 + "ent_fixed_amount": 200,
  167 + "person_proportion": 0.2299,
  168 + "ent_proportion": 0.2224,
  169 + "account_company": "",
  170 + "pay_frequency": "0"
  171 + },
  172 + {
  173 + "id": "170636914569777152",
  174 + "base": 1000,
  175 + "pay_start_month": 1509465600,
  176 + "pay_end_month": 1512057600,
  177 + "abort_month": -62135596800,
  178 + "back_admin": "112",
  179 + "back_admin_id": "132861396747554816",
  180 + "back_admin_mobile": "18501689786",
  181 + "datum_check_status": "init",
  182 + "op_progress": "0",
  183 + "op_result": "init",
  184 + "next_op": "",
  185 + "insurance": "残保金",
  186 + "account": "255668797",
  187 + "service_start_month": 1509465600,
  188 + "pay_rate": 0.4523,
  189 + "fixed_amount": 500,
  190 + "insurance_category": "2",
  191 + "total_amount": 0,
  192 + "created_at": 1515485899,
  193 + "updated_at": 1515485899,
  194 + "tenant_id": "122371433052508160",
  195 + "payback_source": "manual",
  196 + "fee_per_month": 5428.8,
  197 + "op_month": 1514736000,
  198 + "relation_payback_ids": null,
  199 + "policy_category": "0",
  200 + "insured_person_id": "170621814383316992",
  201 + "person_amount": 1380,
  202 + "ent_amount": 1334.4,
  203 + "person_fixed_amount": 300,
  204 + "ent_fixed_amount": 200,
  205 + "person_proportion": 0.2299,
  206 + "ent_proportion": 0.2224,
  207 + "account_company": "",
  208 + "pay_frequency": "0"
  209 + },
  210 + {
  211 + "id": "170636914657857536",
  212 + "base": 1000,
  213 + "pay_start_month": 1509465600,
  214 + "pay_end_month": 1512057600,
  215 + "abort_month": -62135596800,
  216 + "back_admin": "aaa",
  217 + "back_admin_id": "143133151974133760",
  218 + "back_admin_mobile": "13691224345",
  219 + "datum_check_status": "init",
  220 + "op_progress": "0",
  221 + "op_result": "init",
  222 + "next_op": "",
  223 + "insurance": "医疗保险",
  224 + "account": "255668797",
  225 + "service_start_month": 1509465600,
  226 + "pay_rate": 0.4523,
  227 + "fixed_amount": 500,
  228 + "insurance_category": "0",
  229 + "total_amount": 0,
  230 + "created_at": 1515485899,
  231 + "updated_at": 1515485899,
  232 + "tenant_id": "122371433052508160",
  233 + "payback_source": "manual",
  234 + "fee_per_month": 5428.8,
  235 + "op_month": 1514736000,
  236 + "relation_payback_ids": null,
  237 + "policy_category": "0",
  238 + "insured_person_id": "170621814383316992",
  239 + "person_amount": 1380,
  240 + "ent_amount": 1334.4,
  241 + "person_fixed_amount": 300,
  242 + "ent_fixed_amount": 200,
  243 + "person_proportion": 0.2299,
  244 + "ent_proportion": 0.2224,
  245 + "account_company": "",
  246 + "pay_frequency": "0"
  247 + },
  248 + {
  249 + "id": "170636914758520832",
  250 + "base": 1000,
  251 + "pay_start_month": 1509465600,
  252 + "pay_end_month": 1512057600,
  253 + "abort_month": -62135596800,
  254 + "back_admin": "测试",
  255 + "back_admin_id": "143135306059616256",
  256 + "back_admin_mobile": "17710611692",
  257 + "datum_check_status": "init",
  258 + "op_progress": "0",
  259 + "op_result": "init",
  260 + "next_op": "",
  261 + "insurance": "养老保险",
  262 + "account": "255668797",
  263 + "service_start_month": 1509465600,
  264 + "pay_rate": 0.4523,
  265 + "fixed_amount": 500,
  266 + "insurance_category": "0",
  267 + "total_amount": 0,
  268 + "created_at": 1515485899,
  269 + "updated_at": 1515485899,
  270 + "tenant_id": "122371433052508160",
  271 + "payback_source": "manual",
  272 + "fee_per_month": 5428.8,
  273 + "op_month": 1514736000,
  274 + "relation_payback_ids": null,
  275 + "policy_category": "0",
  276 + "insured_person_id": "170621814383316992",
  277 + "person_amount": 1380,
  278 + "ent_amount": 1334.4,
  279 + "person_fixed_amount": 300,
  280 + "ent_fixed_amount": 200,
  281 + "person_proportion": 0.2299,
  282 + "ent_proportion": 0.2224,
  283 + "account_company": "",
  284 + "pay_frequency": "0"
  285 + },
  286 + {
  287 + "id": "170636914825629696",
  288 + "base": 1000,
  289 + "pay_start_month": 1509465600,
  290 + "pay_end_month": 1512057600,
  291 + "abort_month": -62135596800,
  292 + "back_admin": "东方闪电",
  293 + "back_admin_id": "143133044163743744",
  294 + "back_admin_mobile": "14350000000",
  295 + "datum_check_status": "init",
  296 + "op_progress": "0",
  297 + "op_result": "init",
  298 + "next_op": "",
  299 + "insurance": "华佗再造丸",
  300 + "account": "255668797",
  301 + "service_start_month": 1509465600,
  302 + "pay_rate": 0.4523,
  303 + "fixed_amount": 500,
  304 + "insurance_category": "1",
  305 + "total_amount": 0,
  306 + "created_at": 1515485899,
  307 + "updated_at": 1515485899,
  308 + "tenant_id": "122371433052508160",
  309 + "payback_source": "manual",
  310 + "fee_per_month": 5428.8,
  311 + "op_month": 1514736000,
  312 + "relation_payback_ids": null,
  313 + "policy_category": "0",
  314 + "insured_person_id": "170621814383316992",
  315 + "person_amount": 1380,
  316 + "ent_amount": 1334.4,
  317 + "person_fixed_amount": 300,
  318 + "ent_fixed_amount": 200,
  319 + "person_proportion": 0.2299,
  320 + "ent_proportion": 0.2224,
  321 + "account_company": "",
  322 + "pay_frequency": "1"
  323 + }
  324 + ],
  325 + "created_at": 1515485899,
  326 + "updated_at": 1515485899,
  327 + "tenant_id": "122371433052508160",
  328 + "admin": "测试",
  329 + "admin_mobile": "17710611692",
  330 + "admin_id": "132861396747554816",
  331 + "policy_id": "143373974074560512",
  332 + "personal_policy_id": "0",
  333 + "handle_type": "2",
  334 + "belong_ent": "蜗壳爱智能科技",
  335 + "belong_ent_id": "122371433052508160"
  336 + },
  337 + {
  338 + "person_fee": 1234.1,
  339 + "ent_fee": 1234.1,
  340 + "total_fee": 1234.1,
  341 + "id": "170636914884349952",
  342 + "policy_category": "1",
  343 + "policy_name": "林州市最新公积金政策",
  344 + "hhr_type": "",
  345 + "province": "河南省",
  346 + "province_code": "410000",
  347 + "city": "安阳市",
  348 + "city_code": "410500",
  349 + "district": "林州市",
  350 + "district_code": "410581",
  351 + "total_amount": 7236.8,
  352 + "insurances": [{
  353 + "id": "170636914980818944",
  354 + "base": 2000,
  355 + "pay_start_month": 1509465600,
  356 + "pay_end_month": 1512057600,
  357 + "abort_month": -62135596800,
  358 + "back_admin": "候大虎",
  359 + "back_admin_id": "128270343730106368",
  360 + "back_admin_mobile": "13261209796",
  361 + "datum_check_status": "init",
  362 + "op_progress": "0",
  363 + "op_result": "init",
  364 + "next_op": "",
  365 + "insurance": "补充公积金",
  366 + "account": "566656",
  367 + "service_start_month": 1509465600,
  368 + "pay_rate": 0.4523,
  369 + "fixed_amount": 500,
  370 + "insurance_category": "0",
  371 + "total_amount": 0,
  372 + "created_at": 1515485899,
  373 + "updated_at": 1515485899,
  374 + "tenant_id": "122371433052508160",
  375 + "payback_source": "manual",
  376 + "fee_per_month": 3618.4,
  377 + "op_month": 1514736000,
  378 + "relation_payback_ids": null,
  379 + "policy_category": "1",
  380 + "insured_person_id": "170621814383316992",
  381 + "person_amount": 919.6,
  382 + "ent_amount": 889.6,
  383 + "person_fixed_amount": 300,
  384 + "ent_fixed_amount": 200,
  385 + "person_proportion": 0.2299,
  386 + "ent_proportion": 0.2224,
  387 + "account_company": "",
  388 + "pay_frequency": "0"
  389 + },
  390 + {
  391 + "id": "170636915064705024",
  392 + "base": 2000,
  393 + "pay_start_month": 1509465600,
  394 + "pay_end_month": 1512057600,
  395 + "abort_month": -62135596800,
  396 + "back_admin": "测试",
  397 + "back_admin_id": "132861396747554816",
  398 + "back_admin_mobile": "17710611692",
  399 + "datum_check_status": "init",
  400 + "op_progress": "0",
  401 + "op_result": "init",
  402 + "next_op": "",
  403 + "insurance": "公积金",
  404 + "account": "566656",
  405 + "service_start_month": 1509465600,
  406 + "pay_rate": 0.4523,
  407 + "fixed_amount": 500,
  408 + "insurance_category": "0",
  409 + "total_amount": 0,
  410 + "created_at": 1515485899,
  411 + "updated_at": 1515485899,
  412 + "tenant_id": "122371433052508160",
  413 + "payback_source": "manual",
  414 + "fee_per_month": 3618.4,
  415 + "op_month": 1514736000,
  416 + "relation_payback_ids": null,
  417 + "policy_category": "1",
  418 + "insured_person_id": "170621814383316992",
  419 + "person_amount": 919.6,
  420 + "ent_amount": 889.6,
  421 + "person_fixed_amount": 300,
  422 + "ent_fixed_amount": 200,
  423 + "person_proportion": 0.2299,
  424 + "ent_proportion": 0.2224,
  425 + "account_company": "",
  426 + "pay_frequency": "0"
  427 + }
  428 + ],
  429 + "created_at": 1515485899,
  430 + "updated_at": 1515485899,
  431 + "tenant_id": "122371433052508160",
  432 + "admin": "测试",
  433 + "admin_mobile": "17710611692",
  434 + "admin_id": "132861396747554816",
  435 + "policy_id": "143382751427432448",
  436 + "personal_policy_id": "0",
  437 + "handle_type": "2",
  438 + "belong_ent": "蜗壳爱智能科技",
  439 + "belong_ent_id": "122371433052508160"
  440 + }
  441 + ],
  442 + "person_attachments": null,
  443 + "handle_results": null,
  444 + "created_at": 1515485899,
  445 + "updated_at": 1515485899,
  446 + "tenant_id": "122371433052508160",
  447 + "op_result": "success",
  448 + "insurance_ids": "",
  449 + "view_type": "form",
  450 + "target_contract_id": "153258768430272512",
  451 + "target_contract_name": "云测试",
  452 + "form_abnormal_status": "[]",
  453 + "form_is_abnormal": "n",
  454 + "form_handle_status": "wait-confirm",
  455 + "remind_at": -62135596800,
  456 + "si_base": 1000,
  457 + "hf_base": 2000,
  458 + "target_name": "上海锦迪娱乐有限公司 ",
  459 + "ent_si_policy_id": "143373974074560512",
  460 + "ent_hf_policy_id": "143382751427432448",
  461 + "si_province": "河南省",
  462 + "si_province_code": "410000",
  463 + "si_city": "安阳市",
  464 + "si_city_code": "410500",
  465 + "si_district": "林州市",
  466 + "si_district_code": "410581",
  467 + "hf_province": "河南省",
  468 + "hf_province_code": "410000",
  469 + "hf_city": "安阳市",
  470 + "hf_city_code": "410500",
  471 + "hf_district": "林州市",
  472 + "hf_district_code": "410581",
  473 + "creator": "周正友",
  474 + "creator_id": "83422060570742784",
  475 + "person_fee": 4369.3,
  476 + "ent_fee": 4225.61,
  477 + "total_fee": 8594.91,
  478 + "relation_real_id": "0",
  479 + "relation_payback_id": "0",
  480 + "handle_type": "2",
  481 + "op_month": 1514736000,
  482 + "decrease_comment": "",
  483 + "si_policy_belong_category": "",
  484 + "hf_policy_belong_category": "",
  485 + "si_back_return_infos": [{
  486 + "id": "8877776678899288",
  487 + "insurances": "[\"养老\",\"医疗\"]",
  488 + "return_reason": "无法增员",
  489 + "return_comment": "备注",
  490 + "start_month": 1514736000,
  491 + "end_month": 1514736000
  492 + }],
  493 + "hf_back_return_infos": [{
  494 + "id": "8877776678899288",
  495 + "insurances": "[\"公积金\"]",
  496 + "return_reason": "无法增员",
  497 + "return_comment": "备注",
  498 + "start_month": 1514736000,
  499 + "end_month": 1514736000
  500 + }]
  501 + }
  502 +},{
  503 + "url":"/psiorder/do-import-real-template",
  504 + "post_data":{
  505 + "result": {
  506 + "input_columns": [
  507 + "姓名",
  508 + "手机号",
  509 + "证件类型",
  510 + "开户行",
  511 + "证件号码",
  512 + "银行卡号",
  513 + "生育保险",
  514 + "商业健康保险费",
  515 + "服务费",
  516 + "住房公积金",
  517 + "应纳税额",
  518 + "实发工资",
  519 + "通信费",
  520 + "备注",
  521 + "应发工资",
  522 + "养老保险",
  523 + "医疗保险",
  524 + "失业保险"
  525 + ],
  526 + "base_fields": [{
  527 + "column": "姓名",
  528 + "key": "name",
  529 + "is_required": true
  530 + },
  531 + {
  532 + "column": "手机号",
  533 + "key": "mobile",
  534 + "is_required": true
  535 + }
  536 + ],
  537 + "ins_fields": [{
  538 + "column": "基数",
  539 + "key": "base",
  540 + "is_required": true
  541 + },
  542 + {
  543 + "column": "手机号",
  544 + "key": "mobile",
  545 + "is_required": true
  546 + }
  547 + ],
  548 + "insurance_prefix": [
  549 + "养老",
  550 + "医疗",
  551 + "工商"
  552 + ]
  553 + }
  554 + }
  555 +},{
  556 + "url":"/psiorder/real-template",
  557 + "post_data":{
  558 + "item": {
  559 + "id": "151104194051313664",
  560 + "created_at": 1510828935,
  561 + "updated_at": 1510828935,
  562 + "tenant_id": "122371433052508160",
  563 + "object_path": "xxxxxx",
  564 + "name": "小爱科技接单模板",
  565 + "account": "账户",
  566 + "account_id": "9872346001832123",
  567 + "province": "河北省",
  568 + "province_code": "130000",
  569 + "city": "保定市",
  570 + "city_code": "130400",
  571 + "district": "莲池区",
  572 + "district_code": "130401",
  573 + "insurances": ["养老保险", "医疗保险", "工伤保险"],
  574 + "has_payback": "y",
  575 + "header_has_insurance": "y",
  576 + "fields": [{
  577 + "original_column": "姓名",
  578 + "system_column": "姓名",
  579 + "key": "name",
  580 + "field_type": "text",
  581 + "field_category": "default",
  582 + "is_required": true
  583 + },
  584 + {
  585 + "original_column": "联系方式",
  586 + "system_column": "手机号",
  587 + "key": "mobile",
  588 + "field_type": "text",
  589 + "field_category": "default",
  590 + "is_required": true
  591 + },
  592 + {
  593 + "original_column": "证件类型",
  594 + "system_column": "证件类型",
  595 + "key": "credential_type",
  596 + "field_type": "text",
  597 + "field_category": "default",
  598 + "is_required": true
  599 + },
  600 + {
  601 + "original_column": "身份证号码",
  602 + "system_column": "证件号码",
  603 + "key": "credential_number",
  604 + "field_type": "text",
  605 + "field_category": "default",
  606 + "is_required": true
  607 + },
  608 + {
  609 + "original_column": "开户行",
  610 + "system_column": "开户行",
  611 + "key": "bank",
  612 + "field_type": "text",
  613 + "field_category": "default",
  614 + "is_required": true
  615 + },
  616 + {
  617 + "original_column": "银行卡号",
  618 + "system_column": "银行卡号",
  619 + "key": "bank_card_no",
  620 + "field_type": "text",
  621 + "field_category": "default",
  622 + "is_required": true
  623 + },
  624 + {
  625 + "original_column": "应发工资",
  626 + "system_column": "应发工资",
  627 + "key": "salary",
  628 + "field_type": "text",
  629 + "field_category": "default",
  630 + "is_required": true
  631 + },
  632 + {
  633 + "original_column": "住房公积金",
  634 + "system_column": "住房公积金",
  635 + "key": "house_fund",
  636 + "field_type": "float",
  637 + "field_category": "default",
  638 + "is_required": false
  639 + },
  640 + {
  641 + "original_column": "应纳税所得额",
  642 + "system_column": "应纳税所得额",
  643 + "key": "taxable_income",
  644 + "field_type": "float",
  645 + "field_category": "default",
  646 + "is_required": true
  647 + },
  648 + {
  649 + "original_column": "应纳税额",
  650 + "system_column": "应纳税额",
  651 + "key": "tax_amount",
  652 + "field_type": "float",
  653 + "field_category": "default",
  654 + "is_required": true
  655 + },
  656 + {
  657 + "original_column": "徐恒堂",
  658 + "system_column": "徐恒堂",
  659 + "key": "",
  660 + "field_type": "text",
  661 + "field_category": "default",
  662 + "is_required": false
  663 + }
  664 + ],
  665 + "template_path": "/hro/psiorder/tenants/122371433052508160/users/83422060570742784/小爱科技增员接单表.xls"
  666 + }
  667 + }
  668 +},{
  669 + "url":"/psiorder/real-templates",
  670 + "get_data":{
  671 + "total_count": 1,
  672 + "items": [{
  673 + "id": "171752302397362176",
  674 + "created_at": 1515751828,
  675 + "updated_at": 1515751828,
  676 + "tenant_id": "122371433052508160",
  677 + "name": "小爱模板",
  678 + "account": "账户",
  679 + "account_id": "9872346001832123",
  680 + "account_category": "0",
  681 + "province": "河北省",
  682 + "province_code": "130000",
  683 + "city": "保定市",
  684 + "city_code": "130400",
  685 + "district": "莲池区",
  686 + "district_code": "130401",
  687 + "insurances": ["养老保险", "医疗保险", "工伤保险"],
  688 + "has_payback": "y",
  689 + "header_has_insurance": "y",
  690 + "object_path": "/hro/empmgm/tenants/122371433052508160/users/99269474502316032/171752090454986752.xlsx",
  691 + "template_path": "/hro/payroll/tenants/122371433052508160/users/99269474502316032/小爱科技接单模板.xls",
  692 + "status": "active"
  693 + }]
  694 + }
  695 +},{
  696 + "url":"/psiorder/real-templates/[\\W\\w]+",
  697 + "del_data":{
  698 + "result":"SUCCESS"
  699 + }
  700 +},{
  701 + "url":"/psiorder/get-real-mapping",
  702 + "post_data":{
  703 + "result": {
  704 + "input_columns": [
  705 + "养老保险",
  706 + "医疗保险"
  707 + ],
  708 + "ins_fields": [{
  709 + "column": "养老保险",
  710 + "key": "养老保险",
  711 + "is_required": true
  712 + },
  713 + {
  714 + "column": "医疗保险",
  715 + "key": "医疗保险",
  716 + "is_required": true
  717 + }
  718 + ]
  719 + }
  720 + }
  721 +},{
  722 + "url":"/psiorder/real/do-import",
  723 + "post_data":{
  724 + "columns": "[{\"name\":\"姓名\"},{\"id_card_no\":\"身份证号码\"},{\"company\":\"所属公司\"},{\"organization\":\"部门\"},{\"base_salary\":\"基本工资\"},{\"merit_salary\":\"绩效工资\"},{\"total\":\"工资合计\"},{\"telephone_allowance\":\"电话补助\"},{\"lunch_allowance\":\"午餐补助\"},{\"trans_allowance\":\"交通补助\"},{\"other_allowance\":\"其它补助\"},{\"reward\":\"销售提成\/奖金\"},{\"attendance_deduction\":\"出勤扣款\"},{\"other_deduction\":\"其它扣款\"},{\"pay_salary\":\"应发工资\"},{\"company_insurance\":\"公司五险\"},{\"company_fund\":\"公司公积金\"},{\"person_insurance\":\"个人五险\"},{\"person_fund\": \"个人公积金\"},{\"person_total\":\"个人合计\"},{\"company_total\":\"单位合计\"},{\"tax_salary\":\"应税工资\"},{\"personal_tax\":\"个税\"},{\"salary\":\"实发工资\"}]",
  725 + "costData": "[{\"company_fund\":456,\"compay_insurance\":546.45,\"datas\":{\"attendance_deduction\":\"21\",\"base_salary\":\"20000\",\"company\":\"北京小爱智能科技有限公司\",\"company_fund\":\"456\",\"company_insurance\":\"546.45000000000005\",\"company_total\":\"1002.45\",\"id_card_no\":\"110221198301270001\",\"lunch_allowance\":\"0\",\"merit_salary\":\"10000\",\"name\":\"甲\",\"organization\":\"销售部\",\"other_allowance\":\"0\",\"other_deduction\":\"0\",\"pay_salary\":\"3000\",\"person_fund\":\"456\",\"person_insurance\":\"318.45\",\"person_total\":\"774.45\",\"personal_tax\":\"678.65\",\"reward\":\"0\",\"salary\":\"60100\",\"tax_salary\":\"\",\"telephone_allowance\":\"100\",\"total\":\"30000\",\"trans_allowance\":\"200\"},\"id_card_no\":\"110221198301270001\",\"name\":\"甲\",\"pay_salary\":3000,\"salary\":60100},{\"company_fund\":456,\"compay_insurance\":546.45,\"datas\":{\"attendance_deduction\":\"21\",\"base_salary\":\"80000\",\"company\":\"北京小爱智能科技有限公司\",\"company_fund\":\"456\",\"company_insurance\":\"546.45000000000005\",\"company_total\":\"1002.45\",\"id_card_no\":\"110221198301270002\",\"lunch_allowance\":\"0\",\"merit_salary\":\"40000\",\"name\":\"乙\",\"organization\":\"研发部\",\"other_allowance\":\"0\",\"other_deduction\":\"0\",\"pay_salary\":\"12000\",\"person_fund\":\"456\",\"person_insurance\":\"318.45\",\"person_total\":\"774.45\",\"personal_tax\":\"678.65\",\"reward\":\"0\",\"salary\":\"240100\",\"tax_salary\":\"\",\"telephone_allowance\":\"100\",\"total\": \"120000\",\"trans_allowance\":\"200\"},\"id_card_no\":\"110221198301270002\",\"name\":\"乙\",\"pay_salary\":12000,\"salary\":240100}]",
  726 + "errors": "[]"
  727 + }
  728 +},{
  729 + "url":"/psiorder/real",
  730 + "get_data":{
  731 + "total_count": 1,
  732 + "items": [{
  733 + "account_id": "2938402304",
  734 + "account": "账户号",
  735 + "account_category": "0",
  736 + "op_month": 1520309847,
  737 + "people_count": 432,
  738 + "ent_amount": 1000,
  739 + "person_amount": 1000,
  740 + "real_type": "import",
  741 + "total_amount": 2000
  742 + }]
  743 + }
  744 +},{
  745 + "url":"/psiorder/real-detail",
  746 + "get_data":{
  747 + "total_count": 1,
  748 + "items": [{
  749 + "id": "xxx",
  750 + "name": "张三",
  751 + "id_num": "923740928034777",
  752 + "hhr_type": "农村",
  753 + "pay_type": "正常应缴",
  754 + "insurances": ["养老", "医疗"],
  755 + "base": 1000,
  756 + "pay_start_month": 1520309847,
  757 + "pay_end_month": 1520309847,
  758 + "person_amount": 1000,
  759 + "ent_amount": 1000,
  760 + "total_amount": 2000
  761 + }]
  762 + }
  763 +},{
  764 + "url":"/psiorder/accounts",
  765 + "get_data":{
  766 + "total_count": 1,
  767 + "items": [{
  768 + "account": "9999",
  769 + "account_id": "999900000000001",
  770 + "account_category": "0",
  771 + "insurances": ["养老", "医疗"],
  772 + "province": "河北省",
  773 + "province_code": "130000",
  774 + "city": "邢台市",
  775 + "city_code": "130700",
  776 + "district": "大大区",
  777 + "district_code": "130702"
  778 + }]
  779 + }
  780 +},{
  781 + "url":"/psiorder/diff-handle-statistics",
  782 + "get_data":{
  783 + "deduct": 2929,
  784 + "payback": 920,
  785 + "refund": 901
  786 + }
  787 +},{
  788 + "url":"/psiorder/customer-handle-diffs",
  789 + "get_data":{
  790 + "total_count": 1,
  791 + "items": [{
  792 + "id": "0293840273094",
  793 + "diff_handle_type": "deduct",
  794 + "customer": "我是客户",
  795 + "service_contract": "我是服务合同",
  796 + "start_month": 1520309847,
  797 + "handle_month": 1520309847,
  798 + "refund_type": "now",
  799 + "total_amount": 888,
  800 + "status": "handled"
  801 + }]
  802 + }
  803 +},{
  804 + "url":"/psiorder/customer-diff-export",
  805 + "post_data":{
  806 + "object_path":"hro/xxxx.xls"
  807 + }
  808 +},{
  809 + "url":"/psiorder/customer-diff-confirm/[\\W\\w]+",
  810 + "post_data":{
  811 + "result":"SUCCESS"
  812 + }
  813 +},{
  814 + "url":"/psiorder/person-handle-diffs",
  815 + "get_data":{
  816 + "total_count": 1,
  817 + "items": [{
  818 + "id": "0293840273094",
  819 + "name": "张三",
  820 + "id_num": "130928199901020921",
  821 + "customer": "我是客户",
  822 + "service_contract": "我是服务合同",
  823 + "start_month": 1520309847,
  824 + "refund_type": "now",
  825 + "bank_name": "开户行",
  826 + "bank_card_num": "92038480293840",
  827 + "total_amount": 88,
  828 + "status": "handled"
  829 + }]
  830 + }
  831 +},{
  832 + "url":"/psiorder/person-diff-export",
  833 + "post_data":{
  834 + "object_path":"hro/xxxx.xls"
  835 + }
  836 +},{
  837 + "url":"/psiorder/person-diff-confirm/[\\W\\w]+",
  838 + "post_data":{
  839 + "result":"SUCCESS"
  840 + }
  841 +},{
  842 + "url":"/psiorder/diffs",
  843 + "get_data":{
  844 + "total_count": 1,
  845 + "items": [{
  846 + "id": "8887729293747",
  847 + "customer": "我是客户",
  848 + "customer_id": "8888292910839900",
  849 + "service_contract": "我是服务合同",
  850 + "service_contract_id": "77773889200288388",
  851 + "op_month": 1520309847,
  852 + "status": "wait",
  853 + "pre_person_count": 500,
  854 + "pre_total_amount": 10000,
  855 + "real_person_count": 498,
  856 + "real_total_amount": 9800,
  857 + "diff_total_amount": 200
  858 + }]
  859 + }
  860 +},
  861 +{
  862 + "url":"/psiorder/entsi-person-diffs",
  863 + "get_data":{
  864 + "head":{
  865 + "id": "8887729293747",
  866 + "customer": "我是客户",
  867 + "customer_id": "8888292910839900",
  868 + "service_contract": "我是服务合同",
  869 + "service_contract_id": "77773889200288388",
  870 + "op_month": 1520309847,
  871 + "status": "wait",
  872 + "pre_person_count": 500,
  873 + "pre_total_amount": 10000,
  874 + "real_person_count": 498,
  875 + "real_total_amount": 9800,
  876 + "diff_total_amount": 200
  877 + },
  878 + "total_count": 1,
  879 + "items": [{
  880 + "id": "8887729293747",
  881 + "name": "张三",
  882 + "id_num": "证件号码",
  883 + "pay_type": "正常应缴",
  884 + "diff_handle_status": "handled",
  885 + "service_contract_id": "77773889200288388",
  886 + "op_month": 1520309847,
  887 + "pre_amount": 1000,
  888 + "real_total_amount": 980,
  889 + "diff_real_amount": 200,
  890 + "diff_other_amount": 200,
  891 + "diff_amount": 200,
  892 + "person_diff_amount": 0,
  893 + "ent_diff_amount": 0,
  894 + "real_person_amount": 0,
  895 + "real_ent_amount": 0,
  896 + "diff_handle_show_type": "0"
  897 + }]
  898 + }
  899 +},{
  900 + "url":"/psiorder/person-diff/[\\W\\w]+",
  901 + "get_data":{
  902 + "id": "2394727340290",
  903 + "handle_result": {
  904 + "handle_info": "抵款,差异费用抵扣到2018年5月",
  905 + "comment": ""
  906 + },
  907 + "base_info": {
  908 + "name": "小何",
  909 + "id_num": "130928198701010099",
  910 + "province": "河北省",
  911 + "province_code": "130000",
  912 + "city": "邯郸市",
  913 + "city_code": "1300100",
  914 + "district": "第一区",
  915 + "district_code": "130101",
  916 + "hhr_type": "本地农村",
  917 + "customer": "北京小鸟科技",
  918 + "service_contract": "我是服务合同",
  919 + "pay_type": "正常应缴",
  920 + "op_month": 150029399,
  921 + "diff_handle_show_type": "0"
  922 +
  923 + },
  924 + "total_diff_amount": 10000,
  925 + "other_amount": 200,
  926 + "ins_diff_info": [{
  927 + "insurance": "养老",
  928 + "service_month": 150029399,
  929 + "person_pre_amount": 400,
  930 + "person_real_amount": 400,
  931 + "person_diff_amount": 0,
  932 + "ent_pre_amount": 400,
  933 + "ent_real_amount": 400,
  934 + "ent_diff_amount": 0,
  935 + "total_pre_amount": 1000,
  936 + "total_real_amount": 1000,
  937 + "total_diff_amount": 0
  938 + }]
  939 + }
  940 +}]
... ...
此 diff 太大无法显示。
  1 +
  2 +// # user
  3 +
  4 +var util = require('util');
  5 +
  6 +var _ = require('underscore');
  7 +var _str = require('underscore.string');
  8 +_.mixin(_str.exports());
  9 +
  10 +var strength = require('strength');
  11 +var validator = require('validator');
  12 +
  13 +exports = module.exports = function(settings, email, logger) {
  14 +
  15 + var User = {};
  16 +
  17 + return {};
  18 +};
  19 +
  20 +exports['@singleton'] = true;
  21 +exports['@require'] = [ 'igloo/settings', 'igloo/email', 'igloo/logger' ];
... ...
  1 +{
  2 + "name": "hro-middleware",
  3 + "version": "1.0.0",
  4 + "main": "index.js",
  5 + "author": "juvenile <1050299953@qq.com>",
  6 + "license": "MIT",
  7 + "scripts": {
  8 + "start":"nodemon app.js"
  9 + },
  10 + "devDependencies": {
  11 + "bootable": "^0.2.4",
  12 + "compression": "^1.6.1",
  13 + "connect-ensure-login": "^0.1.1",
  14 + "connect-flash": "^0.1.1",
  15 + "cookie-parser": "^1.4.1",
  16 + "csurf": "^1.8.3",
  17 + "ejs": "^2.4.1",
  18 + "electrolyte": "0.0.6",
  19 + "express": "^4.13.4",
  20 + "helmet": "^1.3.0",
  21 + "igloo": "git+http://gitlab.workai.com.cn/zanghb/igloo.git",
  22 + "method-override": "^2.3.5",
  23 + "moment": "^2.12.0",
  24 + "nodemon": "^2.0.15",
  25 + "passport": "^0.3.2",
  26 + "passport-local": "^1.0.0",
  27 + "response-time": "^2.3.1",
  28 + "restler": "^3.4.0",
  29 + "restler-q": "^0.1.1",
  30 + "serve-favicon": "^2.3.0",
  31 + "strength": "^0.1.4",
  32 + "urlencode": "^1.1.0",
  33 + "uuid": "^7.0.1",
  34 + "validator": "^5.1.0",
  35 + "winston-request-logger": "^1.0.7"
  36 + },
  37 + "dependencies": {}
  38 +}
... ...
  1 +var express = require('express');
  2 +
  3 +exports = module.exports = function (IoC, policies, settings) {
  4 + var app = this;
  5 + var router = express.Router();
  6 + var controller = IoC.create('controllers/api');
  7 +
  8 + router.get(
  9 + '/*',
  10 + policies.ensureLoggedOut(),
  11 + controller.get
  12 + );
  13 +
  14 + router.post(
  15 + '/*',
  16 + policies.ensureLoggedOut(),
  17 + controller.post
  18 + );
  19 +
  20 + router.put(
  21 + '/*',
  22 + policies.ensureLoggedOut(),
  23 + controller.put
  24 + );
  25 +
  26 + router.patch(
  27 + '/*',
  28 + policies.ensureLoggedOut(),
  29 + controller.patch
  30 + );
  31 +
  32 + router.head(
  33 + '/*',
  34 + policies.ensureLoggedOut(),
  35 + controller.head
  36 + );
  37 +
  38 + router.delete(
  39 + '/*',
  40 + policies.ensureLoggedOut(),
  41 + controller.delete
  42 + );
  43 +
  44 + app.use(settings.prefix + 'api', router);
  45 +};
  46 +
  47 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  48 +exports['@singleton'] = true;
... ...
  1 +var express = require('express');
  2 +var payRoll = require('../json/payRoll.json');
  3 +
  4 +exports = module.exports = function (IoC, policies, settings) {
  5 + var app = this;
  6 + var router = express.Router();
  7 + var router2 = express.Router();
  8 + var controller = IoC.create('controllers/auth');
  9 +
  10 + if (settings.prefix.length > 0) {
  11 + router.get(
  12 + '/',
  13 + controller.index
  14 + );
  15 + router.get(
  16 + '/signOut',
  17 + controller.signOut
  18 + );
  19 + }
  20 +
  21 + router2.get(
  22 + '/',
  23 + controller.indexPrefix
  24 + );
  25 +
  26 + router.get(
  27 + '/productDes',
  28 + controller.productDes
  29 + );
  30 +
  31 + router.get(
  32 + '/register',
  33 + controller.register
  34 + );
  35 +
  36 + router.get(
  37 + '/mobileRegister',
  38 + controller.mobileRegister
  39 + );
  40 +
  41 + router.get(
  42 + '/mobileRegisterSuccess',
  43 + controller.mobileRegisterSuccess
  44 + );
  45 +
  46 + router.get(
  47 + '/signIn',
  48 + controller.signIn
  49 + );
  50 +
  51 + router.post(
  52 + '/doLogin',
  53 + controller.doLogin
  54 + );
  55 +
  56 +
  57 + router2.get(
  58 + '/signOut',
  59 + controller.signOut
  60 + );
  61 +
  62 + router.post(
  63 + '/smsCodes',
  64 + controller.smsCodes
  65 + );
  66 +
  67 + router.post(
  68 + '/tenants',
  69 + controller.tenants
  70 + );
  71 +
  72 + router.post(
  73 + '/resetPass',
  74 + policies.ensureLoggedOut(),
  75 + controller.resetPass
  76 + );
  77 +
  78 + router.post(
  79 + '/updatePassword',
  80 + policies.ensureLoggedOut(),
  81 + controller.updatePassword
  82 + );
  83 +
  84 +
  85 + router.post(
  86 + '/loadUserInfo',
  87 + policies.ensureLoggedOut(),
  88 + controller.loadUserInfo
  89 + );
  90 +
  91 + router.post(
  92 + '/getUploaderToken',
  93 + policies.ensureLoggedOut(),
  94 + controller.getUploaderToken
  95 + );
  96 +
  97 + router.post(
  98 + '/delOSSObject',
  99 + policies.ensureLoggedOut(),
  100 + controller.delOSSObject
  101 + );
  102 +
  103 + router.post(
  104 + '/smsVerification',
  105 + controller.smsVerification
  106 + )
  107 +
  108 + router.post(
  109 + '/getObjectTokenByID',
  110 + controller.getObjectTokenByID
  111 + )
  112 +
  113 + // router.get(
  114 + // '/healthMonitor',
  115 + // controller.healthMonitor
  116 + // )
  117 +
  118 + // router.head(
  119 + // '/healthMonitor',
  120 + // controller.healthMonitor
  121 + // )
  122 +
  123 + router.post(
  124 + '/getUserRoles',
  125 + policies.ensureLoggedOut(),
  126 + controller.getUserRoles
  127 + );
  128 +
  129 + router.post(
  130 + '/getRoles',
  131 + policies.ensureLoggedOut(),
  132 + controller.getRoles
  133 + );
  134 +
  135 + router.post(
  136 + '/updateUserRoles',
  137 + policies.ensureLoggedOut(),
  138 + controller.updateUserRoles
  139 + );
  140 +
  141 + router.post(
  142 + '/getTenant',
  143 + policies.ensureLoggedOut(),
  144 + controller.getTenant
  145 + );
  146 +
  147 + router.post(
  148 + '/updateTenant',
  149 + policies.ensureLoggedOut(),
  150 + controller.updateTenant
  151 + );
  152 +
  153 + router.get(
  154 + '/offer/:requestId',
  155 + controller.offer
  156 + );
  157 +
  158 + router.post(
  159 + '/onboardStatus',
  160 + policies.ensureLoggedOut(),
  161 + controller.onboardStatus
  162 + );
  163 +
  164 + router.get(
  165 + '/downloadApp',
  166 + controller.dowloadApp
  167 + );
  168 +
  169 + router.get(
  170 + '/info/policy',
  171 + controller.softwareLicense
  172 + );
  173 +
  174 + router.get('/payRoll', function (req, res, next) {
  175 + res.send(payRoll);
  176 + });
  177 +
  178 + router.get(
  179 + '/recharge',
  180 + controller.recharge
  181 + );
  182 +
  183 + router.post(
  184 + '/changePassForRegister',
  185 + controller.changePassForRegister
  186 + );
  187 +
  188 + router.post(
  189 + '/changeTenant',
  190 + policies.ensureLoggedOut(),
  191 + controller.changeTenant
  192 + );
  193 +
  194 + router.post(
  195 + '/hr/sendRejectOffer',
  196 + controller.sendRejectOffer
  197 + );
  198 +
  199 + router.post(
  200 + '/hr/acceptOffer',
  201 + controller.acceptOffer
  202 + );
  203 +
  204 + router.post(
  205 + '/imTokens',
  206 + policies.ensureLoggedOut(),
  207 + controller.imTokens
  208 + );
  209 +
  210 + router.post(
  211 + '/listChannels',
  212 + policies.ensureLoggedOut(),
  213 + controller.listChannels
  214 + );
  215 +
  216 + router.post(
  217 + '/getTastLink',
  218 + policies.ensureLoggedOut(),
  219 + controller.getTastLink
  220 + );
  221 +
  222 + router.get(
  223 + '/filemeta',
  224 + policies.ensureLoggedOut(),
  225 + controller.filemeta
  226 + );
  227 +
  228 + router.get(
  229 + '/getCustomerQrcode',
  230 + policies.ensureLoggedOut(),
  231 + controller.getCustomerQrcode
  232 + );
  233 +
  234 + router.get(
  235 + '/getPositionQrcode',
  236 + policies.ensureLoggedOut(),
  237 + controller.getPositionQrcode
  238 + );
  239 + router.get( //微店模板路由
  240 + '/minishop/:id',
  241 + controller.weidianTempLate
  242 + );
  243 +
  244 + router.get(
  245 + '/wso-workai',
  246 + controller.workaiSecurityOAuth
  247 + );
  248 +
  249 + router.get(
  250 + '/socialwork/freedom-jobs/emps/:id/:verification',
  251 + controller.freedomJobsEmp
  252 + );
  253 +
  254 + router.get(
  255 + '/socialwork/freedom-jobs/emps/:id',
  256 + controller.freedomJobsEmp
  257 + );
  258 +
  259 + router.get(
  260 + '/getShortToken',
  261 + controller.getShortToken
  262 + );
  263 +
  264 + settings.prefix.length > 1 ?
  265 + app.use(settings.prefix.substring(0, settings.prefix.length - 1), router) :
  266 + app.use('/', router);
  267 +
  268 +
  269 + app.use('/', router2);
  270 +};
  271 +
  272 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  273 +exports['@singleton'] = true;
... ...
  1 +var express = require('express');
  2 +
  3 +exports = module.exports = function (IoC, policies, settings) {
  4 + var app = this;
  5 + var router = express.Router();
  6 + var controller = IoC.create('controllers/authed');
  7 +
  8 + router.get(
  9 + '/*',
  10 + controller.get
  11 + );
  12 +
  13 + router.post(
  14 + '/*',
  15 + controller.post
  16 + );
  17 +
  18 + router.put(
  19 + '/*',
  20 + controller.put
  21 + );
  22 +
  23 + router.patch(
  24 + '/*',
  25 + controller.patch
  26 + );
  27 +
  28 + router.head(
  29 + '/*',
  30 + controller.head
  31 + );
  32 +
  33 + router.delete(
  34 + '/*',
  35 + controller.delete
  36 + );
  37 +
  38 + app.use(settings.prefix + 'auth_api', router);
  39 +};
  40 +
  41 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  42 +exports['@singleton'] = true;
... ...
  1 +
  2 +// app - routes
  3 +
  4 +var bootable = require('bootable');
  5 +
  6 +exports = module.exports = function(IoC, settings) {
  7 +
  8 + var app = this;
  9 +
  10 + //auth
  11 + app.phase(bootable.di.routes('./routes/auth.js'));
  12 +
  13 + //mock
  14 + app.phase(bootable.di.routes('./routes/mock.js'));
  15 + //authed
  16 +
  17 + app.phase(bootable.di.routes('./routes/authed.js'));
  18 +
  19 + //api
  20 + app.phase(bootable.di.routes('./routes/api.js'));
  21 +
  22 + //file
  23 + app.phase(bootable.di.routes('./routes/file.js'));
  24 +
  25 + //robot
  26 + app.phase(bootable.di.routes('./routes/robot.js'));
  27 +
  28 + // error handler (always keep this last)
  29 + app.phase(function() {
  30 + var errorHandler = IoC.create('igloo/error-handler');
  31 + app.use(errorHandler);
  32 + });
  33 +
  34 +};
  35 +
  36 +exports['@require'] = [ '$container', 'igloo/settings' ];
... ...
  1 +var express = require('express');
  2 +
  3 +exports = module.exports = function (IoC, policies, settings) {
  4 + var app = this;
  5 + var router = express.Router();
  6 + var controller = IoC.create('controllers/file');
  7 +
  8 + router.get(
  9 + '/*',
  10 + controller.get
  11 + );
  12 +
  13 + router.post(
  14 + '/*',
  15 + controller.post
  16 + );
  17 +
  18 + router.put(
  19 + '/*',
  20 + controller.put
  21 + );
  22 +
  23 + router.patch(
  24 + '/*',
  25 + controller.patch
  26 + );
  27 +
  28 + router.head(
  29 + '/*',
  30 + controller.head
  31 + );
  32 +
  33 + router.delete(
  34 + '/*',
  35 + controller.delete
  36 + );
  37 +
  38 + app.use(settings.prefix + 'file_api', router);
  39 +};
  40 +
  41 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  42 +exports['@singleton'] = true;
... ...
  1 +var express = require('express');
  2 +
  3 +exports = module.exports = function (IoC, policies, settings) {
  4 + var app = this;
  5 + var router = express.Router();
  6 + var controller = IoC.create('controllers/mock');
  7 +
  8 + router.get(
  9 + '/*',
  10 + policies.ensureLoggedOut(),
  11 + controller.get
  12 + );
  13 +
  14 + router.post(
  15 + '/*',
  16 + policies.ensureLoggedOut(),
  17 + controller.post
  18 + );
  19 +
  20 + router.put(
  21 + '/*',
  22 + policies.ensureLoggedOut(),
  23 + controller.put
  24 + );
  25 +
  26 + router.patch(
  27 + '/*',
  28 + policies.ensureLoggedOut(),
  29 + controller.patch
  30 + );
  31 +
  32 + router.head(
  33 + '/*',
  34 + policies.ensureLoggedOut(),
  35 + controller.head
  36 + );
  37 +
  38 + router.delete(
  39 + '/*',
  40 + policies.ensureLoggedOut(),
  41 + controller.delete
  42 + );
  43 +
  44 + app.use(settings.prefix + 'mock/api', router);
  45 +};
  46 +
  47 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  48 +exports['@singleton'] = true;
... ...
  1 +var express = require('express');
  2 +
  3 +exports = module.exports = function (IoC, policies, settings) {
  4 + var app = this;
  5 + var router = express.Router();
  6 + var controller = IoC.create('controllers/robot');
  7 + router.get(
  8 + '/robot',
  9 + controller.index
  10 + );
  11 +
  12 + router.get(
  13 + '/api/*',
  14 + controller.get
  15 + );
  16 +
  17 + router.post(
  18 + '/api/*',
  19 + controller.post
  20 + );
  21 +
  22 + router.put(
  23 + '/api/*',
  24 + controller.put
  25 + );
  26 +
  27 + router.patch(
  28 + '/api/*',
  29 + controller.patch
  30 + );
  31 +
  32 + router.head(
  33 + '/api/*',
  34 + controller.head
  35 + );
  36 +
  37 + router.delete(
  38 + '/api/*',
  39 + controller.delete
  40 + );
  41 +
  42 + app.use(settings.prefix + 'demo', router);
  43 +};
  44 +
  45 +exports['@require'] = ['$container', 'policies', 'igloo/settings'];
  46 +exports['@singleton'] = true;
... ...
  1 +
  2 +// # tests - server
  3 +
  4 +var util = require('util');
  5 +var request = require('supertest');
  6 +var app = require('../app');
  7 +var chai = require('chai');
  8 +var sinon = require('sinon');
  9 +var sinonChai = require('sinon-chai');
  10 +var expect = chai.expect;
  11 +
  12 +chai.should();
  13 +chai.use(sinonChai);
  14 +
  15 +request = request(app);
  16 +
  17 +describe('server', function() {
  18 +
  19 + it('should return 200 if home page loads', function(done) {
  20 + request
  21 + .get('/')
  22 + .accept('application/json')
  23 + .expect(200)
  24 + .end(done);
  25 + });
  26 +
  27 +});
... ...
  1 +
  2 +// # tests - users
  3 +
  4 +var util = require('util');
  5 +var request = require('supertest');
  6 +var app = require('../app');
  7 +var chai = require('chai');
  8 +var sinon = require('sinon');
  9 +var sinonChai = require('sinon-chai');
  10 +var expect = chai.expect;
  11 +var utils = require('./utils');
  12 +var async = require('async');
  13 +var IoC = require('electrolyte');
  14 +var cheerio = require('cheerio');
  15 +
  16 +chai.should();
  17 +chai.use(sinonChai);
  18 +
  19 +request = request(app);
  20 +
  21 +// storage for context-specific variables throughout the tests
  22 +var context = {};
  23 +
  24 +describe('/users', function() {
  25 +
  26 + var User = IoC.create('models/user');
  27 +
  28 + // Clean DB and add 3 sample users before tests start
  29 + before(function(done) {
  30 + async.waterfall([
  31 + utils.cleanDatabase,
  32 + function createTestUsers(callback) {
  33 + // Create 3 test users
  34 + async.timesSeries(3, function(i, _callback) {
  35 + var user = new User({
  36 + email: 'email+' + i + '@example.com',
  37 + name: 'User #' + i,
  38 + surname: 'Last Name #' + i,
  39 + password: '1234' + i
  40 + });
  41 +
  42 + user.save(_callback);
  43 + }, callback);
  44 + }
  45 + ], done);
  46 + });
  47 +
  48 + // Clean DB after all tests are done
  49 + after(function(done) {
  50 + utils.cleanDatabase(done);
  51 + });
  52 +
  53 + it('POST /users - should return 200 if user was created', function(done) {
  54 + this.timeout(3000); // The first request sometimes takes longer to complete
  55 +
  56 + request
  57 + .post('/users')
  58 + .set({
  59 + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled
  60 + })
  61 + .accept('application/json')
  62 + .send({
  63 + email: util.format('niftylettuce+%s@gmail.com', new Date().getTime()),
  64 + name: 'Nifty',
  65 + surname: 'Lettuce',
  66 + password: 'abc123'
  67 + })
  68 + .expect(200)
  69 + .end(function(err, res) {
  70 + if (err) return done(err);
  71 +
  72 + // Test the attributes exist
  73 + expect(res.body).to.exist;
  74 + res.body.should.have.property('id');
  75 + res.body.should.have.property('name');
  76 + res.body.should.have.property('surname');
  77 + res.body.should.not.have.property('password');
  78 +
  79 + // Test the values make sense
  80 + res.body.name.should.equal('Nifty');
  81 + res.body.surname.should.equal('Lettuce');
  82 +
  83 + // Store this id to use later
  84 + context.userIdCreatedWithRequest = res.body.id;
  85 +
  86 + done();
  87 + });
  88 + });
  89 +
  90 + it('GET /users/:id — should return 200 if user was retrieved', function(done) {
  91 + request
  92 + .get(util.format('/users/%s', context.userIdCreatedWithRequest))
  93 + .accept('application/json')
  94 + .expect(200)
  95 + .end(function(err, res) {
  96 + if (err) return done(err);
  97 +
  98 + // Test the attributes exist
  99 + expect(res.body).to.exist;
  100 + res.body.should.have.property('id');
  101 + res.body.should.have.property('name');
  102 + res.body.should.have.property('surname');
  103 + res.body.should.not.have.property('password');
  104 +
  105 + // Test the values make sense
  106 + res.body.name.should.equal('Nifty');
  107 + res.body.surname.should.equal('Lettuce');
  108 +
  109 + done();
  110 + });
  111 + });
  112 +
  113 + it('PUT /users/:id - should return 200 if user was updated', function(done) {
  114 + request
  115 + .put(util.format('/users/%s', context.userIdCreatedWithRequest))
  116 + .set({
  117 + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled
  118 + })
  119 + .accept('application/json')
  120 + .send({
  121 + name: 'NiftyWhoa',
  122 + email: 'niftywhoa@gmail.com',
  123 + surname: 'LettuceWhoa'
  124 + })
  125 + .expect(200)
  126 + .end(function(err, res) {
  127 + if (err) return done(err);
  128 +
  129 + // Test the attributes exist
  130 + expect(res.body).to.exist;
  131 + res.body.should.have.property('id');
  132 + res.body.should.have.property('email');
  133 + res.body.should.have.property('name');
  134 + res.body.should.have.property('surname');
  135 +
  136 + // Test the values make sense
  137 + res.body.email.should.equal('niftywhoa@gmail.com');
  138 + res.body.name.should.equal('NiftyWhoa');
  139 + res.body.surname.should.equal('LettuceWhoa');
  140 +
  141 + done();
  142 + });
  143 + });
  144 +
  145 + it('DELETE /users/:id - should return 200 if user was deleted', function(done) {
  146 + request
  147 + .del(util.format('/users/%s', context.userIdCreatedWithRequest))
  148 + .set({
  149 + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled
  150 + })
  151 + .accept('application/json')
  152 + .expect(200)
  153 + .end(function(err, res) {
  154 + if (err) return done(err);
  155 +
  156 + // Test the attributes exist
  157 + expect(res.body).to.exist;
  158 + res.body.should.have.property('id');
  159 + res.body.should.have.property('deleted');
  160 +
  161 + // Test the values make sense
  162 + res.body.id.should.equal(context.userIdCreatedWithRequest);
  163 + res.body.deleted.should.equal(true);
  164 +
  165 + done();
  166 + });
  167 + });
  168 +
  169 + it('GET /users - should return 200 if user index loads (JSON)', function(done) {
  170 + request
  171 + .get('/users')
  172 + .accept('application/json')
  173 + .expect(200, done);
  174 + });
  175 +
  176 + it('GET /users - should return 200 if user index loads and shows 3 rows (HTML)', function(done) {
  177 + request
  178 + .get('/users')
  179 + .accept('text/html')
  180 + .expect(200)
  181 + .end(function(err, res) {
  182 + // Test the attributes exist
  183 + expect(res.text).to.exist;
  184 +
  185 + var $ = cheerio.load(res.text);
  186 + var $userList = $('table');
  187 + var $userRows = $userList.find('tr');
  188 +
  189 + // Test the values make sense
  190 + $userList.should.have.length.of(1);
  191 + $userRows.should.have.length.of.at.least(3);
  192 +
  193 + done();
  194 + });
  195 + });
  196 +
  197 +});
... ...
  1 +
  2 +// # tests - api
  3 +
  4 +var util = require('util');
  5 +var request = require('supertest');
  6 +var app = require('../app');
  7 +var chai = require('chai');
  8 +var sinon = require('sinon');
  9 +var sinonChai = require('sinon-chai');
  10 +var expect = chai.expect;
  11 +var utils = require('./utils');
  12 +var async = require('async');
  13 +var IoC = require('electrolyte');
  14 +var cheerio = require('cheerio');
  15 +
  16 +chai.should();
  17 +chai.use(sinonChai);
  18 +
  19 +request = request(app);
  20 +
  21 +// storage for context-specific variables throughout the tests
  22 +var context = {};
  23 +
  24 +describe('/api', function() {
  25 +
  26 + var User = IoC.create('models/user');
  27 +
  28 + // Clean DB and add 3 sample users before tests start
  29 + before(function(done) {
  30 + // We need this timeout increased because "registering" a user instead of just saving takes longer
  31 + this.timeout(5000);
  32 +
  33 + async.waterfall([
  34 + utils.cleanDatabase,
  35 + function createTestUsers(callback) {
  36 + // Create 3 test users
  37 + async.timesSeries(3, function(i, _callback) {
  38 + var user = {
  39 + email: 'email+' + i + '@example.com',
  40 + name: 'User #' + i,
  41 + surname: 'Last Name #' + i,
  42 + password: '123456a' + i
  43 + };
  44 +
  45 + // Save the details for the second user
  46 + if ( i === 1 ) {
  47 + context.testUser = user;
  48 + }
  49 +
  50 + // Registering instead of saving so we can login with the user
  51 + User.register({
  52 + email: user.email,
  53 + name: user.name,
  54 + surname: user.surname
  55 + }, user.password, _callback);
  56 + }, callback);
  57 + }
  58 + ], done);
  59 + });
  60 +
  61 + // Clean DB after all tests are done
  62 + after(function(done) {
  63 + utils.cleanDatabase(done);
  64 + });
  65 +
  66 + it('POST /api/auth/email - should return 200 with user object', function(done) {
  67 + request
  68 + .post('/api/auth/email')
  69 + .send({
  70 + email: context.testUser.email,
  71 + password: context.testUser.password
  72 + })
  73 + .expect(200)
  74 + .end(function(err, res) {
  75 + if (err) return done(err);
  76 +
  77 + var result = res.body;
  78 +
  79 + // Test the attributes exist
  80 + expect(result).to.exist;
  81 + result.should.have.property('id');
  82 + result.should.have.property('name');
  83 + result.should.have.property('surname');
  84 + result.should.not.have.property('password');
  85 +
  86 + // Test the values make sense
  87 + result.name.should.equal(context.testUser.name);
  88 + result.surname.should.equal(context.testUser.surname);
  89 +
  90 + // Store the API token to use it later
  91 + context.testUser.apiToken = result.api_token;
  92 +
  93 + done();
  94 + });
  95 + });
  96 +
  97 + it('PUT /api/user - should return 200 with user object', function(done) {
  98 + request
  99 + .put('/api/user')
  100 + .auth(context.testUser.apiToken, 'a')// Apparently supertest or basic-auth need password to not be empty
  101 + .send({
  102 + email: context.testUser.email,
  103 + name: 'Nifty',
  104 + surname: 'Lettuce'
  105 + })
  106 + .expect(200)
  107 + .end(function(err, res) {
  108 + if (err) return done(err);
  109 +
  110 + var result = res.body;
  111 +
  112 + // Test the attributes exist
  113 + expect(result).to.exist;
  114 + result.should.have.property('id');
  115 + result.should.have.property('name');
  116 + result.should.have.property('surname');
  117 + result.should.not.have.property('password');
  118 +
  119 + // Test the values make sense
  120 + result.name.should.equal('Nifty');
  121 + result.surname.should.equal('Lettuce');
  122 +
  123 + done();
  124 + });
  125 + });
  126 +
  127 +});
... ...
  1 +
  2 +// # tests - auth
  3 +
  4 +var util = require('util');
  5 +var request = require('supertest');
  6 +var app = require('../app');
  7 +var chai = require('chai');
  8 +var sinon = require('sinon');
  9 +var sinonChai = require('sinon-chai');
  10 +var expect = chai.expect;
  11 +var utils = require('./utils');
  12 +var async = require('async');
  13 +var IoC = require('electrolyte');
  14 +var cheerio = require('cheerio');
  15 +
  16 +chai.should();
  17 +chai.use(sinonChai);
  18 +
  19 +var agent = request.agent(app);
  20 +request = request(app);
  21 +
  22 +// storage for context-specific variables throughout the tests
  23 +var context = {};
  24 +
  25 +describe('auth', function() {
  26 +
  27 + var User = IoC.create('models/user');
  28 +
  29 + // Clean DB and add 3 sample users before tests start
  30 + before(function(done) {
  31 + async.waterfall([
  32 + utils.cleanDatabase,
  33 + function createTestUsers(callback) {
  34 + // Create 3 test users
  35 + async.timesSeries(3, function(i, _callback) {
  36 + var user = new User({
  37 + email: 'email+' + i + '@example.com',
  38 + name: 'User #' + i,
  39 + surname: 'Last Name #' + i,
  40 + password: '1234' + i
  41 + });
  42 +
  43 + user.save(_callback);
  44 + }, callback);
  45 + }
  46 + ], done);
  47 + });
  48 +
  49 + // Clean DB after all tests are done
  50 + after(function(done) {
  51 + utils.cleanDatabase(done);
  52 + });
  53 +
  54 + it('GET /my-account — should redirect me to /login and show error without login', function(done) {
  55 + agent
  56 + .get('/my-account')
  57 + .accept('text/html')
  58 + .expect(302)
  59 + .end(function(err, res) {
  60 + if (err) return done(err);
  61 +
  62 + // Test the attributes exist
  63 + expect(res.headers.location).to.exist;
  64 +
  65 + // Test the values make sense
  66 + res.headers.location.should.equal('/login');
  67 +
  68 + done();
  69 + });
  70 + });
  71 +
  72 + it('GET /signup — should show me email and password form fields', function(done) {
  73 + agent
  74 + .get('/signup')
  75 + .accept('text/html')
  76 + .expect(200)
  77 + .end(function(err, res) {
  78 + if (err) return done(err);
  79 +
  80 + // Test the attributes exist
  81 + expect(res.text).to.exist;
  82 +
  83 + var $ = cheerio.load(res.text);
  84 + var $container = $('.container form');
  85 +
  86 + // Test the values make sense
  87 + $container.should.have.length.of(1);
  88 + $container.find('input[name="email"]').should.have.length.of.least(1);
  89 + $container.find('input[name="password"]').should.have.length.of.least(1);
  90 + $container.find('button[type="submit"]').should.have.length.of.least(1);
  91 +
  92 + // Save for later use
  93 + context.csrf = $container.find('input[name="_csrf"]').val();
  94 +
  95 + done();
  96 + });
  97 + });
  98 +
  99 + it('POST /signup — should create an account and redirect me to /my-account', function(done) {
  100 +
  101 + // This does take a couple of seconds on average
  102 + this.timeout(5000);
  103 +
  104 + agent
  105 + .post('/signup')
  106 + .send({
  107 + _csrf: context.csrf,
  108 + email: 'test+something@example.com',
  109 + name: 'Test',
  110 + surname: 'Something',
  111 + password: '123a-c456'
  112 + })
  113 + .accept('text/html')
  114 + .expect(302)
  115 + .end(function(err, res) {
  116 + if (err) return done(err);
  117 +
  118 + // Test the attributes exist
  119 + expect(res.headers.location).to.exist;
  120 +
  121 + // Test the values make sense
  122 + res.headers.location.should.equal('/my-account');
  123 +
  124 + // Test we can fetch the user from the DB
  125 + User.findOne({
  126 + email: 'test+something@example.com'
  127 + }, function(err, user) {
  128 + if (err) return done(err);
  129 +
  130 + expect(user).to.exist;
  131 +
  132 + user.should.have.property('name');
  133 + user.name.should.equal('Test');
  134 +
  135 + done();
  136 + });
  137 + });
  138 + });
  139 +
  140 + it('GET /login — should redirect me to / if logged in', function(done) {
  141 + agent
  142 + .get('/login')
  143 + .accept('text/html')
  144 + .expect(302)
  145 + .end(function(err, res) {
  146 + if (err) return done(err);
  147 +
  148 + // Test the attributes exist
  149 + expect(res.headers.location).to.exist;
  150 +
  151 + // Test the values make sense
  152 + res.headers.location.should.equal('/');
  153 +
  154 + done();
  155 + });
  156 + });
  157 +
  158 + it('GET /logout — should log me out and redirect me to /', function(done) {
  159 + agent
  160 + .get('/logout')
  161 + .accept('text/html')
  162 + .expect(302)
  163 + .end(function(err, res) {
  164 + if (err) return done(err);
  165 +
  166 + // Test the attributes exist
  167 + expect(res.headers.location).to.exist;
  168 +
  169 + // Test the values make sense
  170 + res.headers.location.should.equal('/');
  171 +
  172 + done();
  173 + });
  174 + });
  175 +
  176 + it('GET /login — should show me email and password form fields', function(done) {
  177 + agent
  178 + .get('/login')
  179 + .accept('text/html')
  180 + .expect(200)
  181 + .end(function(err, res) {
  182 + if (err) return done(err);
  183 +
  184 + // Test the attributes exist
  185 + expect(res.text).to.exist;
  186 +
  187 + var $ = cheerio.load(res.text);
  188 + var $container = $('.container form');
  189 +
  190 + // Test the values make sense
  191 + $container.should.have.length.of(1);
  192 + $container.find('input[name="email"]').should.have.length.of.least(1);
  193 + $container.find('input[name="password"]').should.have.length.of.least(1);
  194 + $container.find('button[type="submit"]').should.have.length.of.least(1);
  195 +
  196 + // Save for later use
  197 + context.csrf = $container.find('input[name="_csrf"]').val();
  198 +
  199 + done();
  200 + });
  201 + });
  202 +
  203 + it('POST /login — should log me in and redirect me to /', function(done) {
  204 + agent
  205 + .post('/login')
  206 + .send({
  207 + _csrf: context.csrf,
  208 + email: 'test+something@example.com',
  209 + password: '123a-c456'
  210 + })
  211 + .accept('text/html')
  212 + .expect(302)
  213 + .end(function(err, res) {
  214 + if (err) return done(err);
  215 +
  216 + // Test the attributes exist
  217 + expect(res.headers.location).to.exist;
  218 +
  219 + // Test the values make sense
  220 + res.headers.location.should.equal('/');
  221 +
  222 + done();
  223 + });
  224 + });
  225 +
  226 + it('GET /my-account — should show me my email', function(done) {
  227 + agent
  228 + .get('/my-account')
  229 + .accept('text/html')
  230 + .expect(200)
  231 + .end(function(err, res) {
  232 + if (err) return done(err);
  233 +
  234 + // Test the attributes exist
  235 + expect(res.text).to.exist;
  236 +
  237 + var $ = cheerio.load(res.text);
  238 + var $container = $('.container');
  239 +
  240 + // Test the values make sense
  241 + $container.should.have.length.of(1);
  242 + $container.find('h1').text().should.equal('My Account');
  243 + $container.find('h3').eq(0).text().should.equal('Email: test+something@example.com');
  244 + $container.find('h3').eq(1).text().should.equal('Name: Test Something');
  245 +
  246 + done();
  247 + });
  248 + });
  249 +
  250 +});
... ...
  1 +var chai = require('chai');
  2 +chai.should();
... ...
  1 +var IoC = require('electrolyte');
  2 +var path = require('path');
  3 +var fs = require('fs');
  4 +var async = require('async');
  5 +
  6 +var modelsPath = path.join(__dirname, '..', 'app', 'models');
  7 +
  8 +var files = fs.readdirSync(modelsPath);
  9 +var models = [];
  10 +for (var i = 0; i < files.length; i++) {
  11 + var model = IoC.create('models/'+path.basename(files[i], '.js'));
  12 + models.push(model);
  13 +}
  14 +
  15 +exports.cleanDatabase = function(callback) {
  16 + async.eachSeries(models, function(model, next) {
  17 + model.remove({}, next);
  18 + }, callback);
  19 +};
... ...
  1 +var async = require('async');
  2 +
  3 +exports = module.exports = function (logger, rest) {
  4 +
  5 + function strategy(req, username, password, done) {
  6 + var user = {
  7 + refreshToken: "",
  8 + token: "",
  9 + service_catalog: {},
  10 + user_info: {},
  11 + err: null
  12 + };
  13 + async.waterfall([
  14 + function (callback) {//get temp token
  15 + logger.info("get temp token");
  16 + var tempParams = {
  17 + "grant_type": req.body.grant_type,
  18 + "username": req.body.username,
  19 + "scope": req.body.scope,
  20 + "password": req.body.password,
  21 + "img_code": req.body.img_code,
  22 + };
  23 + if (req.body.smscode)
  24 + tempParams['sms_code'] = req.body.smscode;
  25 +
  26 + logger.info("url:" + rest.getBaseUrl('auth/tokens', 'uaa'));
  27 + logger.info("params", tempParams);
  28 + console.log(tempParams)
  29 + rest.restful.postJson(rest.getBaseUrl('auth/tokens', 'uaa'), tempParams, {
  30 + headers: { 'Content-Type': 'application/json', "Accept": "application/json" }
  31 + })
  32 + .on('success', function (data, response) {
  33 + logger.info("tokens-success", data);
  34 + if (data.access_token) {
  35 + user.token = data.access_token;
  36 + user.refreshToken = data.refresh_token;
  37 + user.user_info = {
  38 + 'user': data.user,
  39 + 'tenant': data.tenant,
  40 + 'perms': [],
  41 + 'scope': data.scope,
  42 + 'oss': {}
  43 + };
  44 + user.service_catalog = data.service_catalog
  45 + callback(null, data)
  46 + } else {
  47 + var err = new Error('name or pass err');
  48 + user.err = data.message;
  49 + callback(err, data);
  50 + }
  51 + }).on('error', function (err, response) {
  52 + // logger.info("tokens-error",data);
  53 + var err = new Error('name or pass err');
  54 + callback(err, response);
  55 + }).on('fail', function (data, response) {
  56 + logger.info("tokens-fail", data);
  57 + var err = new Error('name or pass err');
  58 + callback(data, response);
  59 + });
  60 + }], function (err, result) {
  61 + logger.info(err);
  62 + if (err) {
  63 + return done(null, false, err);
  64 + } else {
  65 + return done(null, user);
  66 + }
  67 + });
  68 + }
  69 +
  70 + function serializeUser(user, done) {
  71 + logger.info("passport.serializeUser");
  72 + done(null, user);
  73 + }
  74 +
  75 + function deserializeUser(user, done) {
  76 + var user = {
  77 + refreshToken: "",
  78 + token: "",
  79 + info: {},
  80 + err: null
  81 + };
  82 + console.info("passport.deserializeUser");
  83 + done(null, user);
  84 + }
  85 +
  86 + return {
  87 + strategy: strategy,
  88 + serializeUser: serializeUser,
  89 + deserializeUser: deserializeUser
  90 + };
  91 +};
  92 +
  93 +exports['@singleton'] = true;
  94 +exports['@require'] = ['igloo/logger', 'utils/rest'];
... ...
  1 +var rest = require('restler');
  2 +var async = require('async');
  3 +var uuid = require('uuid/v4');
  4 +var restq = require('restler-q');
  5 +var http = require("http");
  6 +var qs = require("qs");
  7 +
  8 +
  9 +function RestHelper(logger, settings) {
  10 + this.logger = logger;
  11 + this.settings = settings;
  12 + this.restTasks = {};
  13 +}
  14 +
  15 +RestHelper.prototype = {
  16 + getUrl: function (url, baseUrl) {
  17 + var base = this.settings.restful.url + baseUrl + this.settings.restful.version + "/" + url;
  18 + return base;
  19 + },
  20 + preLog: function (tempUrl, tempParams) {
  21 +
  22 + },
  23 + checkJson: function (type) {
  24 + if (type === 'patchJson' || type === 'putJson' || type === 'postJson' || type === 'json') {
  25 + return true;
  26 + } else {
  27 + return false;
  28 + }
  29 + },
  30 + reflashToken: function (data, respones, taskId) {
  31 + // var self=this,method=self.restTasks[taskId].type,context=self.restTasks[taskId].context,req=context.req,res=context.res;
  32 + // if(req.session.passport&&req.session.passport.user&&req.session.passport.user.token&&req.session.passport.user.user_info){
  33 + // var tempParams={
  34 + // 'grant_type':'refresh_token',
  35 + // 'refresh_token':req.session.passport.user.refreshToken,
  36 + // 'account':req.session.passport.user.user_info.tenant_id
  37 + // };
  38 + // rest.postJson(self.getUrl('auth/tokens'),tempParams,{
  39 + // headers: { 'Content-Type': 'application/json','Accept': 'application/json' }})
  40 + // .on('success',function(data,response){
  41 + // console.log(data);
  42 + // console.log(req.session);
  43 + // if(data.access_token){
  44 + // req.session.passport.user.token=data.access_token;
  45 + // req.session.passport.user.refreshToken=data.refresh_token;
  46 + // req.session.save(function(err){ console.log(err);});
  47 + // if(self.checkJson(method)){
  48 + // context.options.accessToken=req.session.passport.user.token;
  49 + // rest[method](context.url,context.data,context.options)
  50 + // .on('success',function(data,response){
  51 + // delete self.restTasks[taskId];
  52 + // if(context.asyncMap){
  53 + // context.callback(null, data);
  54 + // }else{
  55 + // context.callback(data,response);
  56 + // }
  57 + // })
  58 + // .on('fail',function(data,response){
  59 + // self.fail(data,response,req,res);
  60 + // if(context.asyncMap){
  61 + // context.callback(null, data);
  62 + // }else{
  63 + // context.callback(data,response);
  64 + // }
  65 + // });
  66 + // }else{
  67 + // context.data.accessToken=req.session.passport.user.token;
  68 + // rest[method](context.url,context.data)
  69 + // .on('success',function(data,response){
  70 + // delete self.restTasks[taskId];
  71 + // if(context.asyncMap){
  72 + // context.callback(null, data);
  73 + // }else{
  74 + // context.callback(data,response);
  75 + // }
  76 + // })
  77 + // .on('fail',function(data,response){
  78 + // self.fail(data,response,req,res);
  79 + // if(context.asyncMap){
  80 + // context.callback(null, data);
  81 + // }else{
  82 + // context.callback(data,response);
  83 + // }
  84 + // });
  85 + // }
  86 + // }else{
  87 + // data = data||{};
  88 + // data.redirect='/signIn';
  89 + // }
  90 + // }).on('fail',function(data,response){
  91 + // data = data||{};
  92 + // data.redirect='/signIn';
  93 + // });
  94 + // }
  95 + },
  96 + params: function (context, type) {
  97 + var self = this;
  98 + var tempData = context.params || {};
  99 + var tempOptions = context.options || {};
  100 + var tempHead = context.headers || {};
  101 + var req = context.req, res = context.res;
  102 + res.resultMsg = res.resultMsg || [];
  103 + var ip = req.ip.match(/\d+\.\d+\.\d+\.\d+/)[0];
  104 + tempHead['SXClientIP'] = ip;
  105 + tempHead['Client-Ip'] = ip;
  106 + var tempParams = {
  107 + data: tempData,
  108 + headers: tempHead,
  109 + timeout: 1000 * 60 * 10
  110 + };
  111 + context.options.headers = tempHead;
  112 + // self.logger.info('req.session.passport.user.token:',req.session.passport.user.token);
  113 + if (type === 'json') {
  114 + tempParams = context.params || {};
  115 + tempOptions = context.options || {};
  116 + if (!context.excludeToken) {
  117 + tempOptions.accessToken = req.session.passport.user.token;
  118 + }
  119 + if (context.useUrl) {
  120 + self.preLog(context.url, tempParams);
  121 + } else {
  122 + self.preLog(self.getUrl(context.url, context.baseUrl), tempParams);
  123 + }
  124 + } else {
  125 + if (!context.excludeToken) {
  126 + tempParams.accessToken = req.session.passport.user.token;
  127 + }
  128 + self.preLog(self.getUrl(context.url, context.baseUrl), tempData);
  129 + }
  130 + tempOptions['timeout'] = 1000 * 60 * 10;
  131 + return {
  132 + url: context.useUrl ? context.url : self.getUrl(context.url, context.baseUrl),
  133 + data: tempParams,
  134 + options: tempOptions,
  135 + callback: context.callback,
  136 + req: req,
  137 + res: res
  138 + };
  139 + },
  140 + addTask: function (type, context, data, response) {
  141 + var self = this;
  142 + var id = self.generateID();
  143 + self.restTasks[id] = {
  144 + 'type': type,
  145 + 'context': context
  146 + };
  147 + // self.reflashToken(data,response,id);
  148 + },
  149 + generateID: function () {
  150 + return uuid();
  151 + },
  152 + error: function (err, respones, req, res) {
  153 + this.logger.info('this have a err! Maby connection aborted,parse,encoding,decoding failed or some other unhandled errors');
  154 + this.logger.error(err);
  155 +
  156 + },
  157 + fail: function (data, respones, req, res) {
  158 + this.logger.info('request is fail!');
  159 + this.logger.info(respones.statusCode);
  160 + this.logger.error(data);
  161 + res.resultMsg.push(data);
  162 + }
  163 +};
  164 +
  165 +
  166 +
  167 +exports = module.exports = function (logger, settings) {
  168 + var helper = new RestHelper(logger, settings);
  169 + function _getUrl(url, baseUrl) {
  170 + return helper.getUrl(url, baseUrl);
  171 + }
  172 +
  173 + function _preLog(tempUrl, tempParams) {
  174 + helper.preLog(tempUrl, tempParams);
  175 + }
  176 +
  177 + function _error(err, respones) {
  178 + logger.info('this have a err! Maby connection aborted,parse,encoding,decoding failed or some other unhandled errors');
  179 + logger.error(err);
  180 + return
  181 + }
  182 +
  183 + function _fail(data, respones) {
  184 + logger.info('request is fail!');
  185 + logger.info(respones.statusCode);
  186 + logger.info(data);
  187 + return
  188 + }
  189 +
  190 + function restClient(options, success, fail) {
  191 + var postData = !options.params ? '' : options.params;
  192 + var httpRequest = http.request(options, function (res) {
  193 + var _data = '';
  194 + res.setEncoding('utf8');
  195 + res.on('data', function (chunk) {
  196 + _data += chunk;
  197 + });
  198 + res.on('end', function () {
  199 + success(_data, res);
  200 + });
  201 + });
  202 + httpRequest.on('error', function (e) {
  203 + fail(e);
  204 + });
  205 + httpRequest.write(postData);
  206 + httpRequest.end();
  207 + }
  208 +
  209 + function get(context) {
  210 + var param = helper.params(context);
  211 + rest.get(param.url, param.data)
  212 + .on('success', context.callback)
  213 + .on('fail', function (data, response) {
  214 + if (response.statusCode === 401) {
  215 + helper.addTask('get', param, data, response);
  216 + } else {
  217 + _fail(data, response);
  218 + context.callback(data, response);
  219 + }
  220 + });
  221 + }
  222 +
  223 + function post(context) {
  224 + var param = helper.params(context);
  225 + rest.post(param.url, param.data)
  226 + .on('success', context.callback)
  227 + .on('fail', function (data, response) {
  228 + if (response.statusCode === 401) {
  229 + helper.addTask('post', param, data, response);
  230 + } else {
  231 + _fail(data, response);
  232 + context.callback(data, response);
  233 + }
  234 + });
  235 + }
  236 + function put(context) {
  237 + var param = helper.params(context);
  238 + rest.put(param.url, param.data)
  239 + .on('success', context.callback)
  240 + .on('fail', function (data, response) {
  241 + if (response.statusCode === 401) {
  242 + helper.addTask('put', param, data, response);
  243 + } else {
  244 + _fail(data, response);
  245 + context.callback(data, response);
  246 + }
  247 + });
  248 + }
  249 + function del(context) {
  250 + var param = helper.params(context);
  251 + if (param.data && param.data.data)
  252 + param.data.data = JSON.stringify(param.data.data);
  253 + rest.del(param.url, param.data)
  254 + .on('success', context.callback)
  255 + .on('fail', function (data, response) {
  256 + if (response.statusCode === 401) {
  257 + helper.addTask('del', param, data, response);
  258 + } else {
  259 + _fail(data, response);
  260 + context.callback(data, response);
  261 + }
  262 + });
  263 + }
  264 +
  265 + function patch(context) {
  266 + var param = helper.params(context);
  267 + rest.patch(param.url, param.data)
  268 + .on('success', context.callback)
  269 + .on('fail', function (data, response) {
  270 + if (response.statusCode === 401) {
  271 + helper.addTask('patch', param, data, response);
  272 + } else {
  273 + _fail(data, response);
  274 + context.callback(data, response);
  275 + }
  276 + });
  277 + }
  278 +
  279 + function json(context) {
  280 + var param = helper.params(context, 'json');
  281 + rest.json(param.url, param.data, param.options)
  282 + .on('success', context.callback)
  283 + .on('fail', function (data, response) {
  284 + if (response.statusCode === 401) {
  285 + helper.addTask('json', param, data, response);
  286 + } else {
  287 + _fail(data, response);
  288 + context.callback(data, response);
  289 + }
  290 + });
  291 + }
  292 + function postJson(context) {
  293 + var param = helper.params(context, 'json');
  294 + rest.postJson(param.url, param.data, param.options)
  295 + .on('success', context.callback)
  296 + .on('fail', function (data, response) {
  297 + if (response.statusCode === 401) {
  298 + helper.addTask('postJson', param, data, response);
  299 + } else {
  300 + _fail(data, response);
  301 + context.callback(data, response);
  302 + }
  303 + });
  304 + }
  305 +
  306 + function register(context) {
  307 + var param = helper.params(context, 'json');
  308 + rest.postJson(param.url, param.data, param.options)
  309 + .on('success', context.callback)
  310 + .on('fail', function (data, response) {
  311 + _fail(data, response);
  312 + context.callback(data, response);
  313 + });
  314 + }
  315 +
  316 + function putJson(context) {
  317 + var param = helper.params(context, 'json');
  318 + rest.putJson(param.url, param.data, param.options)
  319 + .on('success', context.callback)
  320 + .on('fail', function (data, response) {
  321 + if (response.statusCode === 401) {
  322 + helper.addTask('putJson', param, data, response);
  323 + } else {
  324 + _fail(data, response);
  325 + context.callback(data, response);
  326 + }
  327 + });
  328 + }
  329 +
  330 + function patchJson(context) {
  331 + var param = helper.params(context, 'json');
  332 + rest.patchJson(param.url, param.data, param.options)
  333 + .on('success', context.callback)
  334 + .on('fail', function (data, response) {
  335 + if (response.statusCode === 401) {
  336 + helper.addTask('patchJson', param, data, response);
  337 + } else {
  338 + _fail(data, response);
  339 + context.callback(data, response);
  340 + }
  341 + });
  342 + }
  343 +
  344 + function asyncMap(contexts, cb) {
  345 + var AsyncLibrary = {
  346 + sendRequest: function (number, callback) {
  347 + var context = number;
  348 + var tempParams = context.params || {};
  349 + var tempOptions = context.options || {};
  350 + var req = context.req, res = context.res;
  351 + res.resultMsg = res.resultMsg || [];
  352 + if (!context.excludeToken) {
  353 + tempOptions.accessToken = req.session.passport.user.token;
  354 + }
  355 + _preLog(_getUrl(context.url, context.baseUrl), tempParams);
  356 + rest[context.method](_getUrl(context.url, context.baseUrl), tempParams, tempOptions)
  357 + .on('success', function (data, response) {
  358 + callback(null, data);
  359 + })
  360 + .on('fail', function (data, response) {
  361 + if (response.statusCode === 401) {
  362 + var param = helper.params(context, 'json');
  363 + param.callback = callback;
  364 + param.asyncMap = true;
  365 + helper.addTask(context.method, param, data, response);
  366 + } else {
  367 + callback(null, data);
  368 + }
  369 + });
  370 + }
  371 + };
  372 + async.map(contexts, AsyncLibrary.sendRequest, cb);
  373 + }
  374 +
  375 + function transformParams(jsonParams) {
  376 + var params = ['?'];
  377 + for (var i in jsonParams) {
  378 + params.push(i + '=' + jsonParams[i] + '&');
  379 + }
  380 + return params.join('').substring(0, params.join('').length - 1);
  381 + }
  382 +
  383 + function getFormFields(context) {
  384 + return restq.get(helper.getUrl(context.url, context.baseUrl), {
  385 + accessToken: context.params.token
  386 + })
  387 + }
  388 +
  389 + function initOssToken(context) {
  390 + return restq.postJson(helper.getUrl(context.url, context.baseUrl), context.params, {
  391 + accessToken: context.options.token
  392 + });
  393 + }
  394 +
  395 + return {
  396 + get: get,
  397 + post: post,
  398 + put: put,
  399 + del: del,
  400 + patch: patch,
  401 + json: json,
  402 + postJson: postJson,
  403 + putJson: putJson,
  404 + patchJson: patchJson,
  405 + transformParams: transformParams,
  406 + register: register,
  407 + restful: rest,
  408 + getBaseUrl: _getUrl,
  409 + map: asyncMap,
  410 + getFormFields: getFormFields,
  411 + initOssToken: initOssToken,
  412 + restClient: restClient
  413 + };
  414 +};
  415 +
  416 +
  417 +
  418 +
  419 +exports['@singleton'] = true;
  420 +exports['@require'] = ['igloo/logger', 'igloo/settings'];
... ...
注册登录 后发表评论