正在显示
23 个修改的文件
包含
4690 行增加
和
0 行删除
app.js
0 → 100644
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; |
boot/config.js
0 → 100644
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; |
boot/local.js
0 → 100755
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; |
boot/policies.js
0 → 100644
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' ]; |
cluster.js
0 → 100644
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); |
controllers/api.js
0 → 100644
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']; |
controllers/auth.js
0 → 100644
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"]; |
controllers/authed.js
0 → 100644
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']; |
controllers/file.js
0 → 100644
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']; |
controllers/mock.js
0 → 100644
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']; |
controllers/robot.js
0 → 100644
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']; |
etc/init/01-settings.js
0 → 100644
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' ]; |
etc/init/02-middleware.js
0 → 100644
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']; |
etc/init/03-sessions.js
0 → 100644
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' ]; |
etc/init/04-security.js
0 → 100644
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' ]; |
etc/init/05-caching.js
0 → 100644
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' ]; |
etc/init/06-views.js
0 → 100644
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' ]; |
json/mockDate.json
0 → 100644
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 | +}] |
json/payRoll.json
0 → 100644
此 diff 太大无法显示。
models/user.js
0 → 100644
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' ]; |
package.json
0 → 100644
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 | +} |
routes/api.js
0 → 100644
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; |
请
注册
或
登录
后发表评论