正在显示
34 个修改的文件
包含
4771 行增加
和
0 行删除
.babelrc
0 → 100644
.gitignore
0 → 100644
1 | +.idea/ | ||
2 | +node_modules/ | ||
3 | +temp_build/ | ||
4 | +build/ | ||
5 | +.sass-cache/ | ||
6 | +npm-debug.log | ||
7 | +*.json.gzip | ||
8 | +npm-debug.log.* | ||
9 | +*.rdb | ||
10 | +manifest.json | ||
11 | +src/public/vendor.*.js | ||
12 | +yarn.lock | ||
13 | +igloo.log | ||
14 | +nohup.out | ||
15 | +package-lock.json | ||
16 | +npm-packages-offline-cache/ | ||
17 | +npm-packages-offline-cache.* | ||
18 | +server/views/index.ejs | ||
19 | +server/boot/local.js |
.project
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<projectDescription> | ||
3 | + <name>hro</name> | ||
4 | + <comment></comment> | ||
5 | + <projects> | ||
6 | + </projects> | ||
7 | + <buildSpec> | ||
8 | + <buildCommand> | ||
9 | + <name>com.aptana.editor.php.aptanaPhpBuilder</name> | ||
10 | + <arguments> | ||
11 | + </arguments> | ||
12 | + </buildCommand> | ||
13 | + <buildCommand> | ||
14 | + <name>com.aptana.ide.core.unifiedBuilder</name> | ||
15 | + <arguments> | ||
16 | + </arguments> | ||
17 | + </buildCommand> | ||
18 | + </buildSpec> | ||
19 | + <natures> | ||
20 | + <nature>com.aptana.projects.webnature</nature> | ||
21 | + <nature>com.aptana.editor.php.phpNature</nature> | ||
22 | + </natures> | ||
23 | + <filteredResources> | ||
24 | + <filter> | ||
25 | + <id>1506651609675</id> | ||
26 | + <name></name> | ||
27 | + <type>26</type> | ||
28 | + <matcher> | ||
29 | + <id>org.eclipse.ui.ide.multiFilter</id> | ||
30 | + <arguments>1.0-name-matches-false-false-node_modules</arguments> | ||
31 | + </matcher> | ||
32 | + </filter> | ||
33 | + </filteredResources> | ||
34 | +</projectDescription> |
.yarnrc
0 → 100644
gulpfile.js
0 → 100644
1 | +var gulp = require('gulp'); | ||
2 | +var compass = require('gulp-compass'); | ||
3 | +var del = require('del'); | ||
4 | +var gulpFilter = require('gulp-filter'); | ||
5 | +// var webpack = require('webpack-stream'); | ||
6 | +// var webpackConfig = require('./tools/webpack.config.production.js'); | ||
7 | + | ||
8 | +var paths={ | ||
9 | + sass:['./src/scss/*.scss','./src/scss/**/*.scss'] | ||
10 | +}; | ||
11 | + | ||
12 | +gulp.task('compass', function() { | ||
13 | + gulp.src(paths.sass) | ||
14 | + .pipe(compass({ | ||
15 | + sourcemap:true, | ||
16 | + css: './src/public/css', | ||
17 | + sass: './src/scss', | ||
18 | + image:'./src/public/img' | ||
19 | + })) | ||
20 | + .pipe(gulp.dest('./build/public/css')); | ||
21 | +}); | ||
22 | + | ||
23 | +gulp.task('watch',function(){ | ||
24 | + gulp.watch(paths.sass,['compass']); | ||
25 | +}); | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | +gulp.task('clean',function(){ | ||
30 | + return del([ | ||
31 | + '.tmp', | ||
32 | + 'build/*', | ||
33 | + '!build/.git' | ||
34 | + ],{ | ||
35 | + force: true | ||
36 | + }); | ||
37 | + | ||
38 | +}); | ||
39 | + | ||
40 | +gulp.task('copy',['clean'],function(){ | ||
41 | + var f=gulpFilter(['src/public','src/public/**/*','package.json','src/content','src/content/**/*']); | ||
42 | + return gulp.src([ | ||
43 | + './package.json', | ||
44 | + './src/**/*' | ||
45 | + ]) | ||
46 | + .pipe(f) | ||
47 | + .pipe(gulp.dest('./build')); | ||
48 | +}); | ||
49 | + | ||
50 | +/*copy vendor*/ | ||
51 | +gulp.task('copy-vendor',function(){ | ||
52 | + return gulp.src([ | ||
53 | + './src/public/vendor.*.js' | ||
54 | + ]) | ||
55 | + .pipe(gulp.dest('./build/public')); | ||
56 | +}); | ||
57 | + | ||
58 | +gulp.task('start',['copy'],function(done){ | ||
59 | + runBundle('npm start', done); | ||
60 | +}); | ||
61 | + | ||
62 | + | ||
63 | +gulp.task('build',['copy'],function(){ | ||
64 | + return gulp.src(webpackConfig.entry.app) | ||
65 | + .pipe(webpack(webpackConfig)) | ||
66 | + .pipe(gulp.dest('./build/public')); | ||
67 | +}); | ||
68 | + | ||
69 | +gulp.task('deploy',['build'],function(done){ | ||
70 | + runBundle('node ./server/app.js', done); | ||
71 | +}); | ||
72 | + | ||
73 | + | ||
74 | +function runBundle(cmd, done) { | ||
75 | + var exec = require('child_process').exec; | ||
76 | + var ls=exec(cmd, function(e, stdout) { | ||
77 | + done(); | ||
78 | + }); | ||
79 | + | ||
80 | + ls.stdout.on('data', function (data) { | ||
81 | + console.log(data); | ||
82 | + }); | ||
83 | + | ||
84 | + ls.stderr.on('data', function (data) { | ||
85 | + console.log(data); | ||
86 | + }); | ||
87 | + | ||
88 | + ls.on('exit', function (code) { | ||
89 | + console.log('child process exited with code ' + code); | ||
90 | + }); | ||
91 | + | ||
92 | + ls.on('uncaughtException', function (err) { | ||
93 | + console.log('Caught exception: ' + err); | ||
94 | + }); | ||
95 | +} | ||
96 | + | ||
97 | + | ||
98 | + | ||
99 | + |
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "krhr", | ||
3 | + "version": "0.0.20", | ||
4 | + "description": "this framework for krhr company!", | ||
5 | + "main": "./build/index.js", | ||
6 | + "engines": { | ||
7 | + "node": ">=5.0 <6", | ||
8 | + "npm": ">=3.3 <4" | ||
9 | + }, | ||
10 | + "scripts": { | ||
11 | + "remove-temp": "better-npm-run remove-temp", | ||
12 | + "clean": "better-npm-run clean", | ||
13 | + "start": "better-npm-run start", | ||
14 | + "compile": "better-npm-run compile", | ||
15 | + "compile:dll": "better-npm-run compile-dll", | ||
16 | + "deploy": "better-npm-run deploy", | ||
17 | + "deploy:all": "better-npm-run deploy-all", | ||
18 | + "publish": "better-npm-run service", | ||
19 | + "service": "better-npm-run service", | ||
20 | + "service:recruitIterative": "better-npm-run service-recruitIterative", | ||
21 | + "service:hroRecruit": "better-npm-run service-hroRecruit", | ||
22 | + "service:sipolicyIterative": "better-npm-run service-sipolicyIterative", | ||
23 | + "service:hroSipolicy": "better-npm-run service-hroSipolicy", | ||
24 | + "service:settlemgmIterative": "better-npm-run service-settlemgmIterative", | ||
25 | + "service:hroSettlemgm": "better-npm-run service-hroSettlemgm", | ||
26 | + "service:hroTemp": "better-npm-run service-hroTemp", | ||
27 | + "service:developTest": "better-npm-run service-developTest", | ||
28 | + "dev-start": "node-debug ./app.js", | ||
29 | + "prepublish": "npm prune", | ||
30 | + "test": "cross-env NODE_ENV=test karma start tools/karma.config.js", | ||
31 | + "test-cov": "NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require test/support/should test/", | ||
32 | + "test-travis": "NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require test/support/should test/", | ||
33 | + "test-circleci": "NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require test/support/should test/", | ||
34 | + "upgrade-master-version": "node tools/revision/upgrade-master-version.js", | ||
35 | + "upgrade-branch-version": "node tools/revision/upgrade-branch-version.js", | ||
36 | + "upgrade-patch-version": "node tools/revision/upgrade-patch-version.js" | ||
37 | + }, | ||
38 | + "betterScripts": { | ||
39 | + "remove-temp": { | ||
40 | + "command": "babel-node tools/run remove-temp-build --release", | ||
41 | + "env": { | ||
42 | + "NODE_ENV": "production", | ||
43 | + "DEBUG": "app:*" | ||
44 | + } | ||
45 | + }, | ||
46 | + "start": { | ||
47 | + "command": "node tools/revision/revoke-index-version.js && babel-node tools/run start", | ||
48 | + "env": { | ||
49 | + "NODE_ENV": "development", | ||
50 | + "DEBUG": "app:*" | ||
51 | + } | ||
52 | + }, | ||
53 | + "clean": { | ||
54 | + "command": "babel-node tools/run clean --release", | ||
55 | + "env": { | ||
56 | + "NODE_ENV": "production", | ||
57 | + "DEBUG": "app:*" | ||
58 | + } | ||
59 | + }, | ||
60 | + "compile": { | ||
61 | + "command": "babel-node tools/run compile --release", | ||
62 | + "env": { | ||
63 | + "NODE_ENV": "production", | ||
64 | + "DEBUG": "app:*" | ||
65 | + } | ||
66 | + }, | ||
67 | + "compile-dll": { | ||
68 | + "command": "babel-node tools/run compile-dll --release", | ||
69 | + "env": { | ||
70 | + "NODE_ENV": "production", | ||
71 | + "DEBUG": "app:*" | ||
72 | + } | ||
73 | + }, | ||
74 | + "deploy": { | ||
75 | + "command": "npm run clean && npm run compile && babel-node tools/run copy --release", | ||
76 | + "env": { | ||
77 | + "NODE_ENV": "production", | ||
78 | + "DEBUG": "app:*" | ||
79 | + } | ||
80 | + }, | ||
81 | + "deploy-all": { | ||
82 | + "command": "npm run remove-temp && npm run compile:dll && npm run compile && babel-node tools/run copy --release", | ||
83 | + "env": { | ||
84 | + "NODE_ENV": "production", | ||
85 | + "DEBUG": "app:*" | ||
86 | + } | ||
87 | + }, | ||
88 | + "publish": { | ||
89 | + "command": "npm run deploy && babel-node server/app.js", | ||
90 | + "env": { | ||
91 | + "NODE_ENV": "production", | ||
92 | + "DEBUG": "app:*" | ||
93 | + } | ||
94 | + }, | ||
95 | + "service": { | ||
96 | + "command": "babel-node server/app.js", | ||
97 | + "env": { | ||
98 | + "NODE_ENV": "production", | ||
99 | + "DEBUG": "app:*" | ||
100 | + } | ||
101 | + }, | ||
102 | + "service-recruitIterative": { | ||
103 | + "command": "babel-node server/app.js", | ||
104 | + "env": { | ||
105 | + "NODE_ENV": "recruitIterative", | ||
106 | + "DEBUG": "app:*" | ||
107 | + } | ||
108 | + }, | ||
109 | + "service-hroRecruit": { | ||
110 | + "command": "babel-node server/app.js", | ||
111 | + "env": { | ||
112 | + "NODE_ENV": "hroRecruit", | ||
113 | + "DEBUG": "app:*" | ||
114 | + } | ||
115 | + }, | ||
116 | + "service-sipolicyIterative": { | ||
117 | + "command": "pm2 start server/app.js -i max --name web-hro-sipolicy-iterative", | ||
118 | + "env": { | ||
119 | + "NODE_ENV": "sipolicyIterative", | ||
120 | + "DEBUG": "app:*" | ||
121 | + } | ||
122 | + }, | ||
123 | + "service-hroSipolicy": { | ||
124 | + "command": "babel-node server/app.js", | ||
125 | + "env": { | ||
126 | + "NODE_ENV": "hroSipolicy", | ||
127 | + "DEBUG": "app:*" | ||
128 | + } | ||
129 | + }, | ||
130 | + "service-settlemgmIterative": { | ||
131 | + "command": "babel-node server/app.js", | ||
132 | + "env": { | ||
133 | + "NODE_ENV": "settlemgmIterative", | ||
134 | + "DEBUG": "app:*" | ||
135 | + } | ||
136 | + }, | ||
137 | + "service-hroSettlemgm": { | ||
138 | + "command": "babel-node server/app.js", | ||
139 | + "env": { | ||
140 | + "NODE_ENV": "hroSettlemgm", | ||
141 | + "DEBUG": "app:*" | ||
142 | + } | ||
143 | + }, | ||
144 | + "service-hroTemp": { | ||
145 | + "command": "babel-node server/app.js", | ||
146 | + "env": { | ||
147 | + "NODE_ENV": "hroTemp", | ||
148 | + "DEBUG": "app:*" | ||
149 | + } | ||
150 | + }, | ||
151 | + "service-developTest": { | ||
152 | + "command": "babel-node server/app.js", | ||
153 | + "env": { | ||
154 | + "NODE_ENV": "test", | ||
155 | + "DEBUG": "app:*" | ||
156 | + } | ||
157 | + } | ||
158 | + }, | ||
159 | + "keywords": [ | ||
160 | + "hr", | ||
161 | + "kr" | ||
162 | + ], | ||
163 | + "peerDependencies": { | ||
164 | + "react": "^0.15", | ||
165 | + "react-dom": "^0.15" | ||
166 | + }, | ||
167 | + "dependencies": { | ||
168 | + "ali-oss": "^4.1.5", | ||
169 | + "antd": "^2.7.1", | ||
170 | + "antd-mobile": "^1.0.8", | ||
171 | + "blacklist": "^1.1.4", | ||
172 | + "bluebird": "^3.5.3", | ||
173 | + "co": "^4.6.0", | ||
174 | + "draft-js": "^0.10.5", | ||
175 | + "draftjs-to-html": "^0.8.4", | ||
176 | + "echarts": "^3.2.3", | ||
177 | + "element-resize-event": "^2.0.7", | ||
178 | + "fs": "0.0.2", | ||
179 | + "fullcalendar": "^2.6.1", | ||
180 | + "gregorian-calendar": "^4.1.2", | ||
181 | + "gregorian-calendar-format": "^4.1.1", | ||
182 | + "history": "^2.0.1", | ||
183 | + "html-to-draftjs": "^1.4.0", | ||
184 | + "jquery": "^2.2.1", | ||
185 | + "js-base64": "^2.3.2", | ||
186 | + "lunar-calendar": "^0.1.4", | ||
187 | + "moment": "^2.12.0", | ||
188 | + "path": "^0.12.7", | ||
189 | + "pinyin": "^2.7.1", | ||
190 | + "q": "^1.4.1", | ||
191 | + "rc-calendar": "^5.4.2", | ||
192 | + "rc-time-picker": "^1.1.3", | ||
193 | + "rc-trigger": "^1.2.0", | ||
194 | + "rc-util": "^3.1.3", | ||
195 | + "react": "^15.4.2", | ||
196 | + "react-addons-transition-group": "^0.14.7", | ||
197 | + "react-collapse": "^2.3.3", | ||
198 | + "react-custom-scrollbars": "^3.0.1", | ||
199 | + "react-datetime": "^2.1.0", | ||
200 | + "react-dnd": "^2.1.4", | ||
201 | + "react-dnd-html5-backend": "^2.1.2", | ||
202 | + "react-dom": "^15.4.2", | ||
203 | + "react-draft-wysiwyg": "^1.12.13", | ||
204 | + "react-emoji": "^0.4.1", | ||
205 | + "react-height": "^2.2.0", | ||
206 | + "react-list": "^0.7.18", | ||
207 | + "react-loadable": "^5.5.0", | ||
208 | + "react-month-picker": "^1.0.8", | ||
209 | + "react-motion": "^0.4.7", | ||
210 | + "react-redux": "^4.4.0", | ||
211 | + "react-router": "^2.8.1", | ||
212 | + "react-router-redux": "^4.0.5", | ||
213 | + "react-select": "^0.9.1", | ||
214 | + "react-spinkit": "^3.0.0", | ||
215 | + "react-textarea-autosize": "^3.3.0", | ||
216 | + "redux": "^3.3.1", | ||
217 | + "redux-form": "^6.4.3", | ||
218 | + "redux-thunk": "^2.0.1", | ||
219 | + "simditor": "^2.3.6", | ||
220 | + "simditor-emoji": "^2.1.0", | ||
221 | + "simditor-mention": "^2.0.7", | ||
222 | + "store2": "^2.3.2" | ||
223 | + }, | ||
224 | + "devDependencies": { | ||
225 | + "assets-webpack-plugin": "^3.5.1", | ||
226 | + "async": "^1.5.2", | ||
227 | + "autoprefixer": "^6.3.3", | ||
228 | + "autoprefixer-core": "^6.0.1", | ||
229 | + "babel-cli": "6.24.1", | ||
230 | + "babel-core": "6.24.1", | ||
231 | + "babel-eslint": "^5.0.4", | ||
232 | + "babel-loader": "^6.2.4", | ||
233 | + "babel-node-debug": "^2.0.0", | ||
234 | + "babel-plugin-add-module-exports": "^0.1.4", | ||
235 | + "babel-plugin-import": "1.2.1", | ||
236 | + "babel-plugin-object-assign": "^1.2.1", | ||
237 | + "babel-plugin-react-remove-properties": "^0.2.1", | ||
238 | + "babel-plugin-react-transform": "^2.0.2", | ||
239 | + "babel-plugin-transform-react-constant-elements": "^6.4.0", | ||
240 | + "babel-plugin-transform-react-remove-prop-types": "^0.2.3", | ||
241 | + "babel-plugin-transform-runtime": "^6.6.0", | ||
242 | + "babel-preset-env": "^1.4.0", | ||
243 | + "babel-preset-es2015": "^6.6.0", | ||
244 | + "babel-preset-react": "^6.5.0", | ||
245 | + "babel-preset-stage-0": "^6.5.0", | ||
246 | + "babel-preset-stage-3": "^6.3.13", | ||
247 | + "babel-register": "6.24.1", | ||
248 | + "babel-runtime": "6.23.0", | ||
249 | + "better-npm-run": "0.0.8", | ||
250 | + "body-parser": "^1.15.0", | ||
251 | + "bootable": "^0.2.4", | ||
252 | + "bootable-environment": "^0.2.0", | ||
253 | + "browser-sync": "^2.11.1", | ||
254 | + "chai": "^3.5.0", | ||
255 | + "chai-as-promised": "^7.1.1", | ||
256 | + "chai-enzyme": "^0.6.1", | ||
257 | + "chalk": "^1.1.1", | ||
258 | + "chance": "^1.0.1", | ||
259 | + "cheerio": "^0.20.0", | ||
260 | + "classnames": "^2.2.3", | ||
261 | + "commander": "^2.9.0", | ||
262 | + "compression": "^1.6.1", | ||
263 | + "connect": "^3.4.1", | ||
264 | + "connect-busboy": "0.0.2", | ||
265 | + "connect-ensure-login": "^0.1.1", | ||
266 | + "connect-flash": "^0.1.1", | ||
267 | + "cookie": "^0.2.3", | ||
268 | + "cookie-parser": "^1.4.1", | ||
269 | + "cross-env": "^5.1.1", | ||
270 | + "css-loader": "^0.28.7", | ||
271 | + "csscomb": "^3.1.8", | ||
272 | + "csurf": "^1.8.3", | ||
273 | + "del": "^2.2.0", | ||
274 | + "dirty-chai": "^2.0.1", | ||
275 | + "echarts": "^3.2.3", | ||
276 | + "ejs": "^2.4.1", | ||
277 | + "electrolyte": "0.0.6", | ||
278 | + "element-resize-event": "^2.0.7", | ||
279 | + "enzyme": "^2.8.2", | ||
280 | + "errorhandler": "^1.4.3", | ||
281 | + "es6-promise": "^3.1.2", | ||
282 | + "eslint": "^2.3.0", | ||
283 | + "eslint-config-airbnb": "^6.1.0", | ||
284 | + "eslint-loader": "^1.3.0", | ||
285 | + "eslint-plugin-react": "^4.2.0", | ||
286 | + "eventemitter3": "^1.1.1", | ||
287 | + "express": "^4.13.4", | ||
288 | + "express-session": "^1.13.0", | ||
289 | + "extract-text-webpack-plugin": "^3.0.2", | ||
290 | + "file-loader": "^0.8.5", | ||
291 | + "fs-extra": "^0.26.5", | ||
292 | + "gaze": "^0.5.2", | ||
293 | + "git-repository": "^0.1.1", | ||
294 | + "glob": "^7.0.3", | ||
295 | + "gulp": "^3.9.1", | ||
296 | + "gulp-babel": "^6.1.2", | ||
297 | + "gulp-compass": "^2.1.0", | ||
298 | + "gulp-filter": "^4.0.0", | ||
299 | + "happypack": "^4.0.1", | ||
300 | + "helmet": "^1.3.0", | ||
301 | + "html-webpack-plugin": "^2.30.1", | ||
302 | + "igloo": "git+http://gitlab.workai.com.cn/fanwh/igloo.git", | ||
303 | + "imagemin-pngquant": "^4.2.2", | ||
304 | + "isomorphic-fetch": "^2.2.1", | ||
305 | + "istanbul": "^0.4.2", | ||
306 | + "jest-cli": "^0.9.0", | ||
307 | + "jscs": "^2.11.0", | ||
308 | + "jshint-stylish": "^2.1.0", | ||
309 | + "less": "^2.7.2", | ||
310 | + "less-loader": "^4.0.5", | ||
311 | + "lodash": "^4.6.1", | ||
312 | + "method-override": "^2.3.5", | ||
313 | + "mixpanel": "^0.4.0", | ||
314 | + "mkdirp": "^0.5.1", | ||
315 | + "mocha": "^2.5.3", | ||
316 | + "ms": "^0.7.1", | ||
317 | + "multer": "^1.1.0", | ||
318 | + "multiline": "^1.0.2", | ||
319 | + "ncp": "^2.0.0", | ||
320 | + "passport": "^0.3.2", | ||
321 | + "passport-local": "^1.0.0", | ||
322 | + "pluralize": "^1.2.1", | ||
323 | + "postcss": "^6.0.13", | ||
324 | + "postcss-import": "^11.0.0", | ||
325 | + "postcss-loader": "^2.0.6", | ||
326 | + "precss": "^1.4.0", | ||
327 | + "react-addons-test-utils": "^15.5.1", | ||
328 | + "react-transform-catch-errors": "^1.0.2", | ||
329 | + "react-transform-hmr": "^1.0.4", | ||
330 | + "recluster": "^0.4.5", | ||
331 | + "redbox-react": "^1.2.2", | ||
332 | + "redux-devtools": "^3.1.1", | ||
333 | + "redux-devtools-dock-monitor": "^1.1.0", | ||
334 | + "redux-devtools-log-monitor": "^1.0.5", | ||
335 | + "redux-logger": "^3.0.6", | ||
336 | + "replace": "^0.3.0", | ||
337 | + "resolve-url-loader": "^1.4.3", | ||
338 | + "response-time": "^2.3.1", | ||
339 | + "restler": "^3.4.0", | ||
340 | + "restler-q": "^0.1.1", | ||
341 | + "rimraf": "^2.5.2", | ||
342 | + "run-sequence": "^1.1.5", | ||
343 | + "serve-favicon": "^2.3.0", | ||
344 | + "serve-static": "^1.10.2", | ||
345 | + "sinon": "^2.2.0", | ||
346 | + "sinon-chai": "^2.10.0", | ||
347 | + "source-map-support": "^0.4.0", | ||
348 | + "strength": "^0.1.4", | ||
349 | + "style-loader": "^0.17.0", | ||
350 | + "supertest": "^1.2.0", | ||
351 | + "svg-sprite-loader": "^0.3.1", | ||
352 | + "through2": "^2.0.1", | ||
353 | + "tiny-lr": "^0.2.1", | ||
354 | + "uglifyjs-webpack-plugin": "^1.2.0", | ||
355 | + "underscore": "^1.8.3", | ||
356 | + "underscore.string": "^3.3.4", | ||
357 | + "update-notifier": "^0.6.1", | ||
358 | + "url-loader": "^0.5.7", | ||
359 | + "urlencode": "^1.1.0", | ||
360 | + "uuid": "^3.0.1", | ||
361 | + "validator": "^5.1.0", | ||
362 | + "webpack": "^3.11.0", | ||
363 | + "webpack-dev-middleware": "^1.12.0", | ||
364 | + "webpack-hot-middleware": "2.18.0", | ||
365 | + "webpack-parallel-uglify-plugin": "^1.0.2", | ||
366 | + "webpack-stream": "^3.1.0", | ||
367 | + "webpack-uglify-parallel": "^0.1.4", | ||
368 | + "winston-request-logger": "^1.0.7" | ||
369 | + }, | ||
370 | + "author": "fan", | ||
371 | + "license": "ISC" | ||
372 | +} |
server/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; |
server/boot/config.js
0 → 100644
1 | +// # config | ||
2 | + | ||
3 | +var path = require('path'); | ||
4 | + | ||
5 | +var parentDir = path.join(__dirname, '..', '..'); | ||
6 | +var appDir = path.join(parentDir, 'server'); | ||
7 | + | ||
8 | +var pkg = require(path.join(parentDir, 'package')); | ||
9 | + | ||
10 | +var assetsDir = path.join(parentDir, 'build'); | ||
11 | +var publicDir = path.join(assetsDir, 'public'); | ||
12 | +var templatesDir = path.join(assetsDir, 'emails'); | ||
13 | +var viewsDir = path.join(appDir, 'views'); | ||
14 | + | ||
15 | +var maxAge = 24 * 60 * 60 * 1000;//60 * 60 * 1000; | ||
16 | + | ||
17 | +exports = module.exports = function () { | ||
18 | + | ||
19 | + return { | ||
20 | + defaults: { | ||
21 | + basicAuth: { | ||
22 | + enabled: false, | ||
23 | + name: 'admin', | ||
24 | + pass: 'password' | ||
25 | + }, | ||
26 | + facebook: { | ||
27 | + enabled: false, | ||
28 | + appID: '', | ||
29 | + appSecret: '', | ||
30 | + scope: ['email'] | ||
31 | + }, | ||
32 | + google: { | ||
33 | + enabled: false, | ||
34 | + scope: [ | ||
35 | + 'https://www.googleapis.com/auth/userinfo.profile', | ||
36 | + 'https://www.googleapis.com/auth/userinfo.email' | ||
37 | + ], | ||
38 | + clientID: '', | ||
39 | + clientSecret: '' | ||
40 | + }, | ||
41 | + pkg: pkg, | ||
42 | + cache: false, | ||
43 | + showStack: true, | ||
44 | + assetsDir: assetsDir, | ||
45 | + publicDir: publicDir, | ||
46 | + views: { | ||
47 | + dir: viewsDir, | ||
48 | + engine: 'ejs' | ||
49 | + }, | ||
50 | + password: { | ||
51 | + minStrength: 0, | ||
52 | + limitAttempts: false | ||
53 | + }, | ||
54 | + email: { | ||
55 | + templates: { | ||
56 | + dir: templatesDir, | ||
57 | + options: { | ||
58 | + } | ||
59 | + }, | ||
60 | + // <https://github.com/andris9/Nodemailer> | ||
61 | + transport: { | ||
62 | + service: 'gmail', | ||
63 | + auth: { | ||
64 | + user: 'hi@eskimo.io', | ||
65 | + pass: 'abc123' | ||
66 | + } | ||
67 | + }, | ||
68 | + headers: { | ||
69 | + from: 'hi@eskimo.io' | ||
70 | + } | ||
71 | + }, | ||
72 | + hipchat: { | ||
73 | + level: 'error', | ||
74 | + silent: false, | ||
75 | + token: '', | ||
76 | + notify: false, | ||
77 | + color: 'yellow', | ||
78 | + room: '', | ||
79 | + from: '', | ||
80 | + messageFormat: 'text' | ||
81 | + }, | ||
82 | + session: { | ||
83 | + secret: 'igloo-change-me', | ||
84 | + key: 'igloo', | ||
85 | + cookie: { | ||
86 | + path: '/', | ||
87 | + httpOnly: true, | ||
88 | + secure: false, | ||
89 | + sameSite: 'strict', | ||
90 | + maxAge: maxAge | ||
91 | + }, | ||
92 | + resave: true, | ||
93 | + saveUninitialized: true | ||
94 | + }, | ||
95 | + trustProxy: true, | ||
96 | + updateNotifier: { | ||
97 | + enabled: true, | ||
98 | + dependencies: {}, | ||
99 | + updateCheckInterval: 1000 * 60 * 60, | ||
100 | + updateCheckTimeout: 1000 * 20 | ||
101 | + }, | ||
102 | + staticServer: { | ||
103 | + maxAge: maxAge | ||
104 | + }, | ||
105 | + server: { | ||
106 | + host: 'localhost', | ||
107 | + cluster: false, | ||
108 | + ssl: { | ||
109 | + enabled: false, | ||
110 | + options: {} | ||
111 | + } | ||
112 | + }, | ||
113 | + cookieParser: 'igloo-change-me', | ||
114 | + csrf: { | ||
115 | + enabled: false, | ||
116 | + options: { | ||
117 | + cookie: { | ||
118 | + maxAge: maxAge | ||
119 | + } | ||
120 | + } | ||
121 | + }, | ||
122 | + mongo: { | ||
123 | + host: 'localhost', | ||
124 | + port: 27017, | ||
125 | + opts: {}, | ||
126 | + // faster - don't perform 2nd request to verify | ||
127 | + // log message was received/saved | ||
128 | + safe: false | ||
129 | + }, | ||
130 | + knex: { | ||
131 | + client: 'mysql' | ||
132 | + }, | ||
133 | + redis: { | ||
134 | + host: '192.168.2.70', | ||
135 | + port: 38888, | ||
136 | + pass: 'Q*Kr4?#Rg!', | ||
137 | + maxAge: maxAge | ||
138 | + }, | ||
139 | + output: { | ||
140 | + handleExceptions: false, | ||
141 | + colorize: true, | ||
142 | + prettyPrint: false | ||
143 | + }, | ||
144 | + logger: { | ||
145 | + 'console': true, | ||
146 | + requests: true, | ||
147 | + mongo: false, | ||
148 | + file: false, | ||
149 | + hipchat: false, | ||
150 | + slack: false | ||
151 | + }, | ||
152 | + less: { | ||
153 | + path: publicDir, | ||
154 | + options: { | ||
155 | + force: true | ||
156 | + } | ||
157 | + }, | ||
158 | + jade: { | ||
159 | + amd: { | ||
160 | + path: '/js/tmpl/', | ||
161 | + options: {} | ||
162 | + } | ||
163 | + }, | ||
164 | + liveReload: { | ||
165 | + port: 35729 | ||
166 | + }, | ||
167 | + restful: { | ||
168 | + url: 'http://47.110.158.110:20000/', | ||
169 | + ossUrl: 'http://47.110.158.110:20000/', | ||
170 | + version: '/v1', | ||
171 | + host: '47.110.158.110', | ||
172 | + port: 20000 | ||
173 | + }, | ||
174 | + localStrategy: { | ||
175 | + usernameField: 'username', | ||
176 | + passwordField: 'password', | ||
177 | + // session: false, | ||
178 | + passReqToCallback: true | ||
179 | + } | ||
180 | + }, | ||
181 | + test: { | ||
182 | + cache: true, | ||
183 | + url: 'http://localhost:5999', | ||
184 | + showStack: false, | ||
185 | + updateNotifier: { | ||
186 | + enabled: false, | ||
187 | + }, | ||
188 | + restful: { | ||
189 | + url: 'http://172.21.0.8:20000/', | ||
190 | + ossUrl: 'http://172.21.0.8:10001/v1/', | ||
191 | + version: '/v1' | ||
192 | + }, | ||
193 | + server: { | ||
194 | + host: '0.0.0.0', | ||
195 | + env: 'production', | ||
196 | + port: 5999, | ||
197 | + cluster: false | ||
198 | + }, | ||
199 | + redis: { | ||
200 | + prefix: 'igloo_production_test_develop', | ||
201 | + host: '172.21.0.8', | ||
202 | + port: 38888, | ||
203 | + pass: 'Q*Kr4?#Rg!' | ||
204 | + }, | ||
205 | + logger: { | ||
206 | + 'console': true, | ||
207 | + requests: true, | ||
208 | + mongo: false, | ||
209 | + file: { | ||
210 | + filename: '/opt/work/hro/frontend/hro-develop/igloo.log', | ||
211 | + timestamp: true | ||
212 | + } | ||
213 | + } | ||
214 | + }, | ||
215 | + development: { | ||
216 | + cache: true, | ||
217 | + url: 'http://localhost:3000', | ||
218 | + server: { | ||
219 | + env: 'development', | ||
220 | + port: 3000, | ||
221 | + }, | ||
222 | + mongo: { | ||
223 | + dbname: 'igloo-development', | ||
224 | + db: 'igloo-development' // keep for winston logger | ||
225 | + }, | ||
226 | + knex: { | ||
227 | + debug: true, | ||
228 | + connection: { | ||
229 | + host: '127.0.0.1', | ||
230 | + user: 'root', | ||
231 | + password: '', | ||
232 | + database: 'igloo_development' | ||
233 | + } | ||
234 | + }, | ||
235 | + redis: { | ||
236 | + prefix: 'igloo-development', | ||
237 | + host: '127.0.0.1', | ||
238 | + port: 6379, | ||
239 | + pass: '', | ||
240 | + } | ||
241 | + }, | ||
242 | + production: { | ||
243 | + cache: false, | ||
244 | + url: 'http://localhost:6868', | ||
245 | + views: { | ||
246 | + dir: viewsDir, | ||
247 | + }, | ||
248 | + publicDir: publicDir, | ||
249 | + showStack: false, | ||
250 | + updateNotifier: { | ||
251 | + enabled: false, | ||
252 | + }, | ||
253 | + restful: { | ||
254 | + url: 'http://47.110.158.110:20000/', | ||
255 | + ossUrl: 'http://47.110.158.110:20000/', | ||
256 | + version: '/v1', | ||
257 | + host: '47.110.158.110', | ||
258 | + port: 20000 | ||
259 | + }, | ||
260 | + server: { | ||
261 | + host: '0.0.0.0', | ||
262 | + env: 'production', | ||
263 | + port: 6868, | ||
264 | + cluster: false | ||
265 | + }, | ||
266 | + mongo: { | ||
267 | + dbname: 'igloo-production', | ||
268 | + db: 'igloo-production' // keep for winston logger | ||
269 | + }, | ||
270 | + knex: { | ||
271 | + connection: { | ||
272 | + host: '127.0.0.1', | ||
273 | + user: 'root', | ||
274 | + password: '', | ||
275 | + database: 'igloo_production' | ||
276 | + } | ||
277 | + }, | ||
278 | + redis: { | ||
279 | + prefix: 'igloo_production', | ||
280 | + host: '127.0.0.1', | ||
281 | + port: 6379, | ||
282 | + pass: '', | ||
283 | + }, | ||
284 | + csrf: { | ||
285 | + enabled: true, | ||
286 | + options: { | ||
287 | + cookie: { | ||
288 | + maxAge: maxAge, | ||
289 | + sameSite: 'strict', | ||
290 | + path: '/', | ||
291 | + key: '_csrf', | ||
292 | + httpOnly: true | ||
293 | + } | ||
294 | + } | ||
295 | + }, | ||
296 | + output: { | ||
297 | + colorize: false | ||
298 | + }, | ||
299 | + logger: { | ||
300 | + 'console': true, | ||
301 | + requests: true, | ||
302 | + mongo: false, | ||
303 | + // file: { | ||
304 | + // filename: '/opt/work/hro/frontend/hro/igloo.log', | ||
305 | + // timestamp: true | ||
306 | + // } | ||
307 | + } | ||
308 | + } | ||
309 | + }; | ||
310 | +}; | ||
311 | + | ||
312 | +exports['@singleton'] = true; |
server/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' ]; |
server/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); |
server/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 | + return options; | ||
26 | + } | ||
27 | + | ||
28 | + function addParams(options, req) { | ||
29 | + var postData = !req.body ? '' : JSON.stringify(req.body || {}); | ||
30 | + // options.headers['Content-Length'] = postData.length; | ||
31 | + options.params = postData; | ||
32 | + } | ||
33 | + | ||
34 | + function addContentLength(options) { | ||
35 | + if (options.params) { | ||
36 | + options.headers['Content-Length'] = options.params.length; | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
40 | + function encodeUrl(url) { | ||
41 | + return urlencode(url); | ||
42 | + } | ||
43 | + | ||
44 | + function encodePamars(params) { | ||
45 | + var temp = []; | ||
46 | + for (var i = 0; i < params.length; i++) { | ||
47 | + var param = params[i]; | ||
48 | + var tempParam = param.split("=") | ||
49 | + tempParam[1] = urlencode.decode(tempParam[1], 'utf8'); | ||
50 | + tempParam[1] = tempParam[1].replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | ||
51 | + console.log(tempParam[1]); | ||
52 | + if (i < (params.length - 1)) { | ||
53 | + if (/[:&+/?%#=]/g.test(tempParam[1])) { | ||
54 | + temp.push(tempParam[0] + "=" + encodeUrl(tempParam[1]) + "&"); | ||
55 | + } else { | ||
56 | + temp.push(tempParam[0] + "=" + tempParam[1] + "&"); | ||
57 | + } | ||
58 | + } else { | ||
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 | + } | ||
65 | + } | ||
66 | + return temp.join(""); | ||
67 | + } | ||
68 | + | ||
69 | + function handlePamars(url) { | ||
70 | + var tempUrl = url; | ||
71 | + // if(url.indexOf("?")!=-1){ | ||
72 | + // var temp=url.split("?"); | ||
73 | + // var params=""; | ||
74 | + // if(temp[1]&&temp[1].indexOf("&")!=-1){ | ||
75 | + // params=encodePamars(temp[1].split("&")); | ||
76 | + // }else{ | ||
77 | + // params=encodePamars([temp[1]]); | ||
78 | + // } | ||
79 | + // return temp[0]+"?"+params; | ||
80 | + // }else { | ||
81 | + // return tempUrl; | ||
82 | + // } | ||
83 | + return tempUrl; | ||
84 | + } | ||
85 | + | ||
86 | + function splitServiceFromUrl(url) { | ||
87 | + var catalog = url.substring(1, url.indexOf('/', 1)); | ||
88 | + var pathUrl = url.substring(url.indexOf('/', 1)); | ||
89 | + var fullPath = settings.restful.url + catalog + settings.restful.version + pathUrl; | ||
90 | + return fullPath | ||
91 | + } | ||
92 | + | ||
93 | + function splitUrl(fullUrl) { | ||
94 | + var url = fullUrl.substring(4); | ||
95 | + return url; | ||
96 | + } | ||
97 | + | ||
98 | + function searchService(services, name) { | ||
99 | + if (services[name]) { | ||
100 | + console.log(services[name]); | ||
101 | + return false; | ||
102 | + } else { | ||
103 | + return true; | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + function checkReq(req, res) { | ||
108 | + var flag = true; | ||
109 | + // if(flag&&req.headers&&!req.headers['service-catalog']){ | ||
110 | + // res.status(400); | ||
111 | + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"}); | ||
112 | + // flag=false; | ||
113 | + // } | ||
114 | + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){ | ||
115 | + // res.status(404); | ||
116 | + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"}); | ||
117 | + // flag=false; | ||
118 | + // } | ||
119 | + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){ | ||
120 | + // res.status(404); | ||
121 | + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"}); | ||
122 | + // flag=false; | ||
123 | + // } | ||
124 | + return flag; | ||
125 | + } | ||
126 | + | ||
127 | + function checkJson(req) { | ||
128 | + if (req.headers && req.headers['content-type'] == 'application/json') { | ||
129 | + return true; | ||
130 | + } else { | ||
131 | + return false; | ||
132 | + } | ||
133 | + } | ||
134 | + | ||
135 | + function get(req, res, next) { | ||
136 | + var url = splitUrl(req.originalUrl); | ||
137 | + var options = getOptions(url, 'GET'); | ||
138 | + addToken(options, req); | ||
139 | + function _success(data, response) { | ||
140 | + logger.info('back data:', data); | ||
141 | + if (response.statusCode >= 400 || !data) { | ||
142 | + logger.error(options, data); | ||
143 | + res.send(data); | ||
144 | + } else { | ||
145 | + res.send(data); | ||
146 | + } | ||
147 | + } | ||
148 | + function _fail(err) { | ||
149 | + logger.error(options, err); | ||
150 | + res.send(err); | ||
151 | + } | ||
152 | + rest.restClient(options, _success, _fail); | ||
153 | + } | ||
154 | + | ||
155 | + function post(req, res, next) { | ||
156 | + var url = splitUrl(req.originalUrl); | ||
157 | + var options = getOptions(url, 'POST'); | ||
158 | + addToken(options, req); | ||
159 | + addParams(options, req); | ||
160 | + function _success(data, response) { | ||
161 | + logger.info('back data:', data); | ||
162 | + if (response.statusCode >= 400) { | ||
163 | + logger.error(options, data); | ||
164 | + res.send(data); | ||
165 | + } else if (!data || 'null' == data || "null\n" == data || '{}' == data) { | ||
166 | + res.send({ | ||
167 | + code: 200, | ||
168 | + message: '操作成功!' | ||
169 | + }); | ||
170 | + } else { | ||
171 | + res.send(data); | ||
172 | + } | ||
173 | + } | ||
174 | + function _fail(err) { | ||
175 | + logger.error(options, err); | ||
176 | + res.send(err); | ||
177 | + } | ||
178 | + rest.restClient(options, _success, _fail); | ||
179 | + } | ||
180 | + | ||
181 | + function put(req, res, next) { | ||
182 | + var url = splitUrl(req.originalUrl); | ||
183 | + var options = getOptions(url, 'PUT'); | ||
184 | + addToken(options, req); | ||
185 | + addParams(options, req); | ||
186 | + function _success(data, response) { | ||
187 | + logger.info('back data:', data); | ||
188 | + if (response.statusCode >= 400) { | ||
189 | + logger.error(options, data); | ||
190 | + res.send(data); | ||
191 | + } else if (!data || 'null' == data || "null\n" == data || '{}' == data) { | ||
192 | + res.send({ | ||
193 | + code: 200, | ||
194 | + message: '操作成功!' | ||
195 | + }); | ||
196 | + } else { | ||
197 | + res.send(data); | ||
198 | + } | ||
199 | + } | ||
200 | + function _fail(err) { | ||
201 | + logger.error(options, err); | ||
202 | + res.send(err); | ||
203 | + } | ||
204 | + rest.restClient(options, _success, _fail); | ||
205 | + } | ||
206 | + | ||
207 | + function patch(req, res, next) { | ||
208 | + var url = splitUrl(req.originalUrl); | ||
209 | + var options = getOptions(url, 'PATCH'); | ||
210 | + addToken(options, req); | ||
211 | + addParams(options, req); | ||
212 | + function _success(data, response) { | ||
213 | + logger.info('back data:', data); | ||
214 | + if (response.statusCode >= 400) { | ||
215 | + logger.error(options, data); | ||
216 | + res.send(data); | ||
217 | + } else if (!data) { | ||
218 | + res.send({ | ||
219 | + code: 200, | ||
220 | + message: '操作成功!' | ||
221 | + }); | ||
222 | + } else { | ||
223 | + res.send(data); | ||
224 | + } | ||
225 | + } | ||
226 | + function _fail(err) { | ||
227 | + logger.error(options, err); | ||
228 | + res.send(err); | ||
229 | + } | ||
230 | + rest.restClient(options, _success, _fail); | ||
231 | + } | ||
232 | + | ||
233 | + function head(req, res, next) { | ||
234 | + var url = splitUrl(req.originalUrl); | ||
235 | + var options = getOptions(url, 'HEAD'); | ||
236 | + addToken(options, req); | ||
237 | + addParams(options, req); | ||
238 | + function _success(data, response) { | ||
239 | + logger.info('back data:', data); | ||
240 | + if (response.statusCode >= 400) { | ||
241 | + logger.error(options, data); | ||
242 | + res.send(data); | ||
243 | + } else if (!data) { | ||
244 | + res.send({ | ||
245 | + code: 200, | ||
246 | + message: '操作成功!' | ||
247 | + }); | ||
248 | + } else { | ||
249 | + res.send(data); | ||
250 | + } | ||
251 | + } | ||
252 | + function _fail(err) { | ||
253 | + logger.error(options, err); | ||
254 | + res.send(err); | ||
255 | + } | ||
256 | + rest.restClient(options, _success, _fail); | ||
257 | + } | ||
258 | + | ||
259 | + function del(req, res, next) { | ||
260 | + var url = splitUrl(req.originalUrl); | ||
261 | + var options = getOptions(url, 'DELETE'); | ||
262 | + addToken(options, req); | ||
263 | + addParams(options, req); | ||
264 | + addContentLength(options); | ||
265 | + function _success(data, response) { | ||
266 | + logger.info('back data:', data); | ||
267 | + if (response.statusCode >= 400) { | ||
268 | + logger.error(options, data); | ||
269 | + res.send(data); | ||
270 | + } else if (!data || (data && !data.message)) { | ||
271 | + res.send({ | ||
272 | + code: 200, | ||
273 | + action: "delete", | ||
274 | + message: '删除成功' | ||
275 | + }); | ||
276 | + } else { | ||
277 | + res.send(data); | ||
278 | + } | ||
279 | + } | ||
280 | + function _fail(err) { | ||
281 | + logger.error(options, err); | ||
282 | + res.send(err); | ||
283 | + } | ||
284 | + rest.restClient(options, _success, _fail); | ||
285 | + } | ||
286 | + | ||
287 | + return { | ||
288 | + 'get': get, | ||
289 | + 'post': post, | ||
290 | + 'put': put, | ||
291 | + 'patch': patch, | ||
292 | + 'head': head, | ||
293 | + 'delete': del | ||
294 | + }; | ||
295 | +}; | ||
296 | + | ||
297 | +exports['@singleton'] = true; | ||
298 | +exports['@require'] = ['igloo/logger', 'utils/rest', 'igloo/settings']; |
server/controllers/auth.js
0 → 100644
1 | +var passport = require('passport'); | ||
2 | +var clientRest = require('restler'); | ||
3 | +var urlencode= require('urlencode'); | ||
4 | +exports=module.exports=function(logger,rest,settings){ | ||
5 | + function index(req,res,next){ | ||
6 | + logger.info(req.user); | ||
7 | + if(req.csrfToken) | ||
8 | + res.render('index',{'csrfToken':req.csrfToken()}); | ||
9 | + else | ||
10 | + res.render('index',{'csrfToken':''}); | ||
11 | + } | ||
12 | + | ||
13 | + function productDes(req,res,next){ | ||
14 | + if(req.csrfToken) | ||
15 | + res.render('chat/new-chat',{'csrfToken':req.csrfToken()}); | ||
16 | + else | ||
17 | + res.render('chat/new-chat',{'csrfToken':''}); | ||
18 | + } | ||
19 | + | ||
20 | + function recharge(req,res,next){ | ||
21 | + | ||
22 | + var params=JSON.parse(urlencode.decode(req.query.params)); | ||
23 | + console.log(params); | ||
24 | + if(req.csrfToken) | ||
25 | + res.render('recharge',{'recharge':params,'csrfToken':req.csrfToken()}); | ||
26 | + else | ||
27 | + res.render('recharge',{'recharge':params,'csrfToken':''}); | ||
28 | + | ||
29 | + } | ||
30 | + | ||
31 | + function register(req,res,next){ | ||
32 | + if(req.csrfToken) | ||
33 | + res.render('newRegister',{'csrfToken':req.csrfToken()}); | ||
34 | + else | ||
35 | + res.render('newRegister',{'csrfToken':''}); | ||
36 | + } | ||
37 | + | ||
38 | + function mobileRegister (req,res,next) { | ||
39 | + if(req.csrfToken) | ||
40 | + res.render('registerMobile',{'csrfToken':req.csrfToken()}); | ||
41 | + else | ||
42 | + res.render('registerMobile',{'csrfToken':''}); | ||
43 | + } | ||
44 | + | ||
45 | + function mobileRegisterSuccess (req,res,next) { | ||
46 | + if(req.csrfToken) | ||
47 | + res.render('registerMobileSuccess',{'csrfToken':req.csrfToken()}); | ||
48 | + else | ||
49 | + res.render('registerMobileSuccess',{'csrfToken':''}); | ||
50 | + } | ||
51 | + | ||
52 | + function signIn(req,res,next){ | ||
53 | + // console.log(req); | ||
54 | + if(req.csrfToken) | ||
55 | + res.render('newLogin',{'csrfToken':req.csrfToken()}); | ||
56 | + else | ||
57 | + res.render('newLogin',{'csrfToken':''}); | ||
58 | + | ||
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) { return next(err); } | ||
65 | + if (!user) { return res.send(info); } | ||
66 | + req.logIn(user, function(err) { | ||
67 | + if (err) { return next(err); } | ||
68 | + return res.send({'ok':'登录成功',user_info:req.session.passport.user.user_info}); | ||
69 | + }); | ||
70 | + })(req, res, next); | ||
71 | + } | ||
72 | + | ||
73 | + function signOut(req,res,next){ | ||
74 | + if(req.session.passport&&req.session.passport.user&&req.session.passport.user.user_info&&req.session.passport.user.user_info.user) | ||
75 | + logger.info(req.session.passport.user.user_info.user,'You have successfully logged out'); | ||
76 | + req.logout(); | ||
77 | + req.flash('success', 'You have successfully logged out'); | ||
78 | + res.redirect('/'); | ||
79 | + } | ||
80 | + | ||
81 | + function smsCodes(req,res,next){ | ||
82 | + rest.postJson({ | ||
83 | + 'baseUrl':'url', | ||
84 | + 'url':'auth/smscodes', | ||
85 | + 'params':req.body, | ||
86 | + 'callback':_cb, | ||
87 | + 'req':req, | ||
88 | + 'res':res, | ||
89 | + 'options':{}, | ||
90 | + 'excludeToken':true | ||
91 | + }) | ||
92 | + function _cb(data,response){ | ||
93 | + logger.info("back data:",data); | ||
94 | + if(response.statusCode<300){ | ||
95 | + res.send({"code":200,"message":"发送成功"}); | ||
96 | + }else{ | ||
97 | + res.send(data); | ||
98 | + } | ||
99 | + }; | ||
100 | + } | ||
101 | + | ||
102 | + function tenants(req,res,next){ | ||
103 | + rest.register({ | ||
104 | + 'baseUrl':'url', | ||
105 | + 'url':'tenants', | ||
106 | + 'params':req.body, | ||
107 | + 'callback':_cb, | ||
108 | + 'req':req, | ||
109 | + 'res':res, | ||
110 | + 'options':{}, | ||
111 | + 'excludeToken':true | ||
112 | + }); | ||
113 | + function _cb(data,response){ | ||
114 | + logger.info("back data:",data); | ||
115 | + res.send(data); | ||
116 | + }; | ||
117 | + } | ||
118 | + | ||
119 | + function resetPass(req,res){ | ||
120 | + rest.putJson({ | ||
121 | + 'baseUrl':'url', | ||
122 | + 'url':'auth/user', | ||
123 | + 'params':{ | ||
124 | + 'user':req.body.user, | ||
125 | + 'password':req.body.password, | ||
126 | + 'again_password':req.body.again_password | ||
127 | + }, | ||
128 | + 'callback':_cb, | ||
129 | + 'req':req, | ||
130 | + 'res':res, | ||
131 | + 'options':{} | ||
132 | + }) | ||
133 | + function _cb(data,response){ | ||
134 | + logger.info("back data:",data); | ||
135 | + res.send(data); | ||
136 | + }; | ||
137 | + } | ||
138 | + | ||
139 | + function updatePassword(req,res){ | ||
140 | + rest.patchJson({ | ||
141 | + 'baseUrl':'url', | ||
142 | + 'url':'users/'+req.body.userId, | ||
143 | + 'params':{ | ||
144 | + 'password': req.body.password | ||
145 | + }, | ||
146 | + 'callback':_cb, | ||
147 | + 'req':req, | ||
148 | + 'res':res, | ||
149 | + 'options':{} | ||
150 | + }) | ||
151 | + function _cb(data,response){ | ||
152 | + logger.info("back data:",data); | ||
153 | + res.send(data); | ||
154 | + }; | ||
155 | + } | ||
156 | + | ||
157 | + | ||
158 | + function loadUserInfo(req,res){ | ||
159 | + if(req.session.passport.user&&req.session.passport.user.user_info){ | ||
160 | + res.send({user_info:req.session.passport.user.user_info}); | ||
161 | + }else{ | ||
162 | + res.send({user_info:null}); | ||
163 | + } | ||
164 | + } | ||
165 | + | ||
166 | + function getUploaderToken(req,res){ | ||
167 | + rest.postJson({ | ||
168 | + 'baseUrl':'ossUrl', | ||
169 | + 'url':'inits', | ||
170 | + 'params':req.body, | ||
171 | + 'callback':_cb, | ||
172 | + 'req':req, | ||
173 | + 'res':res, | ||
174 | + 'options':{} | ||
175 | + }) | ||
176 | + function _cb(data,response){ | ||
177 | + logger.info("back data:",data); | ||
178 | + res.send(data); | ||
179 | + }; | ||
180 | + } | ||
181 | + | ||
182 | + function getObjectTokenByID(req,res){ | ||
183 | + rest.get({ | ||
184 | + 'baseUrl':'ossUrl', | ||
185 | + 'url':'objects/'+req.body.file_id, | ||
186 | + 'params':{}, | ||
187 | + 'callback':_cb, | ||
188 | + 'req':req, | ||
189 | + 'res':res, | ||
190 | + 'options':{} | ||
191 | + }) | ||
192 | + function _cb(data,response){ | ||
193 | + logger.info("back data:",data); | ||
194 | + res.send(data); | ||
195 | + }; | ||
196 | + } | ||
197 | + | ||
198 | + function delOSSObject(req,res){ | ||
199 | + rest.del({ | ||
200 | + 'baseUrl':'ossUrl', | ||
201 | + 'url':'s3objects/'+req.body.request_id+'?bucket='+req.body.bucket+'&file='+req.body.name, | ||
202 | + 'params':{}, | ||
203 | + 'callback':_cb, | ||
204 | + 'req':req, | ||
205 | + 'res':res, | ||
206 | + 'options':{} | ||
207 | + }) | ||
208 | + function _cb(data,response){ | ||
209 | + logger.info("back data:",data); | ||
210 | + console.log(response.statusCode) | ||
211 | + if(response.statusCode<300){ | ||
212 | + res.send({'delete':'ok'}); | ||
213 | + } | ||
214 | + }; | ||
215 | + } | ||
216 | + | ||
217 | + function smsVerification(req,res,next){ | ||
218 | + rest.postJson({ | ||
219 | + 'baseUrl':'url', | ||
220 | + 'url':'auth/sms_verification', | ||
221 | + 'params':req.body, | ||
222 | + 'callback':_cb, | ||
223 | + 'req':req, | ||
224 | + 'res':res, | ||
225 | + 'options':{}, | ||
226 | + 'excludeToken':true | ||
227 | + }) | ||
228 | + function _cb(data,response){ | ||
229 | + logger.info("back data:",data); | ||
230 | + if(response.statusCode<300){ | ||
231 | + res.send({"code":200,"message":"发送成功"}); | ||
232 | + }else{ | ||
233 | + res.send({"code":response.statusCode,"message":data.message,'errors':data.errors}); | ||
234 | + } | ||
235 | + }; | ||
236 | + } | ||
237 | + | ||
238 | + function healthMonitor(req,res){ | ||
239 | + res.statusCode = 200; | ||
240 | + return res.send('status ok'); | ||
241 | + } | ||
242 | + | ||
243 | + | ||
244 | + function updateUserRoles(req,res){ | ||
245 | + rest.putJson({ | ||
246 | + 'baseUrl':'url', | ||
247 | + 'url':'user_roles/'+req.body.user_id, | ||
248 | + 'params':req.body.roles, | ||
249 | + 'callback':_cb, | ||
250 | + 'req':req, | ||
251 | + 'res':res, | ||
252 | + 'options':{} | ||
253 | + }) | ||
254 | + function _cb(data,response){ | ||
255 | + logger.info("back data:",data); | ||
256 | + if(response.statusCode<300){ | ||
257 | + res.send({'back':'ok'}); | ||
258 | + }else{ | ||
259 | + res.send(data); | ||
260 | + } | ||
261 | + }; | ||
262 | + } | ||
263 | + | ||
264 | + function getRoles(req,res,next){ | ||
265 | + rest.get({ | ||
266 | + 'baseUrl':'url', | ||
267 | + 'url':'roles', | ||
268 | + 'params':{}, | ||
269 | + 'callback':_cb, | ||
270 | + 'req':req, | ||
271 | + 'res':res, | ||
272 | + 'options':{} | ||
273 | + }) | ||
274 | + function _cb(data,response){ | ||
275 | + logger.info("back data:",data); | ||
276 | + res.send(data); | ||
277 | + }; | ||
278 | + } | ||
279 | + | ||
280 | + | ||
281 | + function getUserRoles(req,res,next){ | ||
282 | + rest.get({ | ||
283 | + 'baseUrl':'url', | ||
284 | + 'url':'user_roles?user='+urlencode(req.body.user)+'&limit='+req.body.limit+'&offset='+req.body.offset, | ||
285 | + 'params':{}, | ||
286 | + 'callback':_cb, | ||
287 | + 'req':req, | ||
288 | + 'res':res, | ||
289 | + 'options':{} | ||
290 | + }) | ||
291 | + function _cb(data,response){ | ||
292 | + logger.info("back data:",data); | ||
293 | + res.send(data); | ||
294 | + }; | ||
295 | + } | ||
296 | + | ||
297 | + function getTenant(req,res){ | ||
298 | + rest.get({ | ||
299 | + 'baseUrl':'url', | ||
300 | + 'url':'tenants/'+req.body.tenant_id, | ||
301 | + 'params':{}, | ||
302 | + 'callback':_cb, | ||
303 | + 'req':req, | ||
304 | + 'res':res, | ||
305 | + 'options':{} | ||
306 | + }) | ||
307 | + function _cb(data,response){ | ||
308 | + logger.info("back data:",data); | ||
309 | + res.send(data); | ||
310 | + }; | ||
311 | + } | ||
312 | + | ||
313 | + function updateTenant(req,res){ | ||
314 | + rest.putJson({ | ||
315 | + 'baseUrl':'url', | ||
316 | + 'url':'tenants/'+req.body.tenant_id, | ||
317 | + 'params':req.body.tenant, | ||
318 | + 'callback':_cb, | ||
319 | + 'req':req, | ||
320 | + 'res':res, | ||
321 | + 'options':{} | ||
322 | + }) | ||
323 | + function _cb(data,response){ | ||
324 | + logger.info("back data:",data); | ||
325 | + res.send(data); | ||
326 | + }; | ||
327 | + } | ||
328 | + | ||
329 | + function offer(req,res){ | ||
330 | + rest.get({ | ||
331 | + 'baseUrl':'hrUrl', | ||
332 | + 'url':'offers/'+req.params.requestId+'?tenant_id='+req.query.tenant_id, | ||
333 | + 'params':{}, | ||
334 | + 'callback':_cb, | ||
335 | + 'req':req, | ||
336 | + 'res':res, | ||
337 | + 'options':{}, | ||
338 | + 'excludeToken':true | ||
339 | + }) | ||
340 | + function _cb(data,response){ | ||
341 | + logger.info("back data:",data); | ||
342 | + //res.send(data); | ||
343 | + console.log(data); | ||
344 | + data['offerId']=req.params.requestId; | ||
345 | + data['tenantId']=req.query.tenant_id; | ||
346 | + res.render('offer',data); | ||
347 | + }; | ||
348 | + } | ||
349 | + | ||
350 | + function onboardStatus(req,res){ | ||
351 | + rest.get({ | ||
352 | + 'baseUrl':'hrUrl', | ||
353 | + 'url':'onboard-status', | ||
354 | + 'params':{}, | ||
355 | + 'callback':_cb, | ||
356 | + 'req':req, | ||
357 | + 'res':res, | ||
358 | + 'options':{}, | ||
359 | + 'useUrl':true | ||
360 | + }) | ||
361 | + function _cb(data,response){ | ||
362 | + logger.info("back data:",data); | ||
363 | + res.send(data); | ||
364 | + }; | ||
365 | + } | ||
366 | + | ||
367 | + function dowloadApp(req,res){ | ||
368 | + var mobileAgent=req.headers['user-agent'].toLowerCase(); | ||
369 | + var agent={ | ||
370 | + android: mobileAgent.indexOf('android') > -1 || mobileAgent.indexOf('Adr') > -1, | ||
371 | + iPhone:mobileAgent.indexOf('iphone') > -1, | ||
372 | + iPad: mobileAgent.indexOf('ipad') > -1 | ||
373 | + } | ||
374 | + if(agent.iPhone||agent.iPad){ | ||
375 | + res.redirect(301, 'https://itunes.apple.com/cn/app/%E8%96%AA%E5%91%97/id1140779439?l=en&mt=8'); | ||
376 | + }else if(agent.android){ | ||
377 | + res.redirect(301, 'http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk'); | ||
378 | + }else{ | ||
379 | + res.redirect(301, 'http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk'); | ||
380 | + } | ||
381 | + } | ||
382 | + | ||
383 | + function softwareLicense (req,res,next) { | ||
384 | + res.render('softwareLicense'); | ||
385 | + } | ||
386 | + | ||
387 | + function changePassForRegister(req,res,next){ | ||
388 | + var options={ | ||
389 | + 'baseUrl':'url', | ||
390 | + 'url':'users/'+req.body.user_id, | ||
391 | + 'params':{ | ||
392 | + 'password': req.body.password | ||
393 | + }, | ||
394 | + 'callback':_cb, | ||
395 | + 'req':req, | ||
396 | + 'res':res, | ||
397 | + 'options':{} | ||
398 | + }; | ||
399 | + if(req.body.access_token){ | ||
400 | + console.log("@@@!!!!!!!!!!!!!!!!"); | ||
401 | + options.options={ | ||
402 | + "accessToken":req.body.access_token | ||
403 | + }; | ||
404 | + options['excludeToken']=true; | ||
405 | + } | ||
406 | + rest.patchJson(options) | ||
407 | + function _cb(data,response){ | ||
408 | + logger.info("back data:",data); | ||
409 | + res.send(data); | ||
410 | + }; | ||
411 | + } | ||
412 | + | ||
413 | + function changeTenant(req,res,next){ | ||
414 | + var params={ | ||
415 | + grant_type:'refresh_token', | ||
416 | + scope:'global_access:tenant_admin,tenant:'+req.body.id, | ||
417 | + refresh_token:req.session.passport.user.refreshToken | ||
418 | + } | ||
419 | + req.session.passport.user.token=''; | ||
420 | + rest.postJson({ | ||
421 | + 'baseUrl':'url', | ||
422 | + 'url':settings.restful.url+'uaa'+settings.restful.version+'/auth/tokens', | ||
423 | + 'useUrl':true, | ||
424 | + 'params':params, | ||
425 | + 'callback':_cb, | ||
426 | + 'req':req, | ||
427 | + 'res':res, | ||
428 | + 'options':{}, | ||
429 | + 'excludeToken':true | ||
430 | + }) | ||
431 | + function _cb(data,response){ | ||
432 | + console.log(data); | ||
433 | + logger.info("back data:",data); | ||
434 | + if(response.statusCode<300){ | ||
435 | + req.session.passport.user.token=data.access_token; | ||
436 | + req.session.passport.user.refreshToken=data.refresh_token; | ||
437 | + req.session.passport.user.user_info={ | ||
438 | + 'user':data.user, | ||
439 | + 'perms':[], | ||
440 | + 'tenant':data.tenant, | ||
441 | + 'scope':data.scope, | ||
442 | + 'oss': req.session.passport.user.user_info.oss | ||
443 | + }; | ||
444 | + req.session.save(function(err) { | ||
445 | + rest.get({ | ||
446 | + 'baseUrl':'url', | ||
447 | + 'url': settings.restful.url+'uaa'+settings.restful.version+'/perms/detail', | ||
448 | + 'useUrl':true, | ||
449 | + 'params':{}, | ||
450 | + 'callback':_scb, | ||
451 | + 'req':req, | ||
452 | + 'res':res, | ||
453 | + 'options':{} | ||
454 | + }); | ||
455 | + }) | ||
456 | + }else{ | ||
457 | + res.send({"code":response.statusCode,"message":data.message,initialize_done:"n"}); | ||
458 | + } | ||
459 | + }; | ||
460 | + function _scb(data1,response){ | ||
461 | + if(response.statusCode<300&&data1.items){ | ||
462 | + req.session.passport.user.user_info.perms=data1.items; | ||
463 | + req.session.save(function(err) { | ||
464 | + // res.send({"code":200,"message":"切换租户成功"}); | ||
465 | + rest.get({ | ||
466 | + 'baseUrl':'url', | ||
467 | + 'url': settings.restful.url+'filemeta'+settings.restful.version+'/config', | ||
468 | + 'useUrl':true, | ||
469 | + 'params':{}, | ||
470 | + 'callback':_scb1, | ||
471 | + 'req':req, | ||
472 | + 'res':res, | ||
473 | + 'options':{} | ||
474 | + }); | ||
475 | + }) | ||
476 | + }else{ | ||
477 | + res.send({"code":response.statusCode,"message":data1.message}); | ||
478 | + } | ||
479 | + } | ||
480 | + function _scb1(data2,response){ | ||
481 | + if(response.statusCode<300&&data2&&data2.bucket){ | ||
482 | + req.session.passport.user.user_info.oss=data2; | ||
483 | + req.session.save(function(err) { | ||
484 | + res.send({"code":200,"message":"切换租户成功"}); | ||
485 | + }); | ||
486 | + }else { | ||
487 | + res.send({"code":200,"message":"切换租户失败"}); | ||
488 | + } | ||
489 | + } | ||
490 | + } | ||
491 | + | ||
492 | + | ||
493 | + function sendRejectOffer(req,res){ | ||
494 | + rest.get({ | ||
495 | + 'baseUrl':'hrUrl', | ||
496 | + 'url':req.body.url, //传一个参数 | ||
497 | + 'params':{}, | ||
498 | + 'callback':_cb, | ||
499 | + 'req':req, | ||
500 | + 'res':res, | ||
501 | + 'options':{}, | ||
502 | + 'excludeToken':true, | ||
503 | + 'useUrl':true | ||
504 | + }); | ||
505 | + function _cb(data,response){ | ||
506 | + logger.info("back data:",data); | ||
507 | + if(response.statusCode<300){ | ||
508 | + res.send({'action':'ok'}); | ||
509 | + }else{ | ||
510 | + res.send(data); | ||
511 | + } | ||
512 | + }; | ||
513 | + } | ||
514 | + | ||
515 | + function acceptOffer(req,res){ | ||
516 | + rest.get({ | ||
517 | + 'baseUrl':'hrUrl', | ||
518 | + 'url':req.body.url, //传一个参数 | ||
519 | + 'params':{}, | ||
520 | + 'callback':_cb, | ||
521 | + 'req':req, | ||
522 | + 'res':res, | ||
523 | + 'options':{}, | ||
524 | + 'excludeToken':true, | ||
525 | + 'useUrl':true | ||
526 | + }); | ||
527 | + function _cb(data,response){ | ||
528 | + logger.info("back data:",data); | ||
529 | + if(response.statusCode<300){ | ||
530 | + res.send({'action':'ok'}); | ||
531 | + }else{ | ||
532 | + res.send(data); | ||
533 | + } | ||
534 | + }; | ||
535 | + } | ||
536 | + | ||
537 | + function imTokens(req,res){ | ||
538 | + rest.post({ | ||
539 | + 'url':'auth/im_tokens', | ||
540 | + 'params':req.body, | ||
541 | + 'callback':_cb, | ||
542 | + 'req':req, | ||
543 | + 'res':res, | ||
544 | + 'options':{} | ||
545 | + }); | ||
546 | + function _cb(data,response){ | ||
547 | + logger.info("back data:",data); | ||
548 | + res.send(data); | ||
549 | + }; | ||
550 | + } | ||
551 | + | ||
552 | + function listChannels(req,res,next){ | ||
553 | + rest.get({ | ||
554 | + 'baseUrl':'chatUrl', | ||
555 | + 'url':'channels?page_size=10&page=0&status=active', | ||
556 | + 'params':req.body, | ||
557 | + 'callback':_cb, | ||
558 | + 'req':req, | ||
559 | + 'res':res, | ||
560 | + 'options':{} | ||
561 | + }) | ||
562 | + function _cb(data,response){ | ||
563 | + logger.info("back data:",data); | ||
564 | + res.send(data); | ||
565 | + }; | ||
566 | + } | ||
567 | + | ||
568 | + function filemeta(req,res,next){ | ||
569 | + var fullPath=settings.restful.url+'filemeta'+settings.restful.version+'/object-redirect'; | ||
570 | + fullPath=fullPath+"?"+"bucket="+req.query.bucket+"&object="+encodeURIComponent(req.query.object); | ||
571 | + var options={ | ||
572 | + 'service_catalog':'', | ||
573 | + 'url':fullPath, | ||
574 | + 'useUrl':true, | ||
575 | + 'params':req.body, | ||
576 | + 'callback':_cb, | ||
577 | + 'req':req, | ||
578 | + 'res':res, | ||
579 | + 'options':{} | ||
580 | + }; | ||
581 | + rest.get(options); | ||
582 | + function _cb(data,response){ | ||
583 | + if(data&&data.download_url){ | ||
584 | + if(req.query.type&&'json'==req.query.type){ | ||
585 | + res.send(data); | ||
586 | + }else{ | ||
587 | + res.redirect(301, data.download_url); | ||
588 | + } | ||
589 | + }else { | ||
590 | + res.send(data); | ||
591 | + } | ||
592 | + } | ||
593 | + } | ||
594 | + | ||
595 | + | ||
596 | + function getCustomerQrcode(req,res,next){ | ||
597 | + var fullPath=settings.restful.url+'crm'+settings.restful.version+'/customers/'+req.query.id+'/qrcode'; | ||
598 | + var options={ | ||
599 | + 'service_catalog':'', | ||
600 | + 'url':fullPath, | ||
601 | + 'useUrl':true, | ||
602 | + 'params':req.body, | ||
603 | + 'callback':_cb, | ||
604 | + 'req':req, | ||
605 | + 'res':res, | ||
606 | + 'options':{} | ||
607 | + }; | ||
608 | + rest.get(options); | ||
609 | + function _cb(data,response){ | ||
610 | + if(data&&data.url_path){ | ||
611 | + res.redirect(301, data.url_path); | ||
612 | + }else { | ||
613 | + res.send(data); | ||
614 | + } | ||
615 | + } | ||
616 | + } | ||
617 | + | ||
618 | + function getPositionQrcode(req,res,next){ | ||
619 | + var fullPath=settings.restful.url+'recruit'+settings.restful.version+'/positions/'+req.query.id+'/qrcode'; | ||
620 | + var options={ | ||
621 | + 'service_catalog':'', | ||
622 | + 'url':fullPath, | ||
623 | + 'useUrl':true, | ||
624 | + 'params':req.body, | ||
625 | + 'callback':_cb, | ||
626 | + 'req':req, | ||
627 | + 'res':res, | ||
628 | + 'options':{} | ||
629 | + }; | ||
630 | + rest.get(options); | ||
631 | + function _cb(data,response){ | ||
632 | + if(data&&data.url_path){ | ||
633 | + res.redirect(301, data.url_path); | ||
634 | + }else { | ||
635 | + res.send(data); | ||
636 | + } | ||
637 | + } | ||
638 | + } | ||
639 | + | ||
640 | + function getOSSConfig(req,res,next){ | ||
641 | + var fullPath=settings.restful.url+'filemeta'+settings.restful.version+'/config'; | ||
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.bucket){ | ||
655 | + req.session.passport.user.user_info.oss=data; | ||
656 | + req.session.save(function(err) { | ||
657 | + res.send({"code":200,"message":"oss配置加载成功"}); | ||
658 | + }); | ||
659 | + }else { | ||
660 | + res.send({"code":200,"message":"oss配置加载失败"}); | ||
661 | + } | ||
662 | + } | ||
663 | + } | ||
664 | + | ||
665 | + function weidianTempLate(req,res,next){ | ||
666 | + const { params } = req; | ||
667 | + var fullPath=settings.restful.url + 'socialwork/internal/minishop/' + params.id; | ||
668 | + var options={ | ||
669 | + 'service_catalog':'', | ||
670 | + 'url':fullPath, | ||
671 | + 'useUrl':true, | ||
672 | + 'params':req.body, | ||
673 | + 'callback':_cb, | ||
674 | + 'req':req, | ||
675 | + 'res':res, | ||
676 | + 'options':{}, | ||
677 | + 'excludeToken':true, | ||
678 | + }; | ||
679 | + rest.get(options); | ||
680 | + function _cb(data,response){ | ||
681 | + logger.info("back data:",data); | ||
682 | + if(response.statusCode<300){ | ||
683 | + const { shop_logo=[], shop_name='', shop_comment='' } = data; | ||
684 | + let imgUrl = ''; | ||
685 | + if (shop_logo.length > 0) { | ||
686 | + imgUrl = 'http://oss.workai.com.cn/public/' + shop_logo[0].object; | ||
687 | + } | ||
688 | + res.render('template/weiDian',{ | ||
689 | + imgUrl: imgUrl, | ||
690 | + shop_name: shop_name, | ||
691 | + shop_comment: shop_comment, | ||
692 | + }) | ||
693 | + }else{ | ||
694 | + res.render('template/weiDian') | ||
695 | + } | ||
696 | + }; | ||
697 | + | ||
698 | + } | ||
699 | + | ||
700 | + return { | ||
701 | + index:index, | ||
702 | + register:register, | ||
703 | + signIn:signIn, | ||
704 | + doLogin:doLogin, | ||
705 | + signOut:signOut, | ||
706 | + smsCodes:smsCodes, | ||
707 | + tenants:tenants, | ||
708 | + productDes:productDes, | ||
709 | + resetPass:resetPass, | ||
710 | + updatePassword:updatePassword, | ||
711 | + loadUserInfo:loadUserInfo, | ||
712 | + getUploaderToken:getUploaderToken, | ||
713 | + getObjectTokenByID, | ||
714 | + delOSSObject:delOSSObject, | ||
715 | + healthMonitor, | ||
716 | + smsVerification, | ||
717 | + updateUserRoles, | ||
718 | + getRoles, | ||
719 | + getUserRoles, | ||
720 | + getTenant, | ||
721 | + updateTenant, | ||
722 | + offer, | ||
723 | + onboardStatus, | ||
724 | + dowloadApp, | ||
725 | + mobileRegister, | ||
726 | + mobileRegisterSuccess, | ||
727 | + softwareLicense, | ||
728 | + recharge, | ||
729 | + changePassForRegister, | ||
730 | + changeTenant, | ||
731 | + sendRejectOffer, | ||
732 | + acceptOffer, | ||
733 | + imTokens, | ||
734 | + listChannels, | ||
735 | + filemeta, | ||
736 | + getCustomerQrcode, | ||
737 | + getPositionQrcode, | ||
738 | + getOSSConfig, | ||
739 | + weidianTempLate | ||
740 | + }; | ||
741 | +}; | ||
742 | + | ||
743 | +exports['@singleton']=true; | ||
744 | +exports['@require']=['igloo/logger','utils/rest','igloo/settings']; |
server/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 | + var url=fullUrl.substring(9); | ||
60 | + return url; | ||
61 | + } | ||
62 | + | ||
63 | + function searchService(services,name){ | ||
64 | + if(services[name]){ | ||
65 | + console.log(services[name]); | ||
66 | + return false; | ||
67 | + }else{ | ||
68 | + return true; | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + function checkReq(req,res){ | ||
73 | + var flag=true; | ||
74 | + // if(flag&&req.headers&&!req.headers['service-catalog']){ | ||
75 | + // res.status(400); | ||
76 | + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"}); | ||
77 | + // flag=false; | ||
78 | + // } | ||
79 | + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){ | ||
80 | + // res.status(404); | ||
81 | + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"}); | ||
82 | + // flag=false; | ||
83 | + // } | ||
84 | + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){ | ||
85 | + // res.status(404); | ||
86 | + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"}); | ||
87 | + // flag=false; | ||
88 | + // } | ||
89 | + return flag; | ||
90 | + } | ||
91 | + | ||
92 | + function checkJson(req){ | ||
93 | + if(req.headers&&req.headers['content-type']=='application/json'){ | ||
94 | + return true; | ||
95 | + }else{ | ||
96 | + return false; | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + function get(req,res,next){ | ||
101 | + var url=splitUrl(req.originalUrl); | ||
102 | + url=handlePamars(url); | ||
103 | + url=splitServiceFromUrl(url); | ||
104 | + if(checkReq(req,res)){ | ||
105 | + var options={ | ||
106 | + 'service_catalog':'', | ||
107 | + 'url': url, | ||
108 | + 'useUrl':true, | ||
109 | + 'params':req.body, | ||
110 | + 'callback':_cb, | ||
111 | + 'req':req, | ||
112 | + 'res':res, | ||
113 | + 'options':{}, | ||
114 | + 'excludeToken':true | ||
115 | + }; | ||
116 | + // if(checkJson(req)){ | ||
117 | + // rest.json(options); | ||
118 | + // }else{ | ||
119 | + // rest.get(options); | ||
120 | + // } | ||
121 | + rest.get(options); | ||
122 | + } | ||
123 | + function _cb(data,response){ | ||
124 | + logger.info('back data:',data); | ||
125 | + if(response.statusCode<300&&!data){ | ||
126 | + res.send({ | ||
127 | + code:200, | ||
128 | + message:'操作成功!' | ||
129 | + }); | ||
130 | + }else { | ||
131 | + res.send(data); | ||
132 | + } | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + function post(req,res,next){ | ||
137 | + var url=splitUrl(req.originalUrl); | ||
138 | + url=splitServiceFromUrl(url); | ||
139 | + if(checkReq(req,res)){ | ||
140 | + var options={ | ||
141 | + 'service_catalog':'', | ||
142 | + 'url': url, | ||
143 | + 'useUrl':true, | ||
144 | + 'params':req.body, | ||
145 | + 'callback':_cb, | ||
146 | + 'req':req, | ||
147 | + 'res':res, | ||
148 | + 'options':{}, | ||
149 | + 'excludeToken':true | ||
150 | + }; | ||
151 | + if(checkJson(req)){ | ||
152 | + rest.postJson(options); | ||
153 | + }else{ | ||
154 | + rest.post(options); | ||
155 | + } | ||
156 | + } | ||
157 | + function _cb(data,response){ | ||
158 | + logger.info('back data:',data); | ||
159 | + if(response.statusCode<300&&!data){ | ||
160 | + res.send({ | ||
161 | + code:200, | ||
162 | + message:'操作成功!' | ||
163 | + }); | ||
164 | + }else{ | ||
165 | + res.send(data); | ||
166 | + } | ||
167 | + } | ||
168 | + } | ||
169 | + | ||
170 | + function put(req,res,next){ | ||
171 | + var url=splitUrl(req.originalUrl); | ||
172 | + url=splitServiceFromUrl(url); | ||
173 | + if(checkReq(req,res)){ | ||
174 | + var options={ | ||
175 | + 'service_catalog':'', | ||
176 | + 'url':url, | ||
177 | + 'useUrl':true, | ||
178 | + 'params':req.body, | ||
179 | + 'callback':_cb, | ||
180 | + 'req':req, | ||
181 | + 'res':res, | ||
182 | + 'options':{}, | ||
183 | + 'excludeToken':true | ||
184 | + }; | ||
185 | + if(checkJson(req)){ | ||
186 | + rest.putJson(options); | ||
187 | + }else{ | ||
188 | + rest.put(options); | ||
189 | + } | ||
190 | + } | ||
191 | + function _cb(data,response){ | ||
192 | + logger.info('back data:',data); | ||
193 | + if(response.statusCode<300&&!data){ | ||
194 | + res.send({ | ||
195 | + code:200, | ||
196 | + message:'操作成功!' | ||
197 | + }); | ||
198 | + }else{ | ||
199 | + res.send(data); | ||
200 | + } | ||
201 | + } | ||
202 | + } | ||
203 | + | ||
204 | + function patch(req,res,next){ | ||
205 | + var url=splitUrl(req.originalUrl); | ||
206 | + url=splitServiceFromUrl(url); | ||
207 | + if(checkReq(req,res)){ | ||
208 | + var options={ | ||
209 | + 'service_catalog':'', | ||
210 | + 'url': url, | ||
211 | + 'useUrl':true, | ||
212 | + 'params':req.body, | ||
213 | + 'callback':_cb, | ||
214 | + 'req':req, | ||
215 | + 'res':res, | ||
216 | + 'options':{}, | ||
217 | + 'excludeToken':true | ||
218 | + }; | ||
219 | + if(checkJson(req)){ | ||
220 | + rest.patchJson(options); | ||
221 | + }else{ | ||
222 | + rest.patch(options); | ||
223 | + } | ||
224 | + } | ||
225 | + function _cb(data,response){ | ||
226 | + logger.info('back data:',data); | ||
227 | + res.send(data); | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + function head(req,res,next){ | ||
232 | + var url=splitUrl(req.originalUrl); | ||
233 | + url=splitServiceFromUrl(url); | ||
234 | + if(checkReq(req,res)){ | ||
235 | + var options={ | ||
236 | + 'service_catalog':'', | ||
237 | + 'url': url, | ||
238 | + 'useUrl':true, | ||
239 | + 'params':req.body, | ||
240 | + 'callback':_cb, | ||
241 | + 'req':req, | ||
242 | + 'res':res, | ||
243 | + 'options':{}, | ||
244 | + 'excludeToken':true | ||
245 | + }; | ||
246 | + rest.get(options); | ||
247 | + } | ||
248 | + function _cb(data,response){ | ||
249 | + logger.info('back data:',data); | ||
250 | + res.send(data); | ||
251 | + } | ||
252 | + } | ||
253 | + | ||
254 | + function del(req,res,next){ | ||
255 | + var url=splitUrl(req.originalUrl); | ||
256 | + url=splitServiceFromUrl(url); | ||
257 | + if(checkReq(req,res)){ | ||
258 | + var options={ | ||
259 | + 'service_catalog':'', | ||
260 | + 'url': url, | ||
261 | + 'useUrl':true, | ||
262 | + 'params':req.body, | ||
263 | + 'callback':_cb, | ||
264 | + 'req':req, | ||
265 | + 'res':res, | ||
266 | + 'options':{}, | ||
267 | + 'excludeToken':true | ||
268 | + }; | ||
269 | + rest.del(options); | ||
270 | + } | ||
271 | + function _cb(data,response){ | ||
272 | + logger.info('back data:',data); | ||
273 | + if(response.statusCode<300){ | ||
274 | + res.send({'action':'delete',"message":"删除成功"}); | ||
275 | + }else{ | ||
276 | + res.send(data); | ||
277 | + } | ||
278 | + } | ||
279 | + } | ||
280 | + | ||
281 | + function doLogin(req,res,next){ | ||
282 | + passport.authenticate('local', function(err, user, info) { | ||
283 | + if (err) { return next(err); } | ||
284 | + if (!user) { return res.send({'error':'用户名或密码错误!'}); } | ||
285 | + req.logIn(user, function(err) { | ||
286 | + if (err) { return next(err); } | ||
287 | + return res.send({'ok':'登录成功',user_info:req.session.passport.user.user_info}); | ||
288 | + }); | ||
289 | + })(req, res, next); | ||
290 | + } | ||
291 | + | ||
292 | + return { | ||
293 | + 'get':get, | ||
294 | + 'post':post, | ||
295 | + 'put':put, | ||
296 | + 'patch':patch, | ||
297 | + 'head':head, | ||
298 | + 'delete':del | ||
299 | + }; | ||
300 | +}; | ||
301 | + | ||
302 | +exports['@singleton']=true; | ||
303 | +exports['@require']=['igloo/logger','utils/rest','igloo/settings']; |
server/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 | + var url=fullUrl.substring(9); | ||
61 | + return url; | ||
62 | + } | ||
63 | + | ||
64 | + function searchService(services,name){ | ||
65 | + if(services[name]){ | ||
66 | + console.log(services[name]); | ||
67 | + return false; | ||
68 | + }else{ | ||
69 | + return true; | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + function checkReq(req,res){ | ||
74 | + var flag=true; | ||
75 | + // if(flag&&req.headers&&!req.headers['service-catalog']){ | ||
76 | + // res.status(400); | ||
77 | + // res.send({"errors":{},"message":"缺少必要请求参数,服务目录名称是必填项"}); | ||
78 | + // flag=false; | ||
79 | + // } | ||
80 | + // if(flag&&req.session.passport&&req.session.passport.user&&!req.session.passport.user.service_catalog){ | ||
81 | + // res.status(404); | ||
82 | + // res.send({"errors":{},"message":"服务目录未加载,请重新登录"}); | ||
83 | + // flag=false; | ||
84 | + // } | ||
85 | + // if(flag&&searchService(req.session.passport.user.service_catalog,req.headers['service-catalog'])){ | ||
86 | + // res.status(404); | ||
87 | + // res.send({"errors":{},"message":"服务目录未查询到请求服务,请确认参数正确"}); | ||
88 | + // flag=false; | ||
89 | + // } | ||
90 | + return flag; | ||
91 | + } | ||
92 | + | ||
93 | + function checkJson(req){ | ||
94 | + if(req.headers&&req.headers['content-type']=='application/json'){ | ||
95 | + return true; | ||
96 | + }else{ | ||
97 | + return false; | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + function get(req,res,next){ | ||
102 | + var url=splitUrl(req.originalUrl); | ||
103 | + url=handlePamars(url); | ||
104 | + url=splitServiceFromUrl(url); | ||
105 | + if(checkReq(req,res)){ | ||
106 | + var options={ | ||
107 | + 'service_catalog':'', | ||
108 | + 'url':url, | ||
109 | + 'useUrl':true, | ||
110 | + 'params':req.body, | ||
111 | + 'callback':_cb, | ||
112 | + 'req':req, | ||
113 | + 'res':res, | ||
114 | + 'options':{} | ||
115 | + }; | ||
116 | + rest.get(options); | ||
117 | + } | ||
118 | + function _cb(data,response){ | ||
119 | + logger.info('back data:',data); | ||
120 | + if(response.statusCode<300&&!data){ | ||
121 | + res.send({ | ||
122 | + code:200, | ||
123 | + message:'操作成功!' | ||
124 | + }); | ||
125 | + }else { | ||
126 | + res.send(data); | ||
127 | + } | ||
128 | + } | ||
129 | + } | ||
130 | + | ||
131 | + function post(req,res,next){ | ||
132 | + var url=splitUrl(req.originalUrl); | ||
133 | + url=splitServiceFromUrl(url); | ||
134 | + if(checkReq(req,res)){ | ||
135 | + var options={ | ||
136 | + 'service_catalog':'services[catalog].public_endpoint', | ||
137 | + 'url':url, | ||
138 | + 'useUrl':true, | ||
139 | + 'params':req.body, | ||
140 | + 'callback':_cb, | ||
141 | + 'req':req, | ||
142 | + 'res':res, | ||
143 | + 'options':{} | ||
144 | + }; | ||
145 | + if(checkJson(req)){ | ||
146 | + rest.postJson(options); | ||
147 | + }else{ | ||
148 | + rest.post(options); | ||
149 | + } | ||
150 | + } | ||
151 | + function _cb(data,response){ | ||
152 | + logger.info('back data:',data); | ||
153 | + if(response.statusCode<300&&!data){ | ||
154 | + res.send({ | ||
155 | + code:200, | ||
156 | + message:'操作成功!' | ||
157 | + }); | ||
158 | + }else{ | ||
159 | + res.send(data); | ||
160 | + } | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | + function put(req,res,next){ | ||
165 | + var url=splitUrl(req.originalUrl); | ||
166 | + url=splitServiceFromUrl(url); | ||
167 | + if(checkReq(req,res)){ | ||
168 | + var options={ | ||
169 | + 'service_catalog':'services[catalog].public_endpoint', | ||
170 | + 'url': url, | ||
171 | + 'useUrl':true, | ||
172 | + 'params':req.body, | ||
173 | + 'callback':_cb, | ||
174 | + 'req':req, | ||
175 | + 'res':res, | ||
176 | + 'options':{} | ||
177 | + }; | ||
178 | + if(checkJson(req)){ | ||
179 | + rest.putJson(options); | ||
180 | + }else{ | ||
181 | + rest.put(options); | ||
182 | + } | ||
183 | + } | ||
184 | + function _cb(data,response){ | ||
185 | + logger.info('back data:',data); | ||
186 | + if(response.statusCode<300&&!data){ | ||
187 | + res.send({ | ||
188 | + code:200, | ||
189 | + message:'操作成功!' | ||
190 | + }); | ||
191 | + }else{ | ||
192 | + res.send(data); | ||
193 | + } | ||
194 | + } | ||
195 | + } | ||
196 | + | ||
197 | + function patch(req,res,next){ | ||
198 | + var url=splitUrl(req.originalUrl); | ||
199 | + url=splitServiceFromUrl(url); | ||
200 | + if(checkReq(req,res)){ | ||
201 | + var options={ | ||
202 | + 'service_catalog':'services[catalog].public_endpoint', | ||
203 | + 'url': url, | ||
204 | + 'useUrl':true, | ||
205 | + 'params':req.body, | ||
206 | + 'callback':_cb, | ||
207 | + 'req':req, | ||
208 | + 'res':res, | ||
209 | + 'options':{} | ||
210 | + }; | ||
211 | + if(checkJson(req)){ | ||
212 | + rest.patchJson(options); | ||
213 | + }else{ | ||
214 | + rest.patch(options); | ||
215 | + } | ||
216 | + } | ||
217 | + function _cb(data,response){ | ||
218 | + logger.info('back data:',data); | ||
219 | + res.send(data); | ||
220 | + } | ||
221 | + } | ||
222 | + | ||
223 | + function head(req,res,next){ | ||
224 | + var url=splitUrl(req.originalUrl); | ||
225 | + url=splitServiceFromUrl(url); | ||
226 | + if(checkReq(req,res)){ | ||
227 | + var options={ | ||
228 | + 'service_catalog':'services[catalog].public_endpoint', | ||
229 | + 'url': url, | ||
230 | + 'useUrl':true, | ||
231 | + 'params':req.body, | ||
232 | + 'callback':_cb, | ||
233 | + 'req':req, | ||
234 | + 'res':res, | ||
235 | + 'options':{} | ||
236 | + }; | ||
237 | + rest.get(options); | ||
238 | + } | ||
239 | + function _cb(data,response){ | ||
240 | + logger.info('back data:',data); | ||
241 | + res.send(data); | ||
242 | + } | ||
243 | + } | ||
244 | + | ||
245 | + function del(req,res,next){ | ||
246 | + var url=splitUrl(req.originalUrl); | ||
247 | + url=splitServiceFromUrl(url); | ||
248 | + if(checkReq(req,res)){ | ||
249 | + var options={ | ||
250 | + 'service_catalog':'services[catalog].public_endpoint', | ||
251 | + 'url': url, | ||
252 | + 'useUrl':true, | ||
253 | + 'params':req.body, | ||
254 | + 'callback':_cb, | ||
255 | + 'req':req, | ||
256 | + 'res':res, | ||
257 | + 'options':{} | ||
258 | + }; | ||
259 | + rest.del(options); | ||
260 | + } | ||
261 | + function _cb(data,response){ | ||
262 | + logger.info('back data:',data); | ||
263 | + if(response.statusCode<300){ | ||
264 | + res.send({'action':'delete',"message":"删除成功"}); | ||
265 | + }else{ | ||
266 | + res.send(data); | ||
267 | + } | ||
268 | + } | ||
269 | + } | ||
270 | + | ||
271 | + return { | ||
272 | + 'get':get, | ||
273 | + 'post':post, | ||
274 | + 'put':put, | ||
275 | + 'patch':patch, | ||
276 | + 'head':head, | ||
277 | + 'delete':del | ||
278 | + }; | ||
279 | +}; | ||
280 | + | ||
281 | +exports['@singleton']=true; | ||
282 | +exports['@require']=['igloo/logger','utils/rest','igloo/settings']; |
server/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']; |
server/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 | + var url=fullUrl.substring(9); | ||
13 | + return url; | ||
14 | + } | ||
15 | + | ||
16 | + function get(req,res,next){ | ||
17 | + var url=splitUrl(req.originalUrl); | ||
18 | + rest.get({ | ||
19 | + 'baseUrl':'url', | ||
20 | + 'url':api_service_endpoint+url, | ||
21 | + 'useUrl':true, | ||
22 | + 'params':req.body, | ||
23 | + 'callback':_cb, | ||
24 | + 'req':req, | ||
25 | + 'res':res, | ||
26 | + 'options':{}, | ||
27 | + 'excludeToken':true | ||
28 | + }); | ||
29 | + function _cb(data,response){ | ||
30 | + console.log(data); | ||
31 | + res.send(data); | ||
32 | + } | ||
33 | + // res.send({ | ||
34 | + // "total_count":20, | ||
35 | + // "items":[{ | ||
36 | + // "id":'001', | ||
37 | + // "call_out_number":'18501068035', | ||
38 | + // "call_out_time":2022222, | ||
39 | + // "status":"4", | ||
40 | + // "record_url":'xxxx' | ||
41 | + // }] | ||
42 | + // }) | ||
43 | + } | ||
44 | + | ||
45 | + function post(req,res,next){ | ||
46 | + var url=splitUrl(req.originalUrl); | ||
47 | + rest.postJson({ | ||
48 | + 'baseUrl':'url', | ||
49 | + 'url':api_service_endpoint+url, | ||
50 | + 'useUrl':true, | ||
51 | + 'params':req.body, | ||
52 | + 'callback':_cb, | ||
53 | + 'req':req, | ||
54 | + 'res':res, | ||
55 | + 'options':{}, | ||
56 | + 'excludeToken':true | ||
57 | + }); | ||
58 | + function _cb(data,response){ | ||
59 | + console.log(data); | ||
60 | + res.send(data); | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + function put(req,res,next){ | ||
65 | + var url=splitUrl(req.originalUrl); | ||
66 | + rest.putJson({ | ||
67 | + 'baseUrl':'url', | ||
68 | + 'url':api_service_endpoint+url, | ||
69 | + 'useUrl':true, | ||
70 | + 'params':req.body, | ||
71 | + 'callback':_cb, | ||
72 | + 'req':req, | ||
73 | + 'res':res, | ||
74 | + 'options':{}, | ||
75 | + 'excludeToken':true | ||
76 | + }); | ||
77 | + function _cb(data,response){ | ||
78 | + res.send(data); | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + function patch(req,res,next){ | ||
83 | + var url=splitUrl(req.originalUrl); | ||
84 | + rest.patchJson({ | ||
85 | + 'baseUrl':'url', | ||
86 | + 'url':api_service_endpoint+url, | ||
87 | + 'useUrl':true, | ||
88 | + 'params':req.body, | ||
89 | + 'callback':_cb, | ||
90 | + 'req':req, | ||
91 | + 'res':res, | ||
92 | + 'options':{}, | ||
93 | + 'excludeToken':true | ||
94 | + }); | ||
95 | + function _cb(data,response){ | ||
96 | + res.send(data); | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + function head(req,res,next){ | ||
101 | + var url=splitUrl(req.originalUrl); | ||
102 | + rest.get({ | ||
103 | + 'baseUrl':'url', | ||
104 | + 'url':api_service_endpoint+url, | ||
105 | + 'useUrl':true, | ||
106 | + 'params':req.body, | ||
107 | + 'callback':_cb, | ||
108 | + 'req':req, | ||
109 | + 'res':res, | ||
110 | + 'options':{}, | ||
111 | + 'excludeToken':true | ||
112 | + }); | ||
113 | + function _cb(data,response){ | ||
114 | + res.send(data); | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + function del(req,res,next){ | ||
119 | + var url=splitUrl(req.originalUrl); | ||
120 | + rest.del({ | ||
121 | + 'baseUrl':'url', | ||
122 | + 'url':api_service_endpoint+url, | ||
123 | + 'useUrl':true, | ||
124 | + 'params':req.body, | ||
125 | + 'callback':_cb, | ||
126 | + 'req':req, | ||
127 | + 'res':res, | ||
128 | + 'options':{}, | ||
129 | + 'excludeToken':true | ||
130 | + }); | ||
131 | + function _cb(data,response){ | ||
132 | + res.send(data); | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + return { | ||
137 | + 'index':index, | ||
138 | + 'get':get, | ||
139 | + 'post':post, | ||
140 | + 'put':put, | ||
141 | + 'patch':patch, | ||
142 | + 'head':head, | ||
143 | + 'delete':del | ||
144 | + }; | ||
145 | +}; | ||
146 | + | ||
147 | +exports['@singleton']=true; | ||
148 | +exports['@require']=['igloo/logger','utils/rest','igloo/settings']; |
server/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' ]; |
server/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 serveStatic = require('serve-static'); | ||
8 | +var winstonRequestLogger = require('winston-request-logger'); | ||
9 | +var methodOverride = require('method-override'); | ||
10 | +var bodyParser = require('body-parser'); | ||
11 | +var responseTime = require('response-time'); | ||
12 | +// var busboy = require('connect-busboy'); | ||
13 | + | ||
14 | + | ||
15 | +exports = module.exports = function(IoC, logger, settings, policies) { | ||
16 | + | ||
17 | + var app = this; | ||
18 | + | ||
19 | + // ignore GET /favicon.ico | ||
20 | + // app.use(serveFavicon(path.join(settings.publicDir, 'favicon.ico'))); | ||
21 | + | ||
22 | + if (settings.server.env === 'development') { | ||
23 | + | ||
24 | + } | ||
25 | + | ||
26 | + // static server (always keep this first) | ||
27 | + // <http://goo.gl/j2BEl5> | ||
28 | + app.use(serveStatic(settings.publicDir, settings.staticServer)); | ||
29 | + | ||
30 | + // adds X-Response-Time header | ||
31 | + app.use(responseTime({ | ||
32 | + digits: 5 | ||
33 | + })); | ||
34 | + | ||
35 | + // prepare req.log for error handler | ||
36 | + app.use(function(req, res, next) { | ||
37 | + req.log = { | ||
38 | + response_time: new Date().getTime(), | ||
39 | + path: req.path, | ||
40 | + query: req.query, | ||
41 | + body: req.body, | ||
42 | + params: req.params | ||
43 | + }; | ||
44 | + next(); | ||
45 | + }); | ||
46 | + | ||
47 | + // winston request logger before everything else | ||
48 | + // but only if it was enabled in settings | ||
49 | + if (settings.logger.requests) { | ||
50 | + app.use(winstonRequestLogger.create(logger)); | ||
51 | + } | ||
52 | + | ||
53 | + // parse request bodies | ||
54 | + // support _method (PUT in forms etc) | ||
55 | + app.use( | ||
56 | + bodyParser.json({limit: '10mb'}), | ||
57 | + bodyParser.urlencoded({ | ||
58 | + limit: '10mb', | ||
59 | + extended: true | ||
60 | + }), | ||
61 | + methodOverride('_method') | ||
62 | + ); | ||
63 | + //support "application/x-www-formurlencoded" or starts with "multipart/*" | ||
64 | + // app.use(busboy({ | ||
65 | + // limits: { | ||
66 | + // fileSize: 10 * 1024 * 1024 | ||
67 | + // } | ||
68 | + // })) | ||
69 | + | ||
70 | +}; | ||
71 | + | ||
72 | +exports['@require'] = [ '$container', 'igloo/logger', 'igloo/settings', 'policies' ]; |
server/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' ]; |
server/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' ]; |
server/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' ]; |
server/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' ]; |
server/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 | +}] |
server/json/payRoll.json
0 → 100644
此 diff 太大无法显示。
server/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' ]; |
server/routes/api.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +exports = module.exports = function(IoC,policies){ | ||
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('/api', router); | ||
45 | +}; | ||
46 | + | ||
47 | +exports['@require']=['$container','policies']; | ||
48 | +exports['@singleton']=true; |
server/routes/auth.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +var payRoll = require('../json/payRoll.json'); | ||
3 | + | ||
4 | +exports = module.exports = function (IoC, policies) { | ||
5 | + var app = this; | ||
6 | + var router = express.Router(); | ||
7 | + var controller = IoC.create('controllers/auth'); | ||
8 | + router.get( | ||
9 | + '/', | ||
10 | + controller.index | ||
11 | + ); | ||
12 | + router.get( | ||
13 | + '/productDes', | ||
14 | + controller.productDes | ||
15 | + ); | ||
16 | + | ||
17 | + router.get( | ||
18 | + '/register', | ||
19 | + controller.register | ||
20 | + ); | ||
21 | + | ||
22 | + router.get( | ||
23 | + '/mobileRegister', | ||
24 | + controller.mobileRegister | ||
25 | + ); | ||
26 | + | ||
27 | + router.get( | ||
28 | + '/mobileRegisterSuccess', | ||
29 | + controller.mobileRegisterSuccess | ||
30 | + ); | ||
31 | + | ||
32 | + router.get( | ||
33 | + '/signIn', | ||
34 | + controller.signIn | ||
35 | + ); | ||
36 | + | ||
37 | + router.post( | ||
38 | + '/doLogin', | ||
39 | + controller.doLogin | ||
40 | + ); | ||
41 | + | ||
42 | + router.get( | ||
43 | + '/signOut', | ||
44 | + controller.signOut | ||
45 | + ); | ||
46 | + | ||
47 | + router.post( | ||
48 | + '/smsCodes', | ||
49 | + controller.smsCodes | ||
50 | + ); | ||
51 | + | ||
52 | + router.post( | ||
53 | + '/tenants', | ||
54 | + controller.tenants | ||
55 | + ); | ||
56 | + | ||
57 | + router.post( | ||
58 | + '/resetPass', | ||
59 | + policies.ensureLoggedOut(), | ||
60 | + controller.resetPass | ||
61 | + ); | ||
62 | + | ||
63 | + router.post( | ||
64 | + '/updatePassword', | ||
65 | + policies.ensureLoggedOut(), | ||
66 | + controller.updatePassword | ||
67 | + ); | ||
68 | + | ||
69 | + | ||
70 | + router.post( | ||
71 | + '/loadUserInfo', | ||
72 | + policies.ensureLoggedOut(), | ||
73 | + controller.loadUserInfo | ||
74 | + ); | ||
75 | + | ||
76 | + router.post( | ||
77 | + '/getUploaderToken', | ||
78 | + policies.ensureLoggedOut(), | ||
79 | + controller.getUploaderToken | ||
80 | + ); | ||
81 | + | ||
82 | + router.post( | ||
83 | + '/delOSSObject', | ||
84 | + policies.ensureLoggedOut(), | ||
85 | + controller.delOSSObject | ||
86 | + ); | ||
87 | + | ||
88 | + router.post( | ||
89 | + '/smsVerification', | ||
90 | + controller.smsVerification | ||
91 | + ) | ||
92 | + | ||
93 | + router.post( | ||
94 | + '/getObjectTokenByID', | ||
95 | + controller.getObjectTokenByID | ||
96 | + ) | ||
97 | + | ||
98 | + // router.get( | ||
99 | + // '/healthMonitor', | ||
100 | + // controller.healthMonitor | ||
101 | + // ) | ||
102 | + | ||
103 | + // router.head( | ||
104 | + // '/healthMonitor', | ||
105 | + // controller.healthMonitor | ||
106 | + // ) | ||
107 | + | ||
108 | + router.post( | ||
109 | + '/getUserRoles', | ||
110 | + policies.ensureLoggedOut(), | ||
111 | + controller.getUserRoles | ||
112 | + ); | ||
113 | + | ||
114 | + router.post( | ||
115 | + '/getRoles', | ||
116 | + policies.ensureLoggedOut(), | ||
117 | + controller.getRoles | ||
118 | + ); | ||
119 | + | ||
120 | + router.post( | ||
121 | + '/updateUserRoles', | ||
122 | + policies.ensureLoggedOut(), | ||
123 | + controller.updateUserRoles | ||
124 | + ); | ||
125 | + | ||
126 | + router.post( | ||
127 | + '/getTenant', | ||
128 | + policies.ensureLoggedOut(), | ||
129 | + controller.getTenant | ||
130 | + ); | ||
131 | + | ||
132 | + router.post( | ||
133 | + '/updateTenant', | ||
134 | + policies.ensureLoggedOut(), | ||
135 | + controller.updateTenant | ||
136 | + ); | ||
137 | + | ||
138 | + router.get( | ||
139 | + '/offer/:requestId', | ||
140 | + controller.offer | ||
141 | + ); | ||
142 | + | ||
143 | + router.post( | ||
144 | + '/onboardStatus', | ||
145 | + policies.ensureLoggedOut(), | ||
146 | + controller.onboardStatus | ||
147 | + ); | ||
148 | + | ||
149 | + router.get( | ||
150 | + '/downloadApp', | ||
151 | + controller.dowloadApp | ||
152 | + ); | ||
153 | + | ||
154 | + router.get( | ||
155 | + '/info/policy', | ||
156 | + controller.softwareLicense | ||
157 | + ); | ||
158 | + | ||
159 | + router.get('/payRoll', function (req, res, next) { | ||
160 | + res.send(payRoll); | ||
161 | + }); | ||
162 | + | ||
163 | + router.get( | ||
164 | + '/recharge', | ||
165 | + controller.recharge | ||
166 | + ); | ||
167 | + | ||
168 | + router.post( | ||
169 | + '/changePassForRegister', | ||
170 | + controller.changePassForRegister | ||
171 | + ); | ||
172 | + | ||
173 | + router.post( | ||
174 | + '/changeTenant', | ||
175 | + policies.ensureLoggedOut(), | ||
176 | + controller.changeTenant | ||
177 | + ); | ||
178 | + | ||
179 | + router.post( | ||
180 | + '/hr/sendRejectOffer', | ||
181 | + controller.sendRejectOffer | ||
182 | + ); | ||
183 | + | ||
184 | + router.post( | ||
185 | + '/hr/acceptOffer', | ||
186 | + controller.acceptOffer | ||
187 | + ); | ||
188 | + | ||
189 | + router.post( | ||
190 | + '/imTokens', | ||
191 | + policies.ensureLoggedOut(), | ||
192 | + controller.imTokens | ||
193 | + ); | ||
194 | + | ||
195 | + router.post( | ||
196 | + '/listChannels', | ||
197 | + policies.ensureLoggedOut(), | ||
198 | + controller.listChannels | ||
199 | + ); | ||
200 | + | ||
201 | + router.get( | ||
202 | + '/filemeta', | ||
203 | + policies.ensureLoggedOut(), | ||
204 | + controller.filemeta | ||
205 | + ); | ||
206 | + | ||
207 | + router.get( | ||
208 | + '/getCustomerQrcode', | ||
209 | + policies.ensureLoggedOut(), | ||
210 | + controller.getCustomerQrcode | ||
211 | + ); | ||
212 | + | ||
213 | + router.get( | ||
214 | + '/getPositionQrcode', | ||
215 | + policies.ensureLoggedOut(), | ||
216 | + controller.getPositionQrcode | ||
217 | + ); | ||
218 | + router.get( //微店模板路由 | ||
219 | + '/minishop/:id', | ||
220 | + controller.weidianTempLate | ||
221 | + ); | ||
222 | + | ||
223 | + app.use('/', router); | ||
224 | +}; | ||
225 | + | ||
226 | +exports['@require'] = ['$container', 'policies']; | ||
227 | +exports['@singleton'] = true; |
server/routes/authed.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +exports = module.exports = function(IoC,policies){ | ||
4 | + var app = this; | ||
5 | + var router= express.Router(); | ||
6 | + var controller = IoC.create('controllers/authed'); | ||
7 | + | ||
8 | + router.get( | ||
9 | + '/*', | ||
10 | + controller.get | ||
11 | + ); | ||
12 | + | ||
13 | + router.post( | ||
14 | + '/*', | ||
15 | + controller.post | ||
16 | + ); | ||
17 | + | ||
18 | + router.put( | ||
19 | + '/*', | ||
20 | + controller.put | ||
21 | + ); | ||
22 | + | ||
23 | + router.patch( | ||
24 | + '/*', | ||
25 | + controller.patch | ||
26 | + ); | ||
27 | + | ||
28 | + router.head( | ||
29 | + '/*', | ||
30 | + controller.head | ||
31 | + ); | ||
32 | + | ||
33 | + router.delete( | ||
34 | + '/*', | ||
35 | + controller.delete | ||
36 | + ); | ||
37 | + | ||
38 | + app.use('/auth_api', router); | ||
39 | +}; | ||
40 | + | ||
41 | +exports['@require']=['$container','policies']; | ||
42 | +exports['@singleton']=true; |
server/routes/bootstarp.js
0 → 100644
1 | + | ||
2 | +// app - routes | ||
3 | + | ||
4 | +var bootable = require('bootable'); | ||
5 | + | ||
6 | +exports = module.exports = function(IoC, settings) { | ||
7 | + | ||
8 | + var app = this; | ||
9 | + | ||
10 | + //auth | ||
11 | + app.phase(bootable.di.routes('./routes/auth.js')); | ||
12 | + | ||
13 | + //mock | ||
14 | + app.phase(bootable.di.routes('./routes/mock.js')); | ||
15 | + //authed | ||
16 | + | ||
17 | + app.phase(bootable.di.routes('./routes/authed.js')); | ||
18 | + | ||
19 | + //api | ||
20 | + app.phase(bootable.di.routes('./routes/api.js')); | ||
21 | + | ||
22 | + //file | ||
23 | + app.phase(bootable.di.routes('./routes/file.js')); | ||
24 | + | ||
25 | + //robot | ||
26 | + app.phase(bootable.di.routes('./routes/robot.js')); | ||
27 | + | ||
28 | + // error handler (always keep this last) | ||
29 | + app.phase(function() { | ||
30 | + var errorHandler = IoC.create('igloo/error-handler'); | ||
31 | + app.use(errorHandler); | ||
32 | + }); | ||
33 | + | ||
34 | +}; | ||
35 | + | ||
36 | +exports['@require'] = [ '$container', 'igloo/settings' ]; |
server/routes/file.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +exports = module.exports = function(IoC,policies){ | ||
4 | + var app = this; | ||
5 | + var router= express.Router(); | ||
6 | + var controller = IoC.create('controllers/file'); | ||
7 | + | ||
8 | + router.get( | ||
9 | + '/*', | ||
10 | + controller.get | ||
11 | + ); | ||
12 | + | ||
13 | + router.post( | ||
14 | + '/*', | ||
15 | + controller.post | ||
16 | + ); | ||
17 | + | ||
18 | + router.put( | ||
19 | + '/*', | ||
20 | + controller.put | ||
21 | + ); | ||
22 | + | ||
23 | + router.patch( | ||
24 | + '/*', | ||
25 | + controller.patch | ||
26 | + ); | ||
27 | + | ||
28 | + router.head( | ||
29 | + '/*', | ||
30 | + controller.head | ||
31 | + ); | ||
32 | + | ||
33 | + router.delete( | ||
34 | + '/*', | ||
35 | + controller.delete | ||
36 | + ); | ||
37 | + | ||
38 | + app.use('/file_api', router); | ||
39 | +}; | ||
40 | + | ||
41 | +exports['@require']=['$container','policies']; | ||
42 | +exports['@singleton']=true; |
server/routes/mock.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +exports = module.exports = function(IoC,policies){ | ||
4 | + var app = this; | ||
5 | + var router= express.Router(); | ||
6 | + var controller = IoC.create('controllers/mock'); | ||
7 | + | ||
8 | + router.get( | ||
9 | + '/*', | ||
10 | + policies.ensureLoggedOut(), | ||
11 | + controller.get | ||
12 | + ); | ||
13 | + | ||
14 | + router.post( | ||
15 | + '/*', | ||
16 | + policies.ensureLoggedOut(), | ||
17 | + controller.post | ||
18 | + ); | ||
19 | + | ||
20 | + router.put( | ||
21 | + '/*', | ||
22 | + policies.ensureLoggedOut(), | ||
23 | + controller.put | ||
24 | + ); | ||
25 | + | ||
26 | + router.patch( | ||
27 | + '/*', | ||
28 | + policies.ensureLoggedOut(), | ||
29 | + controller.patch | ||
30 | + ); | ||
31 | + | ||
32 | + router.head( | ||
33 | + '/*', | ||
34 | + policies.ensureLoggedOut(), | ||
35 | + controller.head | ||
36 | + ); | ||
37 | + | ||
38 | + router.delete( | ||
39 | + '/*', | ||
40 | + policies.ensureLoggedOut(), | ||
41 | + controller.delete | ||
42 | + ); | ||
43 | + | ||
44 | + app.use('/mock/api', router); | ||
45 | +}; | ||
46 | + | ||
47 | +exports['@require']=['$container','policies']; | ||
48 | +exports['@singleton']=true; |
server/routes/robot.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +exports = module.exports = function(IoC,policies){ | ||
4 | + var app = this; | ||
5 | + var router= express.Router(); | ||
6 | + var controller = IoC.create('controllers/robot'); | ||
7 | + router.get( | ||
8 | + '/robot', | ||
9 | + controller.index | ||
10 | + ); | ||
11 | + | ||
12 | + router.get( | ||
13 | + '/api/*', | ||
14 | + controller.get | ||
15 | + ); | ||
16 | + | ||
17 | + router.post( | ||
18 | + '/api/*', | ||
19 | + controller.post | ||
20 | + ); | ||
21 | + | ||
22 | + router.put( | ||
23 | + '/api/*', | ||
24 | + controller.put | ||
25 | + ); | ||
26 | + | ||
27 | + router.patch( | ||
28 | + '/api/*', | ||
29 | + controller.patch | ||
30 | + ); | ||
31 | + | ||
32 | + router.head( | ||
33 | + '/api/*', | ||
34 | + controller.head | ||
35 | + ); | ||
36 | + | ||
37 | + router.delete( | ||
38 | + '/api/*', | ||
39 | + controller.delete | ||
40 | + ); | ||
41 | + | ||
42 | + app.use('/demo', router); | ||
43 | +}; | ||
44 | + | ||
45 | +exports['@require']=['$container','policies']; | ||
46 | +exports['@singleton']=true; |
server/test/01-server.test.js
0 → 100644
1 | + | ||
2 | +// # tests - server | ||
3 | + | ||
4 | +var util = require('util'); | ||
5 | +var request = require('supertest'); | ||
6 | +var app = require('../app'); | ||
7 | +var chai = require('chai'); | ||
8 | +var sinon = require('sinon'); | ||
9 | +var sinonChai = require('sinon-chai'); | ||
10 | +var expect = chai.expect; | ||
11 | + | ||
12 | +chai.should(); | ||
13 | +chai.use(sinonChai); | ||
14 | + | ||
15 | +request = request(app); | ||
16 | + | ||
17 | +describe('server', function() { | ||
18 | + | ||
19 | + it('should return 200 if home page loads', function(done) { | ||
20 | + request | ||
21 | + .get('/') | ||
22 | + .accept('application/json') | ||
23 | + .expect(200) | ||
24 | + .end(done); | ||
25 | + }); | ||
26 | + | ||
27 | +}); |
server/test/02-users.test.js
0 → 100644
1 | + | ||
2 | +// # tests - users | ||
3 | + | ||
4 | +var util = require('util'); | ||
5 | +var request = require('supertest'); | ||
6 | +var app = require('../app'); | ||
7 | +var chai = require('chai'); | ||
8 | +var sinon = require('sinon'); | ||
9 | +var sinonChai = require('sinon-chai'); | ||
10 | +var expect = chai.expect; | ||
11 | +var utils = require('./utils'); | ||
12 | +var async = require('async'); | ||
13 | +var IoC = require('electrolyte'); | ||
14 | +var cheerio = require('cheerio'); | ||
15 | + | ||
16 | +chai.should(); | ||
17 | +chai.use(sinonChai); | ||
18 | + | ||
19 | +request = request(app); | ||
20 | + | ||
21 | +// storage for context-specific variables throughout the tests | ||
22 | +var context = {}; | ||
23 | + | ||
24 | +describe('/users', function() { | ||
25 | + | ||
26 | + var User = IoC.create('models/user'); | ||
27 | + | ||
28 | + // Clean DB and add 3 sample users before tests start | ||
29 | + before(function(done) { | ||
30 | + async.waterfall([ | ||
31 | + utils.cleanDatabase, | ||
32 | + function createTestUsers(callback) { | ||
33 | + // Create 3 test users | ||
34 | + async.timesSeries(3, function(i, _callback) { | ||
35 | + var user = new User({ | ||
36 | + email: 'email+' + i + '@example.com', | ||
37 | + name: 'User #' + i, | ||
38 | + surname: 'Last Name #' + i, | ||
39 | + password: '1234' + i | ||
40 | + }); | ||
41 | + | ||
42 | + user.save(_callback); | ||
43 | + }, callback); | ||
44 | + } | ||
45 | + ], done); | ||
46 | + }); | ||
47 | + | ||
48 | + // Clean DB after all tests are done | ||
49 | + after(function(done) { | ||
50 | + utils.cleanDatabase(done); | ||
51 | + }); | ||
52 | + | ||
53 | + it('POST /users - should return 200 if user was created', function(done) { | ||
54 | + this.timeout(3000); // The first request sometimes takes longer to complete | ||
55 | + | ||
56 | + request | ||
57 | + .post('/users') | ||
58 | + .set({ | ||
59 | + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled | ||
60 | + }) | ||
61 | + .accept('application/json') | ||
62 | + .send({ | ||
63 | + email: util.format('niftylettuce+%s@gmail.com', new Date().getTime()), | ||
64 | + name: 'Nifty', | ||
65 | + surname: 'Lettuce', | ||
66 | + password: 'abc123' | ||
67 | + }) | ||
68 | + .expect(200) | ||
69 | + .end(function(err, res) { | ||
70 | + if (err) return done(err); | ||
71 | + | ||
72 | + // Test the attributes exist | ||
73 | + expect(res.body).to.exist; | ||
74 | + res.body.should.have.property('id'); | ||
75 | + res.body.should.have.property('name'); | ||
76 | + res.body.should.have.property('surname'); | ||
77 | + res.body.should.not.have.property('password'); | ||
78 | + | ||
79 | + // Test the values make sense | ||
80 | + res.body.name.should.equal('Nifty'); | ||
81 | + res.body.surname.should.equal('Lettuce'); | ||
82 | + | ||
83 | + // Store this id to use later | ||
84 | + context.userIdCreatedWithRequest = res.body.id; | ||
85 | + | ||
86 | + done(); | ||
87 | + }); | ||
88 | + }); | ||
89 | + | ||
90 | + it('GET /users/:id — should return 200 if user was retrieved', function(done) { | ||
91 | + request | ||
92 | + .get(util.format('/users/%s', context.userIdCreatedWithRequest)) | ||
93 | + .accept('application/json') | ||
94 | + .expect(200) | ||
95 | + .end(function(err, res) { | ||
96 | + if (err) return done(err); | ||
97 | + | ||
98 | + // Test the attributes exist | ||
99 | + expect(res.body).to.exist; | ||
100 | + res.body.should.have.property('id'); | ||
101 | + res.body.should.have.property('name'); | ||
102 | + res.body.should.have.property('surname'); | ||
103 | + res.body.should.not.have.property('password'); | ||
104 | + | ||
105 | + // Test the values make sense | ||
106 | + res.body.name.should.equal('Nifty'); | ||
107 | + res.body.surname.should.equal('Lettuce'); | ||
108 | + | ||
109 | + done(); | ||
110 | + }); | ||
111 | + }); | ||
112 | + | ||
113 | + it('PUT /users/:id - should return 200 if user was updated', function(done) { | ||
114 | + request | ||
115 | + .put(util.format('/users/%s', context.userIdCreatedWithRequest)) | ||
116 | + .set({ | ||
117 | + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled | ||
118 | + }) | ||
119 | + .accept('application/json') | ||
120 | + .send({ | ||
121 | + name: 'NiftyWhoa', | ||
122 | + email: 'niftywhoa@gmail.com', | ||
123 | + surname: 'LettuceWhoa' | ||
124 | + }) | ||
125 | + .expect(200) | ||
126 | + .end(function(err, res) { | ||
127 | + if (err) return done(err); | ||
128 | + | ||
129 | + // Test the attributes exist | ||
130 | + expect(res.body).to.exist; | ||
131 | + res.body.should.have.property('id'); | ||
132 | + res.body.should.have.property('email'); | ||
133 | + res.body.should.have.property('name'); | ||
134 | + res.body.should.have.property('surname'); | ||
135 | + | ||
136 | + // Test the values make sense | ||
137 | + res.body.email.should.equal('niftywhoa@gmail.com'); | ||
138 | + res.body.name.should.equal('NiftyWhoa'); | ||
139 | + res.body.surname.should.equal('LettuceWhoa'); | ||
140 | + | ||
141 | + done(); | ||
142 | + }); | ||
143 | + }); | ||
144 | + | ||
145 | + it('DELETE /users/:id - should return 200 if user was deleted', function(done) { | ||
146 | + request | ||
147 | + .del(util.format('/users/%s', context.userIdCreatedWithRequest)) | ||
148 | + .set({ | ||
149 | + 'X-Requested-With': 'XMLHttpRequest'// We need to set this so CSRF is ignored when enabled | ||
150 | + }) | ||
151 | + .accept('application/json') | ||
152 | + .expect(200) | ||
153 | + .end(function(err, res) { | ||
154 | + if (err) return done(err); | ||
155 | + | ||
156 | + // Test the attributes exist | ||
157 | + expect(res.body).to.exist; | ||
158 | + res.body.should.have.property('id'); | ||
159 | + res.body.should.have.property('deleted'); | ||
160 | + | ||
161 | + // Test the values make sense | ||
162 | + res.body.id.should.equal(context.userIdCreatedWithRequest); | ||
163 | + res.body.deleted.should.equal(true); | ||
164 | + | ||
165 | + done(); | ||
166 | + }); | ||
167 | + }); | ||
168 | + | ||
169 | + it('GET /users - should return 200 if user index loads (JSON)', function(done) { | ||
170 | + request | ||
171 | + .get('/users') | ||
172 | + .accept('application/json') | ||
173 | + .expect(200, done); | ||
174 | + }); | ||
175 | + | ||
176 | + it('GET /users - should return 200 if user index loads and shows 3 rows (HTML)', function(done) { | ||
177 | + request | ||
178 | + .get('/users') | ||
179 | + .accept('text/html') | ||
180 | + .expect(200) | ||
181 | + .end(function(err, res) { | ||
182 | + // Test the attributes exist | ||
183 | + expect(res.text).to.exist; | ||
184 | + | ||
185 | + var $ = cheerio.load(res.text); | ||
186 | + var $userList = $('table'); | ||
187 | + var $userRows = $userList.find('tr'); | ||
188 | + | ||
189 | + // Test the values make sense | ||
190 | + $userList.should.have.length.of(1); | ||
191 | + $userRows.should.have.length.of.at.least(3); | ||
192 | + | ||
193 | + done(); | ||
194 | + }); | ||
195 | + }); | ||
196 | + | ||
197 | +}); |
请
注册
或
登录
后发表评论