1
|
|
-const passport = require("passport");
|
2
|
|
-const urlencode = require("urlencode");
|
3
|
|
-const async = require("async");
|
4
|
|
-const crypto = require("crypto");
|
5
|
|
-const fs =require('fs')
|
6
|
|
-const path = require("path");
|
7
|
|
-
|
8
|
|
-exports = module.exports = function (logger, rest, settings) {
|
9
|
|
- function index(req, res, next) {
|
10
|
|
- logger.info(req);
|
11
|
|
- // res.redirect("https://www.baidu.com");
|
12
|
|
- }
|
13
|
|
-
|
14
|
|
- function getImg(req, res, next) {
|
15
|
|
- logger.info(req.url, "1231231231");
|
16
|
|
- const parentdir = path.resolve(__dirname, "..")
|
17
|
|
- const paths = parentdir+'/build/public'+urlencode.decode(req.url, 'utf8')
|
18
|
|
- fs.readFile(paths,function(err,data){
|
19
|
|
- console.log(err,data)
|
20
|
|
- if (err) {
|
21
|
|
- res.send('读取错误')
|
22
|
|
- } else {
|
23
|
|
- res.send(data)
|
24
|
|
- }
|
25
|
|
- })
|
26
|
|
- }
|
27
|
|
-
|
28
|
|
- function indexPrefix(req, res) {
|
29
|
|
- // logger.info(req.csrfToken(),'req.cssadasdas');
|
30
|
|
- res.send({data:req.csrfToken()})
|
31
|
|
- // if (req.csrfToken) {
|
32
|
|
- // if (settings.prefix && settings.prefix.length > 1) {
|
33
|
|
- // res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
|
34
|
|
- // } else {
|
35
|
|
- // res.render("index", { csrfToken: req.csrfToken() });
|
36
|
|
- // }
|
37
|
|
- // } else res.render("index", { csrfToken: "" });
|
38
|
|
- }
|
39
|
|
-
|
40
|
|
- function productDes(req, res, next) {
|
41
|
|
- if (req.csrfToken)
|
42
|
|
- res.render("chat/new-chat", { csrfToken: req.csrfToken() });
|
43
|
|
- else res.render("chat/new-chat", { csrfToken: "" });
|
44
|
|
- }
|
45
|
|
-
|
46
|
|
- function recharge(req, res) {
|
47
|
|
- var params = JSON.parse(urlencode.decode(req.query.params));
|
48
|
|
- console.log(params);
|
49
|
|
- if (req.csrfToken)
|
50
|
|
- res.render("recharge", { recharge: params, csrfToken: req.csrfToken() });
|
51
|
|
- else res.render("recharge", { recharge: params, csrfToken: "" });
|
52
|
|
- }
|
53
|
|
-
|
54
|
|
- function register(req, res, next) {
|
55
|
|
- if (req.csrfToken)
|
56
|
|
- res.render("newRegister", { csrfToken: req.csrfToken() });
|
57
|
|
- else res.render("newRegister", { csrfToken: "" });
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- function mobileRegister(req, res) {
|
61
|
|
- if (req.csrfToken)
|
62
|
|
- res.render("registerMobile", { csrfToken: req.csrfToken() });
|
63
|
|
- else res.render("registerMobile", { csrfToken: "" });
|
64
|
|
- }
|
65
|
|
-
|
66
|
|
- function mobileRegisterSuccess(req, res) {
|
67
|
|
- if (req.csrfToken)
|
68
|
|
- res.render("registerMobileSuccess", { csrfToken: req.csrfToken() });
|
69
|
|
- else res.render("registerMobileSuccess", { csrfToken: "" });
|
70
|
|
- }
|
71
|
|
-
|
72
|
|
- function signIn(req, res, next) {
|
73
|
|
- // console.log(req);
|
74
|
|
- if (req.csrfToken) res.render("newLogin", { csrfToken: req.csrfToken() });
|
75
|
|
- else res.render("newLogin", { csrfToken: "" });
|
76
|
|
- }
|
77
|
|
-
|
78
|
|
- function doLogin(req, res, next) {
|
79
|
|
- passport.authenticate("local", function (err, user, info) {
|
80
|
|
- console.log("doLogin:", err, user, info);
|
81
|
|
- if (err) {
|
82
|
|
- return next(err);
|
83
|
|
- }
|
84
|
|
- if (!user) {
|
85
|
|
- return res.send(info);
|
86
|
|
- }
|
87
|
|
- req.logIn(user, function (err) {
|
88
|
|
- if (err) {
|
89
|
|
- return next(err);
|
90
|
|
- }
|
91
|
|
- return res.send({
|
92
|
|
- ok: "登录成功",
|
93
|
|
- user_info: req.session.passport.user.user_info,
|
94
|
|
- });
|
95
|
|
- });
|
96
|
|
- })(req, res, next);
|
97
|
|
- }
|
98
|
|
-
|
99
|
|
- function signOut(req, res, next) {
|
100
|
|
- if (
|
101
|
|
- req.session.passport &&
|
102
|
|
- req.session.passport.user &&
|
103
|
|
- req.session.passport.user.user_info &&
|
104
|
|
- req.session.passport.user.user_info.user
|
105
|
|
- )
|
106
|
|
- logger.info(
|
107
|
|
- req.session.passport.user.user_info.user,
|
108
|
|
- "You have successfully logged out"
|
109
|
|
- );
|
110
|
|
- req.logout();
|
111
|
|
- req.flash("success", "You have successfully logged out");
|
112
|
|
- res.redirect("/");
|
113
|
|
- }
|
114
|
|
-
|
115
|
|
- function smsCodes(req, res, next) {
|
116
|
|
- rest.postJson({
|
117
|
|
- baseUrl: "url",
|
118
|
|
- url: "auth/smscodes",
|
119
|
|
- params: req.body,
|
120
|
|
- callback: _cb,
|
121
|
|
- req: req,
|
122
|
|
- res: res,
|
123
|
|
- options: {},
|
124
|
|
- excludeToken: true,
|
125
|
|
- });
|
126
|
|
- function _cb(data, response) {
|
127
|
|
- logger.info("back data:", data);
|
128
|
|
- if (response.statusCode < 300) {
|
129
|
|
- res.send({ code: 200, message: "发送成功" });
|
130
|
|
- } else {
|
131
|
|
- res.send(data);
|
132
|
|
- }
|
133
|
|
- }
|
134
|
|
- }
|
135
|
|
-
|
136
|
|
- function tenants(req, res, next) {
|
137
|
|
- rest.register({
|
138
|
|
- baseUrl: "url",
|
139
|
|
- url: "tenants",
|
140
|
|
- params: req.body,
|
141
|
|
- callback: _cb,
|
142
|
|
- req: req,
|
143
|
|
- res: res,
|
144
|
|
- options: {},
|
145
|
|
- excludeToken: true,
|
146
|
|
- });
|
147
|
|
- function _cb(data, response) {
|
148
|
|
- logger.info("back data:", data);
|
149
|
|
- res.send(data);
|
150
|
|
- }
|
151
|
|
- }
|
152
|
|
-
|
153
|
|
- function resetPass(req, res) {
|
154
|
|
- rest.putJson({
|
155
|
|
- baseUrl: "url",
|
156
|
|
- url: "auth/user",
|
157
|
|
- params: {
|
158
|
|
- user: req.body.user,
|
159
|
|
- password: req.body.password,
|
160
|
|
- again_password: req.body.again_password,
|
161
|
|
- },
|
162
|
|
- callback: _cb,
|
163
|
|
- req: req,
|
164
|
|
- res: res,
|
165
|
|
- options: {},
|
166
|
|
- });
|
167
|
|
- function _cb(data, response) {
|
168
|
|
- logger.info("back data:", data);
|
169
|
|
- res.send(data);
|
170
|
|
- }
|
171
|
|
- }
|
172
|
|
-
|
173
|
|
- function updatePassword(req, res) {
|
174
|
|
- rest.patchJson({
|
175
|
|
- baseUrl: "url",
|
176
|
|
- url: "users/" + req.body.userId,
|
177
|
|
- params: {
|
178
|
|
- password: req.body.password,
|
179
|
|
- },
|
180
|
|
- callback: _cb,
|
181
|
|
- req: req,
|
182
|
|
- res: res,
|
183
|
|
- options: {},
|
184
|
|
- });
|
185
|
|
- function _cb(data, response) {
|
186
|
|
- logger.info("back data:", data);
|
187
|
|
- res.send(data);
|
188
|
|
- }
|
189
|
|
- }
|
190
|
|
-
|
191
|
|
- function loadUserInfo(req, res) {
|
192
|
|
- settings;
|
193
|
|
- if (req.session.passport.user && req.session.passport.user.user_info) {
|
194
|
|
- res.send({
|
195
|
|
- user_info: req.session.passport.user.user_info,
|
196
|
|
- prefix: settings.prefix,
|
197
|
|
- });
|
198
|
|
- } else {
|
199
|
|
- res.send({ user_info: null, prefix: settings.prefix });
|
200
|
|
- }
|
201
|
|
- }
|
202
|
|
-
|
203
|
|
- function getUploaderToken(req, res) {
|
204
|
|
- rest.postJson({
|
205
|
|
- baseUrl: "ossUrl",
|
206
|
|
- url: "inits",
|
207
|
|
- params: req.body,
|
208
|
|
- callback: _cb,
|
209
|
|
- req: req,
|
210
|
|
- res: res,
|
211
|
|
- options: {},
|
212
|
|
- });
|
213
|
|
- function _cb(data, response) {
|
214
|
|
- logger.info("back data:", data);
|
215
|
|
- res.send(data);
|
216
|
|
- }
|
217
|
|
- }
|
218
|
|
-
|
219
|
|
- function getObjectTokenByID(req, res) {
|
220
|
|
- rest.get({
|
221
|
|
- baseUrl: "ossUrl",
|
222
|
|
- url: "objects/" + req.body.file_id,
|
223
|
|
- params: {},
|
224
|
|
- callback: _cb,
|
225
|
|
- req: req,
|
226
|
|
- res: res,
|
227
|
|
- options: {},
|
228
|
|
- });
|
229
|
|
- function _cb(data, response) {
|
230
|
|
- logger.info("back data:", data);
|
231
|
|
- res.send(data);
|
232
|
|
- }
|
233
|
|
- }
|
234
|
|
-
|
235
|
|
- function delOSSObject(req, res) {
|
236
|
|
- rest.del({
|
237
|
|
- baseUrl: "ossUrl",
|
238
|
|
- url:
|
239
|
|
- "s3objects/" +
|
240
|
|
- req.body.request_id +
|
241
|
|
- "?bucket=" +
|
242
|
|
- req.body.bucket +
|
243
|
|
- "&file=" +
|
244
|
|
- req.body.name,
|
245
|
|
- params: {},
|
246
|
|
- callback: _cb,
|
247
|
|
- req: req,
|
248
|
|
- res: res,
|
249
|
|
- options: {},
|
250
|
|
- });
|
251
|
|
- function _cb(data, response) {
|
252
|
|
- logger.info("back data:", data);
|
253
|
|
- console.log(response.statusCode);
|
254
|
|
- if (response.statusCode < 300) {
|
255
|
|
- res.send({ delete: "ok" });
|
256
|
|
- }
|
257
|
|
- }
|
258
|
|
- }
|
259
|
|
-
|
260
|
|
- function smsVerification(req, res) {
|
261
|
|
- rest.postJson({
|
262
|
|
- baseUrl: "url",
|
263
|
|
- url: "auth/sms_verification",
|
264
|
|
- params: req.body,
|
265
|
|
- callback: _cb,
|
266
|
|
- req: req,
|
267
|
|
- res: res,
|
268
|
|
- options: {},
|
269
|
|
- excludeToken: true,
|
270
|
|
- });
|
271
|
|
- function _cb(data, response) {
|
272
|
|
- logger.info("back data:", data);
|
273
|
|
- if (response.statusCode < 300) {
|
274
|
|
- res.send({ code: 200, message: "发送成功" });
|
275
|
|
- } else {
|
276
|
|
- res.send({
|
277
|
|
- code: response.statusCode,
|
278
|
|
- message: data.message,
|
279
|
|
- errors: data.errors,
|
280
|
|
- });
|
281
|
|
- }
|
282
|
|
- }
|
283
|
|
- }
|
284
|
|
-
|
285
|
|
- function healthMonitor(res) {
|
286
|
|
- res.statusCode = 200;
|
287
|
|
- return res.send("status ok");
|
288
|
|
- }
|
289
|
|
-
|
290
|
|
- function updateUserRoles(req, res) {
|
291
|
|
- rest.putJson({
|
292
|
|
- baseUrl: "url",
|
293
|
|
- url: "user_roles/" + req.body.user_id,
|
294
|
|
- params: req.body.roles,
|
295
|
|
- callback: _cb,
|
296
|
|
- req: req,
|
297
|
|
- res: res,
|
298
|
|
- options: {},
|
299
|
|
- });
|
300
|
|
- function _cb(data, response) {
|
301
|
|
- logger.info("back data:", data);
|
302
|
|
- if (response.statusCode < 300) {
|
303
|
|
- res.send({ back: "ok" });
|
304
|
|
- } else {
|
305
|
|
- res.send(data);
|
306
|
|
- }
|
307
|
|
- }
|
308
|
|
- }
|
309
|
|
-
|
310
|
|
- function getRoles(req, res) {
|
311
|
|
- rest.get({
|
312
|
|
- baseUrl: "url",
|
313
|
|
- url: "roles",
|
314
|
|
- params: {},
|
315
|
|
- callback: _cb,
|
316
|
|
- req: req,
|
317
|
|
- res: res,
|
318
|
|
- options: {},
|
319
|
|
- });
|
320
|
|
- function _cb(data, response) {
|
321
|
|
- logger.info("back data:", data);
|
322
|
|
- res.send(data);
|
323
|
|
- }
|
324
|
|
- }
|
325
|
|
-
|
326
|
|
- function getUserRoles(req, res) {
|
327
|
|
- rest.get({
|
328
|
|
- baseUrl: "url",
|
329
|
|
- url:
|
330
|
|
- "user_roles?user=" +
|
331
|
|
- urlencode(req.body.user) +
|
332
|
|
- "&limit=" +
|
333
|
|
- req.body.limit +
|
334
|
|
- "&offset=" +
|
335
|
|
- req.body.offset,
|
336
|
|
- params: {},
|
337
|
|
- callback: _cb,
|
338
|
|
- req: req,
|
339
|
|
- res: res,
|
340
|
|
- options: {},
|
341
|
|
- });
|
342
|
|
- function _cb(data, response) {
|
343
|
|
- logger.info("back data:", data);
|
344
|
|
- res.send(data);
|
345
|
|
- }
|
346
|
|
- }
|
347
|
|
-
|
348
|
|
- function getTenant(req, res) {
|
349
|
|
- rest.get({
|
350
|
|
- baseUrl: "url",
|
351
|
|
- url: "tenants/" + req.body.tenant_id,
|
352
|
|
- params: {},
|
353
|
|
- callback: _cb,
|
354
|
|
- req: req,
|
355
|
|
- res: res,
|
356
|
|
- options: {},
|
357
|
|
- });
|
358
|
|
- function _cb(data, response) {
|
359
|
|
- logger.info("back data:", data);
|
360
|
|
- res.send(data);
|
361
|
|
- }
|
362
|
|
- }
|
363
|
|
-
|
364
|
|
- function updateTenant(req, res) {
|
365
|
|
- rest.putJson({
|
366
|
|
- baseUrl: "url",
|
367
|
|
- url: "tenants/" + req.body.tenant_id,
|
368
|
|
- params: req.body.tenant,
|
369
|
|
- callback: _cb,
|
370
|
|
- req: req,
|
371
|
|
- res: res,
|
372
|
|
- options: {},
|
373
|
|
- });
|
374
|
|
- function _cb(data, response) {
|
375
|
|
- logger.info("back data:", data);
|
376
|
|
- res.send(data);
|
377
|
|
- }
|
378
|
|
- }
|
379
|
|
-
|
380
|
|
- function offer(req, res) {
|
381
|
|
- rest.get({
|
382
|
|
- baseUrl: "hrUrl",
|
383
|
|
- url:
|
384
|
|
- "offers/" + req.params.requestId + "?tenant_id=" + req.query.tenant_id,
|
385
|
|
- params: {},
|
386
|
|
- callback: _cb,
|
387
|
|
- req: req,
|
388
|
|
- res: res,
|
389
|
|
- options: {},
|
390
|
|
- excludeToken: true,
|
391
|
|
- });
|
392
|
|
- function _cb(data, response) {
|
393
|
|
- logger.info("back data:", data);
|
394
|
|
- //res.send(data);
|
395
|
|
- console.log(data);
|
396
|
|
- data["offerId"] = req.params.requestId;
|
397
|
|
- data["tenantId"] = req.query.tenant_id;
|
398
|
|
- res.render("offer", data);
|
399
|
|
- }
|
400
|
|
- }
|
401
|
|
-
|
402
|
|
- function onboardStatus(req, res) {
|
403
|
|
- rest.get({
|
404
|
|
- baseUrl: "hrUrl",
|
405
|
|
- url: "onboard-status",
|
406
|
|
- params: {},
|
407
|
|
- callback: _cb,
|
408
|
|
- req: req,
|
409
|
|
- res: res,
|
410
|
|
- options: {},
|
411
|
|
- useUrl: true,
|
412
|
|
- });
|
413
|
|
- function _cb(data, response) {
|
414
|
|
- logger.info("back data:", data);
|
415
|
|
- res.send(data);
|
416
|
|
- }
|
417
|
|
- }
|
418
|
|
-
|
419
|
|
- function dowloadApp(req, res) {
|
420
|
|
- var mobileAgent = req.headers["user-agent"].toLowerCase();
|
421
|
|
- var agent = {
|
422
|
|
- android:
|
423
|
|
- mobileAgent.indexOf("android") > -1 || mobileAgent.indexOf("Adr") > -1,
|
424
|
|
- iPhone: mobileAgent.indexOf("iphone") > -1,
|
425
|
|
- iPad: mobileAgent.indexOf("ipad") > -1,
|
426
|
|
- };
|
427
|
|
- if (agent.iPhone || agent.iPad) {
|
428
|
|
- res.redirect(
|
429
|
|
- 301,
|
430
|
|
- "https://itunes.apple.com/cn/app/%E8%96%AA%E5%91%97/id1140779439?l=en&mt=8"
|
431
|
|
- );
|
432
|
|
- } else if (agent.android) {
|
433
|
|
- res.redirect(
|
434
|
|
- 301,
|
435
|
|
- "http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk"
|
436
|
|
- );
|
437
|
|
- } else {
|
438
|
|
- res.redirect(
|
439
|
|
- 301,
|
440
|
|
- "http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk"
|
441
|
|
- );
|
442
|
|
- }
|
443
|
|
- }
|
444
|
|
-
|
445
|
|
- function softwareLicense(res) {
|
446
|
|
- res.render("softwareLicense");
|
447
|
|
- }
|
448
|
|
-
|
449
|
|
- function changePassForRegister(req, res) {
|
450
|
|
- var options = {
|
451
|
|
- baseUrl: "url",
|
452
|
|
- url: "users/" + req.body.user_id,
|
453
|
|
- params: {
|
454
|
|
- password: req.body.password,
|
455
|
|
- },
|
456
|
|
- callback: _cb,
|
457
|
|
- req: req,
|
458
|
|
- res: res,
|
459
|
|
- options: {},
|
460
|
|
- };
|
461
|
|
- if (req.body.access_token) {
|
462
|
|
- console.log("@@@!!!!!!!!!!!!!!!!");
|
463
|
|
- options.options = {
|
464
|
|
- accessToken: req.body.access_token,
|
465
|
|
- };
|
466
|
|
- options["excludeToken"] = true;
|
467
|
|
- }
|
468
|
|
- rest.patchJson(options);
|
469
|
|
- function _cb(data, response) {
|
470
|
|
- logger.info("back data:", data);
|
471
|
|
- res.send(data);
|
472
|
|
- }
|
473
|
|
- }
|
474
|
|
-
|
475
|
|
- function changeTenant(req, res) {
|
476
|
|
- var params = {
|
477
|
|
- grant_type: "refresh_token",
|
478
|
|
- scope: "global_access:tenant_admin,tenant:" + req.body.id,
|
479
|
|
- refresh_token: req.session.passport.user.refreshToken,
|
480
|
|
- };
|
481
|
|
- req.session.passport.user.token = "";
|
482
|
|
- rest.postJson({
|
483
|
|
- baseUrl: "url",
|
484
|
|
- url:
|
485
|
|
- settings.restful.url +
|
486
|
|
- "uaa" +
|
487
|
|
- settings.restful.version +
|
488
|
|
- "/auth/tokens",
|
489
|
|
- useUrl: true,
|
490
|
|
- params: params,
|
491
|
|
- callback: _cb,
|
492
|
|
- req: req,
|
493
|
|
- res: res,
|
494
|
|
- options: {},
|
495
|
|
- excludeToken: true,
|
496
|
|
- });
|
497
|
|
- function _cb(data, response) {
|
498
|
|
- console.log(data);
|
499
|
|
- logger.info("back data:", data);
|
500
|
|
- if (response.statusCode < 300) {
|
501
|
|
- req.session.passport.user.token = data.access_token;
|
502
|
|
- req.session.passport.user.refreshToken = data.refresh_token;
|
503
|
|
- req.session.passport.user.user_info = {
|
504
|
|
- user: data.user,
|
505
|
|
- perms: [],
|
506
|
|
- tenant: data.tenant,
|
507
|
|
- scope: data.scope,
|
508
|
|
- oss: req.session.passport.user.user_info.oss,
|
509
|
|
- };
|
510
|
|
- req.session.save(function () {
|
511
|
|
- rest.get({
|
512
|
|
- baseUrl: "url",
|
513
|
|
- url:
|
514
|
|
- settings.restful.url +
|
515
|
|
- "uaa" +
|
516
|
|
- settings.restful.version +
|
517
|
|
- "/perms/detail",
|
518
|
|
- useUrl: true,
|
519
|
|
- params: {},
|
520
|
|
- callback: _scb,
|
521
|
|
- req: req,
|
522
|
|
- res: res,
|
523
|
|
- options: {},
|
524
|
|
- });
|
525
|
|
- });
|
526
|
|
- } else {
|
527
|
|
- res.send({
|
528
|
|
- code: response.statusCode,
|
529
|
|
- message: data.message,
|
530
|
|
- initialize_done: "n",
|
531
|
|
- });
|
532
|
|
- }
|
533
|
|
- }
|
534
|
|
- function _scb(data1, response) {
|
535
|
|
- if (response.statusCode < 300 && data1.items) {
|
536
|
|
- req.session.passport.user.user_info.perms = data1.items;
|
537
|
|
- req.session.save(function () {
|
538
|
|
- // res.send({"code":200,"message":"切换租户成功"});
|
539
|
|
- rest.get({
|
540
|
|
- baseUrl: "url",
|
541
|
|
- url:
|
542
|
|
- settings.restful.url +
|
543
|
|
- "filemeta" +
|
544
|
|
- settings.restful.version +
|
545
|
|
- "/config",
|
546
|
|
- useUrl: true,
|
547
|
|
- params: {},
|
548
|
|
- callback: _scb1,
|
549
|
|
- req: req,
|
550
|
|
- res: res,
|
551
|
|
- options: {},
|
552
|
|
- });
|
553
|
|
- });
|
554
|
|
- } else {
|
555
|
|
- res.send({ code: response.statusCode, message: data1.message });
|
556
|
|
- }
|
557
|
|
- }
|
558
|
|
- function _scb1(data2, response) {
|
559
|
|
- if (response.statusCode < 300 && data2 && data2.bucket) {
|
560
|
|
- req.session.passport.user.user_info.oss = data2;
|
561
|
|
- req.session.save(function () {
|
562
|
|
- res.send({ code: 200, message: "切换租户成功" });
|
563
|
|
- });
|
564
|
|
- } else {
|
565
|
|
- res.send({ code: 200, message: "切换租户失败" });
|
566
|
|
- }
|
567
|
|
- }
|
568
|
|
- }
|
569
|
|
-
|
570
|
|
- function sendRejectOffer(req, res) {
|
571
|
|
- rest.get({
|
572
|
|
- baseUrl: "hrUrl",
|
573
|
|
- url: req.body.url, //传一个参数
|
574
|
|
- params: {},
|
575
|
|
- callback: _cb,
|
576
|
|
- req: req,
|
577
|
|
- res: res,
|
578
|
|
- options: {},
|
579
|
|
- excludeToken: true,
|
580
|
|
- useUrl: true,
|
581
|
|
- });
|
582
|
|
- function _cb(data, response) {
|
583
|
|
- logger.info("back data:", data);
|
584
|
|
- if (response.statusCode < 300) {
|
585
|
|
- res.send({ action: "ok" });
|
586
|
|
- } else {
|
587
|
|
- res.send(data);
|
588
|
|
- }
|
589
|
|
- }
|
590
|
|
- }
|
591
|
|
-
|
592
|
|
- function acceptOffer(req, res) {
|
593
|
|
- rest.get({
|
594
|
|
- baseUrl: "hrUrl",
|
595
|
|
- url: req.body.url, //传一个参数
|
596
|
|
- params: {},
|
597
|
|
- callback: _cb,
|
598
|
|
- req: req,
|
599
|
|
- res: res,
|
600
|
|
- options: {},
|
601
|
|
- excludeToken: true,
|
602
|
|
- useUrl: true,
|
603
|
|
- });
|
604
|
|
- function _cb(data, response) {
|
605
|
|
- logger.info("back data:", data);
|
606
|
|
- if (response.statusCode < 300) {
|
607
|
|
- res.send({ action: "ok" });
|
608
|
|
- } else {
|
609
|
|
- res.send(data);
|
610
|
|
- }
|
611
|
|
- }
|
612
|
|
- }
|
613
|
|
-
|
614
|
|
- function imTokens(req, res) {
|
615
|
|
- rest.post({
|
616
|
|
- url: "auth/im_tokens",
|
617
|
|
- params: req.body,
|
618
|
|
- callback: _cb,
|
619
|
|
- req: req,
|
620
|
|
- res: res,
|
621
|
|
- options: {},
|
622
|
|
- });
|
623
|
|
- function _cb(data, response) {
|
624
|
|
- logger.info("back data:", data);
|
625
|
|
- res.send(data);
|
626
|
|
- }
|
627
|
|
- }
|
628
|
|
-
|
629
|
|
- function listChannels(req, res) {
|
630
|
|
- rest.get({
|
631
|
|
- baseUrl: "chatUrl",
|
632
|
|
- url: "channels?page_size=10&page=0&status=active",
|
633
|
|
- params: req.body,
|
634
|
|
- callback: _cb,
|
635
|
|
- req: req,
|
636
|
|
- res: res,
|
637
|
|
- options: {},
|
638
|
|
- });
|
639
|
|
- function _cb(data, response) {
|
640
|
|
- logger.info("back data:", data);
|
641
|
|
- res.send(data);
|
642
|
|
- }
|
643
|
|
- }
|
644
|
|
-
|
645
|
|
- function filemeta(req, res) {
|
646
|
|
- var fullPath =
|
647
|
|
- settings.restful.url +
|
648
|
|
- "filemeta" +
|
649
|
|
- settings.restful.version +
|
650
|
|
- "/object-redirect";
|
651
|
|
- fullPath =
|
652
|
|
- fullPath +
|
653
|
|
- "?" +
|
654
|
|
- "bucket=" +
|
655
|
|
- req.query.bucket +
|
656
|
|
- "&object=" +
|
657
|
|
- encodeURIComponent(req.query.object);
|
658
|
|
- console.info("fullPath::::::", fullPath);
|
659
|
|
- var options = {
|
660
|
|
- service_catalog: "",
|
661
|
|
- url: fullPath,
|
662
|
|
- useUrl: true,
|
663
|
|
- params: req.body,
|
664
|
|
- callback: _cb,
|
665
|
|
- req: req,
|
666
|
|
- res: res,
|
667
|
|
- options: {},
|
668
|
|
- };
|
669
|
|
- rest.get(options);
|
670
|
|
- function _cb(data, response) {
|
671
|
|
- if (data && data.download_url) {
|
672
|
|
- if (req.query.type && "json" == req.query.type) {
|
673
|
|
- res.send(data);
|
674
|
|
- } else {
|
675
|
|
- var url = data.download_url;
|
676
|
|
- let path = url.split("?")[0];
|
677
|
|
- let pathArray = path.split("/");
|
678
|
|
- let result = [];
|
679
|
|
- for (var i = 0; i < pathArray.length; i++) {
|
680
|
|
- if (i == pathArray.length - 1) {
|
681
|
|
- result.push(encodeURIComponent(pathArray[i]));
|
682
|
|
- } else {
|
683
|
|
- result.push(pathArray[i]);
|
684
|
|
- }
|
685
|
|
- }
|
686
|
|
- let result1 = result.join("/");
|
687
|
|
- if (url.indexOf("?") !== -1) {
|
688
|
|
- result1 += "?" + url.split("?")[1];
|
689
|
|
- }
|
690
|
|
- if (req.query.result_callback) {
|
691
|
|
- res.send(data);
|
692
|
|
- } else {
|
693
|
|
- res.redirect(301, result1);
|
694
|
|
- }
|
695
|
|
- }
|
696
|
|
- } else {
|
697
|
|
- res.send(data);
|
698
|
|
- }
|
699
|
|
- }
|
700
|
|
- }
|
701
|
|
-
|
702
|
|
- function getCustomerQrcode(req, res) {
|
703
|
|
- var fullPath =
|
704
|
|
- settings.restful.url +
|
705
|
|
- "crm" +
|
706
|
|
- settings.restful.version +
|
707
|
|
- "/customers/" +
|
708
|
|
- req.query.id +
|
709
|
|
- "/qrcode";
|
710
|
|
- var options = {
|
711
|
|
- service_catalog: "",
|
712
|
|
- url: fullPath,
|
713
|
|
- useUrl: true,
|
714
|
|
- params: req.body,
|
715
|
|
- callback: _cb,
|
716
|
|
- req: req,
|
717
|
|
- res: res,
|
718
|
|
- options: {},
|
719
|
|
- };
|
720
|
|
- rest.get(options);
|
721
|
|
- function _cb(data, response) {
|
722
|
|
- if (data && data.url_path) {
|
723
|
|
- res.redirect(301, data.url_path);
|
724
|
|
- } else {
|
725
|
|
- res.send(data);
|
726
|
|
- }
|
727
|
|
- }
|
728
|
|
- }
|
729
|
|
-
|
730
|
|
- function getPositionQrcode(req, res) {
|
731
|
|
- var fullPath =
|
732
|
|
- settings.restful.url +
|
733
|
|
- "recruit" +
|
734
|
|
- settings.restful.version +
|
735
|
|
- "/positions/" +
|
736
|
|
- req.query.id +
|
737
|
|
- "/qrcode";
|
738
|
|
- var options = {
|
739
|
|
- service_catalog: "",
|
740
|
|
- url: fullPath,
|
741
|
|
- useUrl: true,
|
742
|
|
- params: req.body,
|
743
|
|
- callback: _cb,
|
744
|
|
- req: req,
|
745
|
|
- res: res,
|
746
|
|
- options: {},
|
747
|
|
- };
|
748
|
|
- rest.get(options);
|
749
|
|
- function _cb(data, response) {
|
750
|
|
- if (data && data.url_path) {
|
751
|
|
- res.redirect(301, data.url_path);
|
752
|
|
- } else {
|
753
|
|
- res.send(data);
|
754
|
|
- }
|
755
|
|
- }
|
756
|
|
- }
|
757
|
|
-
|
758
|
|
- function getOSSConfig(req, res) {
|
759
|
|
- var fullPath =
|
760
|
|
- settings.restful.url + "filemeta" + settings.restful.version + "/config";
|
761
|
|
- var options = {
|
762
|
|
- service_catalog: "",
|
763
|
|
- url: fullPath,
|
764
|
|
- useUrl: true,
|
765
|
|
- params: req.body,
|
766
|
|
- callback: _cb,
|
767
|
|
- req: req,
|
768
|
|
- res: res,
|
769
|
|
- options: {},
|
770
|
|
- };
|
771
|
|
- rest.get(options);
|
772
|
|
- function _cb(data, response) {
|
773
|
|
- if (data && data.bucket) {
|
774
|
|
- req.session.passport.user.user_info.oss = data;
|
775
|
|
- req.session.save(function () {
|
776
|
|
- res.send({ code: 200, message: "oss配置加载成功" });
|
777
|
|
- });
|
778
|
|
- } else {
|
779
|
|
- res.send({ code: 200, message: "oss配置加载失败" });
|
780
|
|
- }
|
781
|
|
- }
|
782
|
|
- }
|
783
|
|
-
|
784
|
|
- function weidianTempLate(req, res) {
|
785
|
|
- const { params } = req;
|
786
|
|
- var fullPath =
|
787
|
|
- settings.restful.url + "socialwork/internal/minishop/" + params.id;
|
788
|
|
- var options = {
|
789
|
|
- service_catalog: "",
|
790
|
|
- url: fullPath,
|
791
|
|
- useUrl: true,
|
792
|
|
- params: req.body,
|
793
|
|
- callback: _cb,
|
794
|
|
- req: req,
|
795
|
|
- res: res,
|
796
|
|
- options: {},
|
797
|
|
- excludeToken: true,
|
798
|
|
- };
|
799
|
|
- rest.get(options);
|
800
|
|
- function _cb(data, response) {
|
801
|
|
- logger.info("back data:", data);
|
802
|
|
- if (response.statusCode < 300) {
|
803
|
|
- const { shop_logo = [], shop_name = "", shop_comment = "" } = data;
|
804
|
|
- let imgUrl = "";
|
805
|
|
- if (shop_logo.length > 0) {
|
806
|
|
- imgUrl = "http://oss.workai.com.cn/public/" + shop_logo[0].object;
|
807
|
|
- }
|
808
|
|
- res.render("template/weiDian", {
|
809
|
|
- imgUrl: imgUrl,
|
810
|
|
- shop_name: shop_name,
|
811
|
|
- shop_comment: shop_comment,
|
812
|
|
- });
|
813
|
|
- } else {
|
814
|
|
- res.render("template/weiDian");
|
815
|
|
- }
|
816
|
|
- }
|
817
|
|
- }
|
818
|
|
-
|
819
|
|
- function workaiSecurityOAuth(req, res) {
|
820
|
|
- var params = req.query;
|
821
|
|
- if (params.authorization_code) {
|
822
|
|
- var passport = {
|
823
|
|
- user: {
|
824
|
|
- refreshToken: "",
|
825
|
|
- token: "",
|
826
|
|
- service_catalog: {},
|
827
|
|
- user_info: {},
|
828
|
|
- err: null,
|
829
|
|
- },
|
830
|
|
- };
|
831
|
|
- async.waterfall(
|
832
|
|
- [
|
833
|
|
- function (callback) {
|
834
|
|
- //第三方登录
|
835
|
|
- var tempParams = {
|
836
|
|
- grant_type: "authorization_code_v1",
|
837
|
|
- code: params.authorization_code,
|
838
|
|
- };
|
839
|
|
- // var tempParams={
|
840
|
|
- // "grant_type":"password",
|
841
|
|
- // "username":"18510929499",
|
842
|
|
- // "scope":"global_access:tenant_admin",
|
843
|
|
- // "password":"a123456"
|
844
|
|
- // };
|
845
|
|
- logger.info(
|
846
|
|
- "Third login",
|
847
|
|
- settings.restful.url + "uaa/v1/auth/tokens",
|
848
|
|
- tempParams
|
849
|
|
- );
|
850
|
|
- rest.restful
|
851
|
|
- .postJson(
|
852
|
|
- settings.restful.url + "uaa/v1/auth/tokens",
|
853
|
|
- tempParams,
|
854
|
|
- {
|
855
|
|
- headers: {
|
856
|
|
- "Content-Type": "application/json",
|
857
|
|
- Accept: "application/json",
|
858
|
|
- },
|
859
|
|
- }
|
860
|
|
- )
|
861
|
|
- .on("success", function (data) {
|
862
|
|
- logger.info("Third login json data:", data);
|
863
|
|
- if (data.access_token) {
|
864
|
|
- var scopes = data.scope.split(",");
|
865
|
|
- passport.user.token = data.access_token;
|
866
|
|
- passport.user.refreshToken = data.refresh_token;
|
867
|
|
- passport.user.user_info = data.user || {};
|
868
|
|
- passport.user.tenant_info = data.tenant;
|
869
|
|
- passport.user.customer_info = data.customer;
|
870
|
|
- passport.user.user_info.perms = data.perms;
|
871
|
|
- passport.user.type = data.user.type;
|
872
|
|
- passport.user.real_auth_status = data.user.real_auth_status;
|
873
|
|
- passport.user.credential_status = data.user.credential_status;
|
874
|
|
- passport.user.user_info.scope = scopes[0];
|
875
|
|
- callback(null, data);
|
876
|
|
- } else {
|
877
|
|
- var err = new Error("Third login err");
|
878
|
|
- passport.user.err = data.message;
|
879
|
|
- callback(err, data);
|
880
|
|
- }
|
881
|
|
- })
|
882
|
|
- .on("error", function (err, response) {
|
883
|
|
- logger.error("Third login error", err);
|
884
|
|
- var err = new Error("Third login err");
|
885
|
|
- callback(err, response);
|
886
|
|
- })
|
887
|
|
- .on("fail", function (data, response) {
|
888
|
|
- logger.error("Third login fail", data);
|
889
|
|
- callback(data, response);
|
890
|
|
- });
|
891
|
|
- },
|
892
|
|
- function (data, callback) {
|
893
|
|
- //获取机构列表
|
894
|
|
- var tempHead = {};
|
895
|
|
- var ip = req.ip.match(/\d+\.\d+\.\d+\.\d+/)[0];
|
896
|
|
- var user_agent = req.headers["user-agent"] || "";
|
897
|
|
- tempHead["SXClientIP"] = ip;
|
898
|
|
- tempHead["User-Agent"] = user_agent;
|
899
|
|
- logger.info(
|
900
|
|
- "Third login tenants",
|
901
|
|
- settings.restful.url + "uaa/v1/tenants?all=true",
|
902
|
|
- { accessToken: data.access_token, headers: tempHead }
|
903
|
|
- );
|
904
|
|
- rest.restful
|
905
|
|
- .get(settings.restful.url + "uaa/v1/tenants?all=true", {
|
906
|
|
- accessToken: data.access_token,
|
907
|
|
- headers: tempHead,
|
908
|
|
- })
|
909
|
|
- .on("success", function (data1) {
|
910
|
|
- logger.info("Third login tenants list:", data1);
|
911
|
|
- if (data1 && data1.items && data1.items.length > 0) {
|
912
|
|
- callback(null, data1.items);
|
913
|
|
- } else {
|
914
|
|
- var err = new Error("Third login tenants list err");
|
915
|
|
- passport.user.err = data.message;
|
916
|
|
- callback(err, data);
|
917
|
|
- }
|
918
|
|
- })
|
919
|
|
- .on("error", function (err, response) {
|
920
|
|
- var err = new Error("Third login tenants list err");
|
921
|
|
- callback(err, response);
|
922
|
|
- })
|
923
|
|
- .on("fail", function (data, response) {
|
924
|
|
- callback(data, response);
|
925
|
|
- });
|
926
|
|
- },
|
927
|
|
- function (data, callback) {
|
928
|
|
- //刷新token
|
929
|
|
- if (data && data.length == 1) {
|
930
|
|
- var params = {
|
931
|
|
- grant_type: "refresh_token",
|
932
|
|
- scope: "global_access:tenant_admin,tenant:" + data[0].id,
|
933
|
|
- refresh_token: passport.user.refreshToken,
|
934
|
|
- };
|
935
|
|
- passport.user.token = "";
|
936
|
|
- logger.info(
|
937
|
|
- "Third login tokens",
|
938
|
|
- settings.restful.url + "uaa/v1/auth/tokens",
|
939
|
|
- params
|
940
|
|
- );
|
941
|
|
- rest.restful
|
942
|
|
- .postJson(settings.restful.url + "uaa/v1/auth/tokens", params, {
|
943
|
|
- headers: {
|
944
|
|
- "Content-Type": "application/json",
|
945
|
|
- Accept: "application/json",
|
946
|
|
- },
|
947
|
|
- })
|
948
|
|
- .on("success", function (data2) {
|
949
|
|
- logger.info("Third login json data2:", data2);
|
950
|
|
- if (data2.access_token) {
|
951
|
|
- var scopes = data2.scope.split(",");
|
952
|
|
- passport.user.token = data2.access_token;
|
953
|
|
- passport.user.refreshToken = data2.refresh_token;
|
954
|
|
- passport.user.user_info = data2.user || {};
|
955
|
|
- passport.user.tenant_info = data2.tenant;
|
956
|
|
- passport.user.customer_info = data2.customer;
|
957
|
|
- passport.user.user_info.perms = data2.perms;
|
958
|
|
- passport.user.type = data2.user.type;
|
959
|
|
- passport.user.real_auth_status =
|
960
|
|
- data2.user.real_auth_status;
|
961
|
|
- passport.user.credential_status =
|
962
|
|
- data2.user.credential_status;
|
963
|
|
- passport.user.user_info.scope = scopes[0];
|
964
|
|
- passport.user.user_info.tenant = data2.tenant;
|
965
|
|
- passport.user.user_info.user = {
|
966
|
|
- credential_status: data2.credential_status,
|
967
|
|
- id: data2.id,
|
968
|
|
- is_root: data2.is_root,
|
969
|
|
- mobile: data2.mobile,
|
970
|
|
- name: data2.name,
|
971
|
|
- real_auth_status: data2.real_auth_status,
|
972
|
|
- status: data2.status,
|
973
|
|
- type: data2.type,
|
974
|
|
- wx_open_id: data2.wx_open_id,
|
975
|
|
- };
|
976
|
|
- callback(null, data2);
|
977
|
|
- } else {
|
978
|
|
- var err = new Error("Third login err");
|
979
|
|
- passport.user.err = data2.message;
|
980
|
|
- callback(err, data2);
|
981
|
|
- }
|
982
|
|
- })
|
983
|
|
- .on("error", function (err, response) {
|
984
|
|
- logger.error("Third login error", err);
|
985
|
|
- var err = new Error("Third login err");
|
986
|
|
- callback(err, response);
|
987
|
|
- })
|
988
|
|
- .on("fail", function (data2, response) {
|
989
|
|
- logger.error("Third login fail", data2);
|
990
|
|
- callback(data2, response);
|
991
|
|
- });
|
992
|
|
- } else if (data && data.length > 1) {
|
993
|
|
- // #/login/choose-tenant
|
994
|
|
- callback(null, data);
|
995
|
|
- } else {
|
996
|
|
- var err = new Error("Third login tenants list item error");
|
997
|
|
- callback(err, data);
|
998
|
|
- }
|
999
|
|
- },
|
1000
|
|
- ],
|
1001
|
|
- function (err, result) {
|
1002
|
|
- if (err) {
|
1003
|
|
- //登陆失败跳转失败页
|
1004
|
|
- res.render("loginerr", { err: err });
|
1005
|
|
- } else if (result instanceof Array && result.length > 1) {
|
1006
|
|
- //登陆成功跳转选择机构页
|
1007
|
|
- req.session.passport = passport;
|
1008
|
|
- req.session.save(function () {
|
1009
|
|
- res.redirect(301, settings.prefix + "#login/choose-tenant");
|
1010
|
|
- });
|
1011
|
|
- } else {
|
1012
|
|
- req.session.passport = passport;
|
1013
|
|
- req.session.save(function () {
|
1014
|
|
- rest.get({
|
1015
|
|
- baseUrl: "url",
|
1016
|
|
- url:
|
1017
|
|
- settings.restful.url +
|
1018
|
|
- "uaa" +
|
1019
|
|
- settings.restful.version +
|
1020
|
|
- "/perms/detail",
|
1021
|
|
- useUrl: true,
|
1022
|
|
- params: {},
|
1023
|
|
- callback: _scb,
|
1024
|
|
- req: req,
|
1025
|
|
- res: res,
|
1026
|
|
- options: {},
|
1027
|
|
- });
|
1028
|
|
- });
|
1029
|
|
- function _scb(data1, response) {
|
1030
|
|
- if (response.statusCode < 300 && data1.items) {
|
1031
|
|
- req.session.passport.user.user_info.perms = data1.items;
|
1032
|
|
- req.session.save(function () {
|
1033
|
|
- if (params.redirect_page) {
|
1034
|
|
- res.redirect(
|
1035
|
|
- 301,
|
1036
|
|
- settings.prefix + "#" + params.redirect_page
|
1037
|
|
- ); //登陆成功跳转首页
|
1038
|
|
- } else {
|
1039
|
|
- res.redirect(301, settings.prefix + "#container/home"); //登陆成功跳转首页
|
1040
|
|
- }
|
1041
|
|
- });
|
1042
|
|
- } else {
|
1043
|
|
- if (params.redirect_page) {
|
1044
|
|
- res.redirect(
|
1045
|
|
- 301,
|
1046
|
|
- settings.prefix + "#" + params.redirect_page
|
1047
|
|
- ); //登陆成功跳转首页
|
1048
|
|
- } else {
|
1049
|
|
- res.redirect(301, settings.prefix + "#container/home"); //登陆成功跳转首页
|
1050
|
|
- }
|
1051
|
|
- }
|
1052
|
|
- }
|
1053
|
|
- }
|
1054
|
|
- }
|
1055
|
|
- );
|
1056
|
|
- }
|
1057
|
|
- }
|
1058
|
|
-
|
1059
|
|
- function getTastLink(req, res) {
|
1060
|
|
- var url = crypto.createHash("md5").update(req.body.id).digest("hex");
|
1061
|
|
- if (settings.prefix && settings.prefix.length > 1) {
|
1062
|
|
- res.send(
|
1063
|
|
- req.protocol +
|
1064
|
|
- "://" +
|
1065
|
|
- req.get("host") +
|
1066
|
|
- settings.prefix.substring(0, settings.prefix.length - 1) +
|
1067
|
|
- "/socialwork/freedom-jobs/emps/" +
|
1068
|
|
- req.body.id +
|
1069
|
|
- "/" +
|
1070
|
|
- url
|
1071
|
|
- );
|
1072
|
|
- } else {
|
1073
|
|
- res.send({
|
1074
|
|
- url:
|
1075
|
|
- req.protocol +
|
1076
|
|
- "://" +
|
1077
|
|
- req.get("host") +
|
1078
|
|
- "/socialwork/freedom-jobs/emps/" +
|
1079
|
|
- req.body.id +
|
1080
|
|
- "/" +
|
1081
|
|
- url,
|
1082
|
|
- });
|
1083
|
|
- }
|
1084
|
|
- }
|
1085
|
|
-
|
1086
|
|
- function freedomJobsEmp(req, res) {
|
1087
|
|
- var id = req.params.id;
|
1088
|
|
- // var url = crypto.createHash('md5').update(id).digest('hex');
|
1089
|
|
- if (false) {
|
1090
|
|
- //验证未通过verification != url
|
1091
|
|
- if (settings.prefix && settings.prefix.length > 1) {
|
1092
|
|
- res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
|
1093
|
|
- } else {
|
1094
|
|
- res.redirect("/");
|
1095
|
|
- }
|
1096
|
|
- } else {
|
1097
|
|
- //验证通过跳转,获取token存到session里
|
1098
|
|
- var passport = {
|
1099
|
|
- user: {
|
1100
|
|
- refreshToken: "",
|
1101
|
|
- token: "",
|
1102
|
|
- service_catalog: {},
|
1103
|
|
- user_info: {},
|
1104
|
|
- err: null,
|
1105
|
|
- },
|
1106
|
|
- };
|
1107
|
|
- var tempParams = {
|
1108
|
|
- grant_type: "client_credential",
|
1109
|
|
- client_id: "340161778618994688", //多宝鱼环境
|
1110
|
|
- client_secret: "0f8c30aa3d15332652f62c3eaf22fdea",
|
1111
|
|
- };
|
1112
|
|
- rest.restful
|
1113
|
|
- .postJson(settings.restful.url + "uaa/v1/auth/tokens", tempParams, {
|
1114
|
|
- headers: {
|
1115
|
|
- "Content-Type": "application/json",
|
1116
|
|
- Accept: "application/json",
|
1117
|
|
- },
|
1118
|
|
- })
|
1119
|
|
- .on("success", function (data) {
|
1120
|
|
- if (data.access_token) {
|
1121
|
|
- var scopes = data.scope.split(",");
|
1122
|
|
- passport.user.token = data.access_token;
|
1123
|
|
- passport.user.refreshToken = data.refresh_token;
|
1124
|
|
- passport.user.user_info = data.user;
|
1125
|
|
- passport.user.tenant_info = data.tenant;
|
1126
|
|
- passport.user.customer_info = data.customer;
|
1127
|
|
- passport.user.user_info.perms = data.perms;
|
1128
|
|
- passport.user.type = data.user.type;
|
1129
|
|
- passport.user.real_auth_status = data.user.real_auth_status;
|
1130
|
|
- passport.user.credential_status = data.user.credential_status;
|
1131
|
|
- passport.user.user_info.scope = scopes[0];
|
1132
|
|
- req.session.passport = passport;
|
1133
|
|
- req.session.save(function () {
|
1134
|
|
- if (settings.prefix && settings.prefix.length > 1) {
|
1135
|
|
- res.redirect(
|
1136
|
|
- 301,
|
1137
|
|
- settings.prefix.substring(0, settings.prefix.length - 1) +
|
1138
|
|
- "/#task_assign/" +
|
1139
|
|
- id
|
1140
|
|
- );
|
1141
|
|
- } else {
|
1142
|
|
- res.redirect(301, "/#task_assign/" + id);
|
1143
|
|
- }
|
1144
|
|
- });
|
1145
|
|
- } else {
|
1146
|
|
- passport.user.err = data.message;
|
1147
|
|
- }
|
1148
|
|
- })
|
1149
|
|
- .on("error", function (err, response) {
|
1150
|
|
- logger.error("Third login error", err);
|
1151
|
|
- var err = new Error("Third login err");
|
1152
|
|
- callback(err, response);
|
1153
|
|
- })
|
1154
|
|
- .on("fail", function (data) {
|
1155
|
|
- logger.error("Third login fail", data);
|
1156
|
|
- });
|
1157
|
|
- }
|
1158
|
|
- }
|
1159
|
|
-
|
1160
|
|
- function getShortToken(req, res) {
|
1161
|
|
- var params = {
|
1162
|
|
- grant_type: "refresh_token",
|
1163
|
|
- scope: req.session.passport.user.scope,
|
1164
|
|
- refresh_token: req.session.passport.user.refreshToken,
|
1165
|
|
- };
|
1166
|
|
- logger.info("getShortToken:", params);
|
1167
|
|
- rest.postJson({
|
1168
|
|
- baseUrl: "url",
|
1169
|
|
- url:
|
1170
|
|
- settings.restful.url +
|
1171
|
|
- "uaa" +
|
1172
|
|
- settings.restful.version +
|
1173
|
|
- "/auth/tokens",
|
1174
|
|
- useUrl: true,
|
1175
|
|
- params: params,
|
1176
|
|
- callback: _cb,
|
1177
|
|
- req: req,
|
1178
|
|
- res: res,
|
1179
|
|
- options: {},
|
1180
|
|
- excludeToken: true,
|
1181
|
|
- });
|
1182
|
|
- function _cb(data, response) {
|
1183
|
|
- console.log(data);
|
1184
|
|
- logger.info("back data:", data);
|
1185
|
|
- res.send({ code: response.statusCode, access_token: data.access_token });
|
1186
|
|
- }
|
1187
|
|
- }
|
1188
|
|
-
|
1189
|
|
- return {
|
1190
|
|
- index: index,
|
1191
|
|
- indexPrefix,
|
1192
|
|
- register: register,
|
1193
|
|
- signIn: signIn,
|
1194
|
|
- doLogin: doLogin,
|
1195
|
|
- signOut: signOut,
|
1196
|
|
- smsCodes: smsCodes,
|
1197
|
|
- tenants: tenants,
|
1198
|
|
- productDes: productDes,
|
1199
|
|
- resetPass: resetPass,
|
1200
|
|
- updatePassword: updatePassword,
|
1201
|
|
- loadUserInfo: loadUserInfo,
|
1202
|
|
- getUploaderToken: getUploaderToken,
|
1203
|
|
- getObjectTokenByID,
|
1204
|
|
- delOSSObject: delOSSObject,
|
1205
|
|
- healthMonitor,
|
1206
|
|
- smsVerification,
|
1207
|
|
- updateUserRoles,
|
1208
|
|
- getRoles,
|
1209
|
|
- getUserRoles,
|
1210
|
|
- getTenant,
|
1211
|
|
- updateTenant,
|
1212
|
|
- offer,
|
1213
|
|
- onboardStatus,
|
1214
|
|
- dowloadApp,
|
1215
|
|
- mobileRegister,
|
1216
|
|
- mobileRegisterSuccess,
|
1217
|
|
- softwareLicense,
|
1218
|
|
- recharge,
|
1219
|
|
- changePassForRegister,
|
1220
|
|
- changeTenant,
|
1221
|
|
- sendRejectOffer,
|
1222
|
|
- acceptOffer,
|
1223
|
|
- imTokens,
|
1224
|
|
- listChannels,
|
1225
|
|
- filemeta,
|
1226
|
|
- getCustomerQrcode,
|
1227
|
|
- getPositionQrcode,
|
1228
|
|
- getOSSConfig,
|
1229
|
|
- weidianTempLate,
|
1230
|
|
- workaiSecurityOAuth,
|
1231
|
|
- getTastLink,
|
1232
|
|
- freedomJobsEmp,
|
1233
|
|
- getShortToken,
|
1234
|
|
- getImg
|
1235
|
|
- };
|
|
1
|
+var passport = require('passport');
|
|
2
|
+var clientRest = require('restler');
|
|
3
|
+var urlencode = require('urlencode');
|
|
4
|
+var async = require('async');
|
|
5
|
+var crypto = require('crypto');
|
|
6
|
+
|
|
7
|
+exports = module.exports = function (logger, rest, redis, settings) {
|
|
8
|
+ function index(req, res, next) {
|
|
9
|
+ logger.debug(req.user);
|
|
10
|
+ if (req.csrfToken) {
|
|
11
|
+ res.render('index', { 'csrfToken': req.csrfToken() });
|
|
12
|
+ } else
|
|
13
|
+ res.render('index', { 'csrfToken': '' });
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ function indexPrefix(req, res, next) {
|
|
17
|
+ logger.debug(req.user);
|
|
18
|
+ if (req.csrfToken) {
|
|
19
|
+ if (settings.prefix && settings.prefix.length > 1) {
|
|
20
|
+ res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
|
|
21
|
+ } else {
|
|
22
|
+ res.render('index', { 'csrfToken': req.csrfToken() });
|
|
23
|
+ }
|
|
24
|
+ } else
|
|
25
|
+ res.render('index', { 'csrfToken': '' });
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ function productDes(req, res, next) {
|
|
29
|
+ if (req.csrfToken)
|
|
30
|
+ res.render('chat/new-chat', { 'csrfToken': req.csrfToken() });
|
|
31
|
+ else
|
|
32
|
+ res.render('chat/new-chat', { 'csrfToken': '' });
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ function recharge(req, res, next) {
|
|
36
|
+
|
|
37
|
+ var params = JSON.parse(urlencode.decode(req.query.params));
|
|
38
|
+ logger.debug(params);
|
|
39
|
+ if (req.csrfToken)
|
|
40
|
+ res.render('recharge', { 'recharge': params, 'csrfToken': req.csrfToken() });
|
|
41
|
+ else
|
|
42
|
+ res.render('recharge', { 'recharge': params, 'csrfToken': '' });
|
|
43
|
+
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ function register(req, res, next) {
|
|
47
|
+ if (req.csrfToken)
|
|
48
|
+ res.render('newRegister', { 'csrfToken': req.csrfToken() });
|
|
49
|
+ else
|
|
50
|
+ res.render('newRegister', { 'csrfToken': '' });
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ function mobileRegister(req, res, next) {
|
|
54
|
+ if (req.csrfToken)
|
|
55
|
+ res.render('registerMobile', { 'csrfToken': req.csrfToken() });
|
|
56
|
+ else
|
|
57
|
+ res.render('registerMobile', { 'csrfToken': '' });
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ function mobileRegisterSuccess(req, res, next) {
|
|
61
|
+ if (req.csrfToken)
|
|
62
|
+ res.render('registerMobileSuccess', { 'csrfToken': req.csrfToken() });
|
|
63
|
+ else
|
|
64
|
+ res.render('registerMobileSuccess', { 'csrfToken': '' });
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ function signIn(req, res, next) {
|
|
68
|
+ // console.log(req);
|
|
69
|
+ if (req.csrfToken)
|
|
70
|
+ res.render('newLogin', { 'csrfToken': req.csrfToken() });
|
|
71
|
+ else
|
|
72
|
+ res.render('newLogin', { 'csrfToken': '' });
|
|
73
|
+
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ function doLogin(req, res, next) {
|
|
77
|
+ passport.authenticate('local', function (err, user, info) {
|
|
78
|
+ logger.debug("doLogin:", err, user, info)
|
|
79
|
+ if (err) { return next(err); }
|
|
80
|
+ if (!user) { return res.send(info); }
|
|
81
|
+ req.logIn(user, function (err) {
|
|
82
|
+ if (err) { return next(err); }
|
|
83
|
+ return res.send({ 'ok': '登录成功', user_info: req.session.passport.user.user_info });
|
|
84
|
+ });
|
|
85
|
+ })(req, res, next);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ function refreshToken (req, res, next) {
|
|
89
|
+ var timer = null;
|
|
90
|
+ const count = req.session.refreshTokenCount||0;
|
|
91
|
+ if(count>3){
|
|
92
|
+ res.send({
|
|
93
|
+ code:500,
|
|
94
|
+ message:'失败'
|
|
95
|
+ })
|
|
96
|
+ timer = setTimeout(()=>{
|
|
97
|
+ req.session.refreshTokenCount=0
|
|
98
|
+ clearTimeout(timer)
|
|
99
|
+ },1000*60*5)
|
|
100
|
+ return
|
|
101
|
+ }
|
|
102
|
+ var tempParams = {
|
|
103
|
+ "grant_type": "refresh_token",
|
|
104
|
+ "username": req.session.passport.user.user_info.user.mobile,
|
|
105
|
+ refresh_token:req.session.passport.user.refreshToken,
|
|
106
|
+ "scope": "global_access:tenant_admin",
|
|
107
|
+ };
|
|
108
|
+ var url = rest.getBaseUrl('auth/tokens', 'uaa');
|
|
109
|
+ var headers = rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req);
|
|
110
|
+ rest.restful.postJson(url, tempParams, {
|
|
111
|
+ headers: headers
|
|
112
|
+ }).on('success',function(data,response){
|
|
113
|
+ req.session.passport.user.token = data.access_token;
|
|
114
|
+ req.session.refreshTokenCount = count+1;
|
|
115
|
+ res.send({code:200,message:'成功'})
|
|
116
|
+ rest.proxyLog(data,response,req,{headers,'data':tempParams,url})
|
|
117
|
+ })
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ function signOut(req, res, next) {
|
|
121
|
+ if (req.session.passport && req.session.passport.user && req.session.passport.user.user_info && req.session.passport.user.user_info.user)
|
|
122
|
+ logger.debug(req.session.passport.user.user_info.user, 'You have successfully logged out');
|
|
123
|
+ req.logout();
|
|
124
|
+ req.flash('success', 'You have successfully logged out');
|
|
125
|
+ res.redirect('/');
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ function smsCodes(req, res, next) {
|
|
129
|
+ rest.postJson({
|
|
130
|
+ 'baseUrl': 'url',
|
|
131
|
+ 'url': 'auth/smscodes',
|
|
132
|
+ 'params': req.body,
|
|
133
|
+ 'callback': _cb,
|
|
134
|
+ 'req': req,
|
|
135
|
+ 'res': res,
|
|
136
|
+ 'options': {},
|
|
137
|
+ 'excludeToken': true
|
|
138
|
+ })
|
|
139
|
+ function _cb(data, response) {
|
|
140
|
+ logger.debug("back data:", data);
|
|
141
|
+ if (response.statusCode < 300) {
|
|
142
|
+ res.send({ "code": 200, "message": "发送成功" });
|
|
143
|
+ } else {
|
|
144
|
+ res.send(data);
|
|
145
|
+ }
|
|
146
|
+ };
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ function tenants(req, res, next) {
|
|
150
|
+ rest.register({
|
|
151
|
+ 'baseUrl': 'url',
|
|
152
|
+ 'url': 'tenants',
|
|
153
|
+ 'params': req.body,
|
|
154
|
+ 'callback': _cb,
|
|
155
|
+ 'req': req,
|
|
156
|
+ 'res': res,
|
|
157
|
+ 'options': {},
|
|
158
|
+ 'excludeToken': true
|
|
159
|
+ });
|
|
160
|
+ function _cb(data, response) {
|
|
161
|
+ logger.debug("back data:", data);
|
|
162
|
+ res.send(data);
|
|
163
|
+ };
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ function resetPass(req, res) {
|
|
167
|
+ rest.putJson({
|
|
168
|
+ 'baseUrl': 'url',
|
|
169
|
+ 'url': 'auth/user',
|
|
170
|
+ 'params': {
|
|
171
|
+ 'user': req.body.user,
|
|
172
|
+ 'password': req.body.password,
|
|
173
|
+ 'again_password': req.body.again_password
|
|
174
|
+ },
|
|
175
|
+ 'callback': _cb,
|
|
176
|
+ 'req': req,
|
|
177
|
+ 'res': res,
|
|
178
|
+ 'options': {}
|
|
179
|
+ })
|
|
180
|
+ function _cb(data, response) {
|
|
181
|
+ logger.debug("back data:", data);
|
|
182
|
+ res.send(data);
|
|
183
|
+ };
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ function updatePassword(req, res) {
|
|
187
|
+ rest.patchJson({
|
|
188
|
+ 'baseUrl': 'url',
|
|
189
|
+ 'url': 'users/' + req.body.userId,
|
|
190
|
+ 'params': {
|
|
191
|
+ 'password': req.body.password
|
|
192
|
+ },
|
|
193
|
+ 'callback': _cb,
|
|
194
|
+ 'req': req,
|
|
195
|
+ 'res': res,
|
|
196
|
+ 'options': {}
|
|
197
|
+ })
|
|
198
|
+ function _cb(data, response) {
|
|
199
|
+ logger.debug("back data:", data);
|
|
200
|
+ res.send(data);
|
|
201
|
+ };
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+ function loadUserInfo(req, res,next) {
|
|
206
|
+
|
|
207
|
+ if (req.session.passport.user && req.session.passport.user.user_info) {
|
|
208
|
+ logger.debug("loadUserInfo:", req.session.passport.user.user_info);
|
|
209
|
+ if(req.body.id){
|
|
210
|
+ var params = {
|
|
211
|
+ grant_type: 'refresh_token',
|
|
212
|
+ scope: 'global_access:tenant_admin,tenant:' + req.body.id,
|
|
213
|
+ refresh_token: req.session.passport.user.refreshToken
|
|
214
|
+ }
|
|
215
|
+ // req.session.passport.user.token = '';
|
|
216
|
+ rest.postJson({
|
|
217
|
+ 'baseUrl': 'url',
|
|
218
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/auth/tokens',
|
|
219
|
+ 'useUrl': true,
|
|
220
|
+ 'params': params,
|
|
221
|
+ 'callback': _cb,
|
|
222
|
+ 'req': req,
|
|
223
|
+ 'res': res,
|
|
224
|
+ 'options': {},
|
|
225
|
+ 'excludeToken': true
|
|
226
|
+ })
|
|
227
|
+ function _cb(data, response) {
|
|
228
|
+ logger.debug("changeTenant,tokens......:", data);
|
|
229
|
+ if (response.statusCode < 300) {
|
|
230
|
+ req.session.passport.user.token = data.access_token;
|
|
231
|
+ req.session.passport.user.refreshToken = data.refresh_token;
|
|
232
|
+ req.session.passport.user.user_info = {
|
|
233
|
+ 'user': data.user,
|
|
234
|
+ 'perms': req.session.passport.user.user_info.perms,
|
|
235
|
+ 'tenant': data.tenant,
|
|
236
|
+ 'scope': data.scope,
|
|
237
|
+ 'oss': req.session.passport.user.user_info.oss,
|
|
238
|
+ };
|
|
239
|
+ req.session.save(function (err) {
|
|
240
|
+ rest.get({
|
|
241
|
+ 'baseUrl': 'url',
|
|
242
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/perms/detail',
|
|
243
|
+ 'useUrl': true,
|
|
244
|
+ 'params': {},
|
|
245
|
+ 'callback': _scb,
|
|
246
|
+ 'req': req,
|
|
247
|
+ 'res': res,
|
|
248
|
+ 'options': {}
|
|
249
|
+ });
|
|
250
|
+ })
|
|
251
|
+ } else {
|
|
252
|
+ res.send({ "code": response.statusCode, "message": data.message, initialize_done: "n" });
|
|
253
|
+ }
|
|
254
|
+ };
|
|
255
|
+ function _scb(data1, response) {
|
|
256
|
+ if (response.statusCode < 300 && data1.items) {
|
|
257
|
+ logger.debug("perms......:", data1.items);
|
|
258
|
+ //判断是否存在优学乐业菜单
|
|
259
|
+ if (data1.items.length > 0) {
|
|
260
|
+ let yxly_list = data1.items.filter((item, index) => { return item.module == 'yxly' });
|
|
261
|
+ if (yxly_list.length > 0) {
|
|
262
|
+ loadYxlyToken(req, res);
|
|
263
|
+ }
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ req.session.passport.user.user_info.perms = data1.items;
|
|
267
|
+ req.session.save(function (err) {
|
|
268
|
+ rest.get({
|
|
269
|
+ 'baseUrl': 'url',
|
|
270
|
+ 'url': settings.restful.url + 'filemeta' + settings.restful.version + '/config',
|
|
271
|
+ 'useUrl': true,
|
|
272
|
+ 'params': {},
|
|
273
|
+ 'callback': _scb1,
|
|
274
|
+ 'req': req,
|
|
275
|
+ 'res': res,
|
|
276
|
+ 'options': {}
|
|
277
|
+ });
|
|
278
|
+ })
|
|
279
|
+ } else {
|
|
280
|
+ res.send({ "code": response.statusCode, "message": data1.message });
|
|
281
|
+ }
|
|
282
|
+ }
|
|
283
|
+ function _scb1(data2, response) {
|
|
284
|
+ if (response.statusCode < 300 && data2 && data2.bucket) {
|
|
285
|
+ req.session.passport.user.user_info.oss = data2;
|
|
286
|
+ req.session.save(function (err) {
|
|
287
|
+ res.send({ user_info: req.session.passport.user.user_info, prefix: settings.prefix });
|
|
288
|
+ });
|
|
289
|
+ } else {
|
|
290
|
+ res.send({ "code": 200, "message": "切换租户失败" });
|
|
291
|
+ }
|
|
292
|
+ }
|
|
293
|
+ }else {
|
|
294
|
+ res.send({ user_info: req.session.passport.user.user_info, prefix: settings.prefix });
|
|
295
|
+ }
|
|
296
|
+ } else {
|
|
297
|
+ res.send({ user_info: null, prefix: settings.prefix });
|
|
298
|
+ }
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ function getUploaderToken(req, res) {
|
|
302
|
+ rest.postJson({
|
|
303
|
+ 'baseUrl': 'ossUrl',
|
|
304
|
+ 'url': 'inits',
|
|
305
|
+ 'params': req.body,
|
|
306
|
+ 'callback': _cb,
|
|
307
|
+ 'req': req,
|
|
308
|
+ 'res': res,
|
|
309
|
+ 'options': {}
|
|
310
|
+ })
|
|
311
|
+ function _cb(data, response) {
|
|
312
|
+ logger.debug("back data:", data);
|
|
313
|
+ res.send(data);
|
|
314
|
+ };
|
|
315
|
+ }
|
|
316
|
+
|
|
317
|
+ function getObjectTokenByID(req, res) {
|
|
318
|
+ rest.get({
|
|
319
|
+ 'baseUrl': 'ossUrl',
|
|
320
|
+ 'url': 'objects/' + req.body.file_id,
|
|
321
|
+ 'params': {},
|
|
322
|
+ 'callback': _cb,
|
|
323
|
+ 'req': req,
|
|
324
|
+ 'res': res,
|
|
325
|
+ 'options': {}
|
|
326
|
+ })
|
|
327
|
+ function _cb(data, response) {
|
|
328
|
+ logger.debug("back data:", data);
|
|
329
|
+ res.send(data);
|
|
330
|
+ };
|
|
331
|
+ }
|
|
332
|
+
|
|
333
|
+ function delOSSObject(req, res) {
|
|
334
|
+ rest.del({
|
|
335
|
+ 'baseUrl': 'ossUrl',
|
|
336
|
+ 'url': 's3objects/' + req.body.request_id + '?bucket=' + req.body.bucket + '&file=' + req.body.name,
|
|
337
|
+ 'params': {},
|
|
338
|
+ 'callback': _cb,
|
|
339
|
+ 'req': req,
|
|
340
|
+ 'res': res,
|
|
341
|
+ 'options': {}
|
|
342
|
+ })
|
|
343
|
+ function _cb(data, response) {
|
|
344
|
+ logger.debug("back data:", data);
|
|
345
|
+ logger.debug(response.statusCode)
|
|
346
|
+ if (response.statusCode < 300) {
|
|
347
|
+ res.send({ 'delete': 'ok' });
|
|
348
|
+ }
|
|
349
|
+ };
|
|
350
|
+ }
|
|
351
|
+
|
|
352
|
+ function smsVerification(req, res, next) {
|
|
353
|
+ rest.postJson({
|
|
354
|
+ 'baseUrl': 'url',
|
|
355
|
+ 'url': 'auth/sms_verification',
|
|
356
|
+ 'params': req.body,
|
|
357
|
+ 'callback': _cb,
|
|
358
|
+ 'req': req,
|
|
359
|
+ 'res': res,
|
|
360
|
+ 'options': {},
|
|
361
|
+ 'excludeToken': true
|
|
362
|
+ })
|
|
363
|
+ function _cb(data, response) {
|
|
364
|
+ logger.debug("back data:", data);
|
|
365
|
+ if (response.statusCode < 300) {
|
|
366
|
+ res.send({ "code": 200, "message": "发送成功" });
|
|
367
|
+ } else {
|
|
368
|
+ res.send({ "code": response.statusCode, "message": data.message, 'errors': data.errors });
|
|
369
|
+ }
|
|
370
|
+ };
|
|
371
|
+ }
|
|
372
|
+
|
|
373
|
+ function healthMonitor(req, res) {
|
|
374
|
+ res.statusCode = 200;
|
|
375
|
+ return res.send('status ok');
|
|
376
|
+ }
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+ function updateUserRoles(req, res) {
|
|
380
|
+ rest.putJson({
|
|
381
|
+ 'baseUrl': 'url',
|
|
382
|
+ 'url': 'user_roles/' + req.body.user_id,
|
|
383
|
+ 'params': req.body.roles,
|
|
384
|
+ 'callback': _cb,
|
|
385
|
+ 'req': req,
|
|
386
|
+ 'res': res,
|
|
387
|
+ 'options': {}
|
|
388
|
+ })
|
|
389
|
+ function _cb(data, response) {
|
|
390
|
+ logger.debug("back data:", data);
|
|
391
|
+ if (response.statusCode < 300) {
|
|
392
|
+ res.send({ 'back': 'ok' });
|
|
393
|
+ } else {
|
|
394
|
+ res.send(data);
|
|
395
|
+ }
|
|
396
|
+ };
|
|
397
|
+ }
|
|
398
|
+
|
|
399
|
+ function getRoles(req, res, next) {
|
|
400
|
+ rest.get({
|
|
401
|
+ 'baseUrl': 'url',
|
|
402
|
+ 'url': 'roles',
|
|
403
|
+ 'params': {},
|
|
404
|
+ 'callback': _cb,
|
|
405
|
+ 'req': req,
|
|
406
|
+ 'res': res,
|
|
407
|
+ 'options': {}
|
|
408
|
+ })
|
|
409
|
+ function _cb(data, response) {
|
|
410
|
+ logger.debug("back data:", data);
|
|
411
|
+ res.send(data);
|
|
412
|
+ };
|
|
413
|
+ }
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+ function getUserRoles(req, res, next) {
|
|
417
|
+ rest.get({
|
|
418
|
+ 'baseUrl': 'url',
|
|
419
|
+ 'url': 'user_roles?user=' + urlencode(req.body.user) + '&limit=' + req.body.limit + '&offset=' + req.body.offset,
|
|
420
|
+ 'params': {},
|
|
421
|
+ 'callback': _cb,
|
|
422
|
+ 'req': req,
|
|
423
|
+ 'res': res,
|
|
424
|
+ 'options': {}
|
|
425
|
+ })
|
|
426
|
+ function _cb(data, response) {
|
|
427
|
+ logger.debug("back data:", data);
|
|
428
|
+ res.send(data);
|
|
429
|
+ };
|
|
430
|
+ }
|
|
431
|
+
|
|
432
|
+ function getTenant(req, res) {
|
|
433
|
+ rest.get({
|
|
434
|
+ 'baseUrl': 'url',
|
|
435
|
+ 'url': 'tenants/' + req.body.tenant_id,
|
|
436
|
+ 'params': {},
|
|
437
|
+ 'callback': _cb,
|
|
438
|
+ 'req': req,
|
|
439
|
+ 'res': res,
|
|
440
|
+ 'options': {}
|
|
441
|
+ })
|
|
442
|
+ function _cb(data, response) {
|
|
443
|
+ logger.debug("back data:", data);
|
|
444
|
+ res.send(data);
|
|
445
|
+ };
|
|
446
|
+ }
|
|
447
|
+
|
|
448
|
+ function updateTenant(req, res) {
|
|
449
|
+ rest.putJson({
|
|
450
|
+ 'baseUrl': 'url',
|
|
451
|
+ 'url': 'tenants/' + req.body.tenant_id,
|
|
452
|
+ 'params': req.body.tenant,
|
|
453
|
+ 'callback': _cb,
|
|
454
|
+ 'req': req,
|
|
455
|
+ 'res': res,
|
|
456
|
+ 'options': {}
|
|
457
|
+ })
|
|
458
|
+ function _cb(data, response) {
|
|
459
|
+ logger.debug("back data:", data);
|
|
460
|
+ res.send(data);
|
|
461
|
+ };
|
|
462
|
+ }
|
|
463
|
+
|
|
464
|
+ function offer(req, res) {
|
|
465
|
+ rest.get({
|
|
466
|
+ 'baseUrl': 'hrUrl',
|
|
467
|
+ 'url': 'offers/' + req.params.requestId + '?tenant_id=' + req.query.tenant_id,
|
|
468
|
+ 'params': {},
|
|
469
|
+ 'callback': _cb,
|
|
470
|
+ 'req': req,
|
|
471
|
+ 'res': res,
|
|
472
|
+ 'options': {},
|
|
473
|
+ 'excludeToken': true
|
|
474
|
+ })
|
|
475
|
+ function _cb(data, response) {
|
|
476
|
+ logger.debug(data);
|
|
477
|
+ data['offerId'] = req.params.requestId;
|
|
478
|
+ data['tenantId'] = req.query.tenant_id;
|
|
479
|
+ res.render('offer', data);
|
|
480
|
+ };
|
|
481
|
+ }
|
|
482
|
+
|
|
483
|
+ function onboardStatus(req, res) {
|
|
484
|
+ rest.get({
|
|
485
|
+ 'baseUrl': 'hrUrl',
|
|
486
|
+ 'url': 'onboard-status',
|
|
487
|
+ 'params': {},
|
|
488
|
+ 'callback': _cb,
|
|
489
|
+ 'req': req,
|
|
490
|
+ 'res': res,
|
|
491
|
+ 'options': {},
|
|
492
|
+ 'useUrl': true
|
|
493
|
+ })
|
|
494
|
+ function _cb(data, response) {
|
|
495
|
+ logger.debug("back data:", data);
|
|
496
|
+ res.send(data);
|
|
497
|
+ };
|
|
498
|
+ }
|
|
499
|
+
|
|
500
|
+ function dowloadApp(req, res) {
|
|
501
|
+ var mobileAgent = req.headers['user-agent'].toLowerCase();
|
|
502
|
+ var agent = {
|
|
503
|
+ android: mobileAgent.indexOf('android') > -1 || mobileAgent.indexOf('Adr') > -1,
|
|
504
|
+ iPhone: mobileAgent.indexOf('iphone') > -1,
|
|
505
|
+ iPad: mobileAgent.indexOf('ipad') > -1
|
|
506
|
+ }
|
|
507
|
+ if (agent.iPhone || agent.iPad) {
|
|
508
|
+ res.redirect(301, 'https://itunes.apple.com/cn/app/%E8%96%AA%E5%91%97/id1140779439?l=en&mt=8');
|
|
509
|
+ } else if (agent.android) {
|
|
510
|
+ res.redirect(301, 'http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk');
|
|
511
|
+ } else {
|
|
512
|
+ res.redirect(301, 'http://krhrimg.oss-cn-beijing.aliyuncs.com/appdownload/production/android/krhr-android.apk');
|
|
513
|
+ }
|
|
514
|
+ }
|
|
515
|
+
|
|
516
|
+ function softwareLicense(req, res, next) {
|
|
517
|
+ res.render('softwareLicense');
|
|
518
|
+ }
|
|
519
|
+
|
|
520
|
+ function changePassForRegister(req, res, next) {
|
|
521
|
+ var options = {
|
|
522
|
+ 'baseUrl': 'url',
|
|
523
|
+ 'url': 'users/' + req.body.user_id,
|
|
524
|
+ 'params': {
|
|
525
|
+ 'password': req.body.password
|
|
526
|
+ },
|
|
527
|
+ 'callback': _cb,
|
|
528
|
+ 'req': req,
|
|
529
|
+ 'res': res,
|
|
530
|
+ 'options': {}
|
|
531
|
+ };
|
|
532
|
+ if (req.body.access_token) {
|
|
533
|
+ options.options = {
|
|
534
|
+ "accessToken": req.body.access_token
|
|
535
|
+ };
|
|
536
|
+ options['excludeToken'] = true;
|
|
537
|
+ }
|
|
538
|
+ rest.patchJson(options)
|
|
539
|
+ function _cb(data, response) {
|
|
540
|
+ logger.debug("back data:", data);
|
|
541
|
+ res.send(data);
|
|
542
|
+ };
|
|
543
|
+ }
|
|
544
|
+
|
|
545
|
+ function changeTenant(req, res, next) {
|
|
546
|
+ var params = {
|
|
547
|
+ grant_type: 'refresh_token',
|
|
548
|
+ scope: 'global_access:tenant_admin,tenant:' + req.body.id,
|
|
549
|
+ refresh_token: req.session.passport.user.refreshToken
|
|
550
|
+ }
|
|
551
|
+ req.session.passport.user.token = '';
|
|
552
|
+ rest.postJson({
|
|
553
|
+ 'baseUrl': 'url',
|
|
554
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/auth/tokens',
|
|
555
|
+ 'useUrl': true,
|
|
556
|
+ 'params': params,
|
|
557
|
+ 'callback': _cb,
|
|
558
|
+ 'req': req,
|
|
559
|
+ 'res': res,
|
|
560
|
+ 'options': {},
|
|
561
|
+ 'excludeToken': true
|
|
562
|
+ })
|
|
563
|
+ function _cb(data, response) {
|
|
564
|
+ logger.debug("changeTenant,tokens......:", data);
|
|
565
|
+ if (response.statusCode < 300) {
|
|
566
|
+ req.session.passport.user.token = data.access_token;
|
|
567
|
+ req.session.passport.user.refreshToken = data.refresh_token;
|
|
568
|
+ req.session.passport.user.user_info = {
|
|
569
|
+ 'user': data.user,
|
|
570
|
+ 'perms': [],
|
|
571
|
+ 'tenant': data.tenant,
|
|
572
|
+ 'scope': data.scope,
|
|
573
|
+ 'oss': req.session.passport.user.user_info.oss,
|
|
574
|
+ };
|
|
575
|
+ req.session.save(function (err) {
|
|
576
|
+ rest.get({
|
|
577
|
+ 'baseUrl': 'url',
|
|
578
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/perms/detail',
|
|
579
|
+ 'useUrl': true,
|
|
580
|
+ 'params': {},
|
|
581
|
+ 'callback': _scb,
|
|
582
|
+ 'req': req,
|
|
583
|
+ 'res': res,
|
|
584
|
+ 'options': {}
|
|
585
|
+ });
|
|
586
|
+ })
|
|
587
|
+ } else {
|
|
588
|
+ res.send({ "code": response.statusCode, "message": data.message, initialize_done: "n" });
|
|
589
|
+ }
|
|
590
|
+ };
|
|
591
|
+ function _scb(data1, response) {
|
|
592
|
+ if (response.statusCode < 300 && data1.items) {
|
|
593
|
+ logger.debug("perms......:", data1.items);
|
|
594
|
+ //判断是否存在优学乐业菜单
|
|
595
|
+ if (data1.items.length > 0) {
|
|
596
|
+ let yxly_list = data1.items.filter((item, index) => { return item.module == 'yxly' });
|
|
597
|
+ if (yxly_list.length > 0) {
|
|
598
|
+ loadYxlyToken(req, res);
|
|
599
|
+ }
|
|
600
|
+ }
|
|
601
|
+
|
|
602
|
+ req.session.passport.user.user_info.perms = data1.items;
|
|
603
|
+ req.session.save(function (err) {
|
|
604
|
+ rest.get({
|
|
605
|
+ 'baseUrl': 'url',
|
|
606
|
+ 'url': settings.restful.url + 'filemeta' + settings.restful.version + '/config',
|
|
607
|
+ 'useUrl': true,
|
|
608
|
+ 'params': {},
|
|
609
|
+ 'callback': _scb1,
|
|
610
|
+ 'req': req,
|
|
611
|
+ 'res': res,
|
|
612
|
+ 'options': {}
|
|
613
|
+ });
|
|
614
|
+ })
|
|
615
|
+ } else {
|
|
616
|
+ res.send({ "code": response.statusCode, "message": data1.message });
|
|
617
|
+ }
|
|
618
|
+ }
|
|
619
|
+ function _scb1(data2, response) {
|
|
620
|
+ if (response.statusCode < 300 && data2 && data2.bucket) {
|
|
621
|
+ req.session.passport.user.user_info.oss = data2;
|
|
622
|
+ req.session.save(function (err) {
|
|
623
|
+ res.send({ "code": 200, "message": "切换租户成功" });
|
|
624
|
+ });
|
|
625
|
+ } else {
|
|
626
|
+ res.send({ "code": 200, "message": "切换租户失败" });
|
|
627
|
+ }
|
|
628
|
+ }
|
|
629
|
+ }
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+ function sendRejectOffer(req, res) {
|
|
633
|
+ rest.get({
|
|
634
|
+ 'baseUrl': 'hrUrl',
|
|
635
|
+ 'url': req.body.url, //传一个参数
|
|
636
|
+ 'params': {},
|
|
637
|
+ 'callback': _cb,
|
|
638
|
+ 'req': req,
|
|
639
|
+ 'res': res,
|
|
640
|
+ 'options': {},
|
|
641
|
+ 'excludeToken': true,
|
|
642
|
+ 'useUrl': true
|
|
643
|
+ });
|
|
644
|
+ function _cb(data, response) {
|
|
645
|
+ logger.debug("back data:", data);
|
|
646
|
+ if (response.statusCode < 300) {
|
|
647
|
+ res.send({ 'action': 'ok' });
|
|
648
|
+ } else {
|
|
649
|
+ res.send(data);
|
|
650
|
+ }
|
|
651
|
+ };
|
|
652
|
+ }
|
|
653
|
+
|
|
654
|
+ function acceptOffer(req, res) {
|
|
655
|
+ rest.get({
|
|
656
|
+ 'baseUrl': 'hrUrl',
|
|
657
|
+ 'url': req.body.url, //传一个参数
|
|
658
|
+ 'params': {},
|
|
659
|
+ 'callback': _cb,
|
|
660
|
+ 'req': req,
|
|
661
|
+ 'res': res,
|
|
662
|
+ 'options': {},
|
|
663
|
+ 'excludeToken': true,
|
|
664
|
+ 'useUrl': true
|
|
665
|
+ });
|
|
666
|
+ function _cb(data, response) {
|
|
667
|
+ logger.debug("back data:", data);
|
|
668
|
+ if (response.statusCode < 300) {
|
|
669
|
+ res.send({ 'action': 'ok' });
|
|
670
|
+ } else {
|
|
671
|
+ res.send(data);
|
|
672
|
+ }
|
|
673
|
+ };
|
|
674
|
+ }
|
|
675
|
+
|
|
676
|
+ function imTokens(req, res) {
|
|
677
|
+ rest.post({
|
|
678
|
+ 'url': 'auth/im_tokens',
|
|
679
|
+ 'params': req.body,
|
|
680
|
+ 'callback': _cb,
|
|
681
|
+ 'req': req,
|
|
682
|
+ 'res': res,
|
|
683
|
+ 'options': {}
|
|
684
|
+ });
|
|
685
|
+ function _cb(data, response) {
|
|
686
|
+ logger.debug("back data:", data);
|
|
687
|
+ res.send(data);
|
|
688
|
+ };
|
|
689
|
+ }
|
|
690
|
+
|
|
691
|
+ function listChannels(req, res, next) {
|
|
692
|
+ rest.get({
|
|
693
|
+ 'baseUrl': 'chatUrl',
|
|
694
|
+ 'url': 'channels?page_size=10&page=0&status=active',
|
|
695
|
+ 'params': req.body,
|
|
696
|
+ 'callback': _cb,
|
|
697
|
+ 'req': req,
|
|
698
|
+ 'res': res,
|
|
699
|
+ 'options': {}
|
|
700
|
+ })
|
|
701
|
+ function _cb(data, response) {
|
|
702
|
+ logger.debug("back data:", data);
|
|
703
|
+ res.send(data);
|
|
704
|
+ };
|
|
705
|
+ }
|
|
706
|
+
|
|
707
|
+ function filemeta(req, res, next) {
|
|
708
|
+ var fullPath = settings.restful.url + 'filemeta' + settings.restful.version + '/object-redirect';
|
|
709
|
+ fullPath = fullPath + "?" + "bucket=" + req.query.bucket + "&object=" + encodeURIComponent(req.query.object);
|
|
710
|
+ console.info('fullPath::::::', fullPath);
|
|
711
|
+ var options = {
|
|
712
|
+ 'service_catalog': '',
|
|
713
|
+ 'url': fullPath,
|
|
714
|
+ 'useUrl': true,
|
|
715
|
+ 'params': req.body,
|
|
716
|
+ 'callback': _cb,
|
|
717
|
+ 'req': req,
|
|
718
|
+ 'res': res,
|
|
719
|
+ 'options': {}
|
|
720
|
+ };
|
|
721
|
+ rest.get(options);
|
|
722
|
+ function _cb(data, response) {
|
|
723
|
+ if (data && data.download_url) {
|
|
724
|
+ if (req.query.type && 'json' == req.query.type) {
|
|
725
|
+ res.send(data);
|
|
726
|
+ } else {
|
|
727
|
+ var url = data.download_url;
|
|
728
|
+ let path = url.split('?')[0];
|
|
729
|
+ let pathArray = path.split('/');
|
|
730
|
+ let result = [];
|
|
731
|
+ for (var i = 0; i < pathArray.length; i++) {
|
|
732
|
+ if (i == pathArray.length - 1) {
|
|
733
|
+ result.push(encodeURIComponent(pathArray[i]));
|
|
734
|
+ } else {
|
|
735
|
+ result.push(pathArray[i]);
|
|
736
|
+ }
|
|
737
|
+ }
|
|
738
|
+ let result1 = result.join('/');
|
|
739
|
+ if (url.indexOf('?') !== -1) {
|
|
740
|
+ result1 += '?' + url.split('?')[1];
|
|
741
|
+ }
|
|
742
|
+ if (req.query.result_callback) {
|
|
743
|
+ res.send(data);
|
|
744
|
+ } else {
|
|
745
|
+ res.redirect(301, result1);
|
|
746
|
+ }
|
|
747
|
+ }
|
|
748
|
+ } else {
|
|
749
|
+ res.send(data);
|
|
750
|
+ }
|
|
751
|
+ }
|
|
752
|
+ }
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+ function getCustomerQrcode(req, res, next) {
|
|
756
|
+ var fullPath = settings.restful.url + 'crm' + settings.restful.version + '/customers/' + req.query.id + '/qrcode';
|
|
757
|
+ var options = {
|
|
758
|
+ 'service_catalog': '',
|
|
759
|
+ 'url': fullPath,
|
|
760
|
+ 'useUrl': true,
|
|
761
|
+ 'params': req.body,
|
|
762
|
+ 'callback': _cb,
|
|
763
|
+ 'req': req,
|
|
764
|
+ 'res': res,
|
|
765
|
+ 'options': {}
|
|
766
|
+ };
|
|
767
|
+ rest.get(options);
|
|
768
|
+ function _cb(data, response) {
|
|
769
|
+ if (data && data.url_path) {
|
|
770
|
+ res.redirect(301, data.url_path);
|
|
771
|
+ } else {
|
|
772
|
+ res.send(data);
|
|
773
|
+ }
|
|
774
|
+ }
|
|
775
|
+ }
|
|
776
|
+
|
|
777
|
+ function getPositionQrcode(req, res, next) {
|
|
778
|
+ var fullPath = settings.restful.url + 'recruit' + settings.restful.version + '/positions/' + req.query.id + '/qrcode';
|
|
779
|
+ var options = {
|
|
780
|
+ 'service_catalog': '',
|
|
781
|
+ 'url': fullPath,
|
|
782
|
+ 'useUrl': true,
|
|
783
|
+ 'params': req.body,
|
|
784
|
+ 'callback': _cb,
|
|
785
|
+ 'req': req,
|
|
786
|
+ 'res': res,
|
|
787
|
+ 'options': {}
|
|
788
|
+ };
|
|
789
|
+ rest.get(options);
|
|
790
|
+ function _cb(data, response) {
|
|
791
|
+ if (data && data.url_path) {
|
|
792
|
+ res.redirect(301, data.url_path);
|
|
793
|
+ } else {
|
|
794
|
+ res.send(data);
|
|
795
|
+ }
|
|
796
|
+ }
|
|
797
|
+ }
|
|
798
|
+
|
|
799
|
+ function getOSSConfig(req, res, next) {
|
|
800
|
+ var fullPath = settings.restful.url + 'filemeta' + settings.restful.version + '/config';
|
|
801
|
+ var options = {
|
|
802
|
+ 'service_catalog': '',
|
|
803
|
+ 'url': fullPath,
|
|
804
|
+ 'useUrl': true,
|
|
805
|
+ 'params': req.body,
|
|
806
|
+ 'callback': _cb,
|
|
807
|
+ 'req': req,
|
|
808
|
+ 'res': res,
|
|
809
|
+ 'options': {}
|
|
810
|
+ };
|
|
811
|
+ rest.get(options);
|
|
812
|
+ function _cb(data, response) {
|
|
813
|
+ if (data && data.bucket) {
|
|
814
|
+ req.session.passport.user.user_info.oss = data;
|
|
815
|
+ req.session.save(function (err) {
|
|
816
|
+ res.send({ "code": 200, "message": "oss配置加载成功" });
|
|
817
|
+ });
|
|
818
|
+ } else {
|
|
819
|
+ res.send({ "code": 200, "message": "oss配置加载失败" });
|
|
820
|
+ }
|
|
821
|
+ }
|
|
822
|
+ }
|
|
823
|
+
|
|
824
|
+ function weidianTempLate(req, res, next) {
|
|
825
|
+ const { params } = req;
|
|
826
|
+ var fullPath = settings.restful.url + 'socialwork/internal/minishop/' + params.id;
|
|
827
|
+ var options = {
|
|
828
|
+ 'service_catalog': '',
|
|
829
|
+ 'url': fullPath,
|
|
830
|
+ 'useUrl': true,
|
|
831
|
+ 'params': req.body,
|
|
832
|
+ 'callback': _cb,
|
|
833
|
+ 'req': req,
|
|
834
|
+ 'res': res,
|
|
835
|
+ 'options': {},
|
|
836
|
+ 'excludeToken': true,
|
|
837
|
+ };
|
|
838
|
+ rest.get(options);
|
|
839
|
+ function _cb(data, response) {
|
|
840
|
+ logger.debug("back data:", data);
|
|
841
|
+ if (response.statusCode < 300) {
|
|
842
|
+ const { shop_logo = [], shop_name = '', shop_comment = '' } = data;
|
|
843
|
+ let imgUrl = '';
|
|
844
|
+ if (shop_logo.length > 0) {
|
|
845
|
+ imgUrl = 'http://oss.workai.com.cn/public/' + shop_logo[0].object;
|
|
846
|
+ }
|
|
847
|
+ res.render('template/weiDian', {
|
|
848
|
+ imgUrl: imgUrl,
|
|
849
|
+ shop_name: shop_name,
|
|
850
|
+ shop_comment: shop_comment,
|
|
851
|
+ })
|
|
852
|
+ } else {
|
|
853
|
+ res.render('template/weiDian')
|
|
854
|
+ }
|
|
855
|
+ };
|
|
856
|
+
|
|
857
|
+ }
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+ function workaiSecurityOAuth(req, res, next) {
|
|
861
|
+ var params = req.query;
|
|
862
|
+ if (params.authorization_code) {
|
|
863
|
+ var passport = {
|
|
864
|
+ user: {
|
|
865
|
+ refreshToken: "",
|
|
866
|
+ token: "",
|
|
867
|
+ service_catalog: {},
|
|
868
|
+ user_info: {},
|
|
869
|
+ err: null
|
|
870
|
+ }
|
|
871
|
+ };
|
|
872
|
+ async.waterfall([
|
|
873
|
+ function (callback) {//第三方登录
|
|
874
|
+ var tempParams = {
|
|
875
|
+ "grant_type": 'authorization_code_v1',
|
|
876
|
+ "code": params.authorization_code
|
|
877
|
+ };
|
|
878
|
+ // var tempParams={
|
|
879
|
+ // "grant_type":"password",
|
|
880
|
+ // "username":"18510929499",
|
|
881
|
+ // "scope":"global_access:tenant_admin",
|
|
882
|
+ // "password":"a123456"
|
|
883
|
+ // };
|
|
884
|
+ logger.debug("Third login", settings.restful.url + 'uaa/v1/auth/tokens', tempParams);
|
|
885
|
+ rest.restful.postJson(settings.restful.url + 'uaa/v1/auth/tokens', tempParams, {
|
|
886
|
+ headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req)
|
|
887
|
+ })
|
|
888
|
+ .on('success', function (data, response) {
|
|
889
|
+ logger.debug("Third login json data:", data);
|
|
890
|
+ if (data.access_token) {
|
|
891
|
+ var scopes = data.scope.split(",");
|
|
892
|
+ passport.user.token = data.access_token;
|
|
893
|
+ passport.user.refreshToken = data.refresh_token;
|
|
894
|
+ passport.user.user_info = data.user || {};
|
|
895
|
+ passport.user.tenant_info = data.tenant;
|
|
896
|
+ passport.user.customer_info = data.customer;
|
|
897
|
+ passport.user.user_info.perms = data.perms;
|
|
898
|
+ passport.user.type = data.user.type;
|
|
899
|
+ passport.user.real_auth_status = data.user.real_auth_status;
|
|
900
|
+ passport.user.credential_status = data.user.credential_status;
|
|
901
|
+ passport.user.user_info.scope = scopes[0];
|
|
902
|
+ callback(null, data)
|
|
903
|
+ } else {
|
|
904
|
+ var err = new Error('Third login err');
|
|
905
|
+ passport.user.err = data.message;
|
|
906
|
+ callback(err, data);
|
|
907
|
+ }
|
|
908
|
+ rest.proxyLog(data,response,req,{headers:rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
909
|
+ }).on('error', function (err, response) {
|
|
910
|
+ logger.debug("Third login error", err);
|
|
911
|
+ var err = new Error('Third login err');
|
|
912
|
+ callback(err, response);
|
|
913
|
+ rest.proxyLog(err,response,req,{headers:rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
914
|
+ }).on('fail', function (data, response) {
|
|
915
|
+ logger.debug("Third login fail", data);
|
|
916
|
+ var err = new Error('Third login err');
|
|
917
|
+ callback(data, response);
|
|
918
|
+ rest.proxyLog(data,response,req,{headers:rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
919
|
+ });
|
|
920
|
+ }, function (data, callback) { //获取机构列表
|
|
921
|
+ var tempHead = {};
|
|
922
|
+ var ip = req.ip.match(/\d+\.\d+\.\d+\.\d+/)[0];
|
|
923
|
+ var user_agent = req.headers['user-agent'] || '';
|
|
924
|
+ tempHead['SXClientIP'] = ip;
|
|
925
|
+ tempHead['User-Agent'] = user_agent;
|
|
926
|
+ logger.debug("Third login tenants", settings.restful.url + 'uaa/v1/tenants?all=true', { accessToken: data.access_token, headers: tempHead });
|
|
927
|
+ rest.restful.get(settings.restful.url + 'uaa/v1/tenants?all=true', { accessToken: data.access_token, headers: rest.addHeaders(tempHead,req) })
|
|
928
|
+ .on('success', function (data1, response) {
|
|
929
|
+ logger.debug("Third login tenants list:", data1);
|
|
930
|
+ if (data1 && data1.items && data1.items.length > 0) {
|
|
931
|
+ callback(null, data1.items)
|
|
932
|
+ } else {
|
|
933
|
+ var err = new Error('Third login tenants list err');
|
|
934
|
+ passport.user.err = data.message;
|
|
935
|
+ callback(err, data);
|
|
936
|
+ }
|
|
937
|
+ rest.proxyLog(data1,response,req,{headers:rest.addHeaders(tempHead,req),'data':{},url:settings.restful.url + 'uaa/v1/tenants?all=true'})
|
|
938
|
+ }).on('error', function (err, response) {
|
|
939
|
+ var err = new Error('Third login tenants list err');
|
|
940
|
+ callback(err, response);
|
|
941
|
+ rest.proxyLog(err,response,req,{headers:rest.addHeaders(tempHead,req),'data':{},url:settings.restful.url + 'uaa/v1/tenants?all=true'})
|
|
942
|
+ }).on('fail', function (data, response) {
|
|
943
|
+ var err = new Error('Third login tenants list fail');
|
|
944
|
+ callback(data, response);
|
|
945
|
+ rest.proxyLog(data,response,req,{headers:rest.addHeaders(tempHead,req),'data':{},url:settings.restful.url + 'uaa/v1/tenants?all=true'})
|
|
946
|
+ });
|
|
947
|
+ }, function (data, callback) { //刷新token
|
|
948
|
+ if (data && data.length == 1) {
|
|
949
|
+ var params = {
|
|
950
|
+ grant_type: 'refresh_token',
|
|
951
|
+ scope: 'global_access:tenant_admin,tenant:' + data[0].id,
|
|
952
|
+ refresh_token: passport.user.refreshToken
|
|
953
|
+ }
|
|
954
|
+ passport.user.token = '';
|
|
955
|
+ logger.debug("Third login tokens", settings.restful.url + 'uaa/v1/auth/tokens', params);
|
|
956
|
+ rest.restful.postJson(settings.restful.url + 'uaa/v1/auth/tokens', params, {
|
|
957
|
+ headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req)
|
|
958
|
+ })
|
|
959
|
+ .on('success', function (data2, response) {
|
|
960
|
+ logger.debug("Third login json data2:", data2);
|
|
961
|
+ if (data2.access_token) {
|
|
962
|
+ var scopes = data2.scope.split(",");
|
|
963
|
+ passport.user.token = data2.access_token;
|
|
964
|
+ passport.user.refreshToken = data2.refresh_token;
|
|
965
|
+ passport.user.user_info = data2.user || {};
|
|
966
|
+ passport.user.tenant_info = data2.tenant;
|
|
967
|
+ passport.user.customer_info = data2.customer;
|
|
968
|
+ passport.user.user_info.perms = data2.perms;
|
|
969
|
+ passport.user.type = data2.user.type;
|
|
970
|
+ passport.user.real_auth_status = data2.user.real_auth_status;
|
|
971
|
+ passport.user.credential_status = data2.user.credential_status;
|
|
972
|
+ passport.user.user_info.scope = scopes[0];
|
|
973
|
+ passport.user.user_info.tenant = data2.tenant;
|
|
974
|
+ passport.user.user_info.user = {
|
|
975
|
+ credential_status: data2.credential_status,
|
|
976
|
+ id: data2.id,
|
|
977
|
+ is_root: data2.is_root,
|
|
978
|
+ mobile: data2.mobile,
|
|
979
|
+ name: data2.name,
|
|
980
|
+ real_auth_status: data2.real_auth_status,
|
|
981
|
+ status: data2.status,
|
|
982
|
+ type: data2.type,
|
|
983
|
+ wx_open_id: data2.wx_open_id
|
|
984
|
+ };
|
|
985
|
+ callback(null, data2)
|
|
986
|
+ } else {
|
|
987
|
+ var err = new Error('Third login err');
|
|
988
|
+ passport.user.err = data2.message;
|
|
989
|
+ callback(err, data2);
|
|
990
|
+ }
|
|
991
|
+ rest.proxyLog(data2,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':params,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
992
|
+ }).on('error', function (err, response) {
|
|
993
|
+ logger.debug("Third login error", err);
|
|
994
|
+ var err = new Error('Third login err');
|
|
995
|
+ callback(err, response);
|
|
996
|
+ rest.proxyLog(err,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':params,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
997
|
+ }).on('fail', function (data2, response) {
|
|
998
|
+ logger.debug("Third login fail", data2);
|
|
999
|
+ var err = new Error('Third login err');
|
|
1000
|
+ callback(data2, response);
|
|
1001
|
+ rest.proxyLog(data2,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':params,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
1002
|
+ });
|
|
1003
|
+ } else if (data && data.length > 1) {// #/login/choose-tenant
|
|
1004
|
+ callback(null, data)
|
|
1005
|
+ } else {
|
|
1006
|
+ var err = new Error('Third login tenants list item error');
|
|
1007
|
+ callback(err, data);
|
|
1008
|
+ }
|
|
1009
|
+ }], function (err, result) {
|
|
1010
|
+ if (err) {//登陆失败跳转失败页
|
|
1011
|
+ res.render('loginerr', { 'err': err });
|
|
1012
|
+ } else if (result instanceof Array && result.length > 1) {//登陆成功跳转选择机构页
|
|
1013
|
+ req.session.passport = passport;
|
|
1014
|
+ req.session.save(function (err) {
|
|
1015
|
+ res.redirect(301, settings.prefix + '#login/choose-tenant');
|
|
1016
|
+ });
|
|
1017
|
+ } else {
|
|
1018
|
+ req.session.passport = passport;
|
|
1019
|
+ req.session.save(function (err) {
|
|
1020
|
+ rest.get({
|
|
1021
|
+ 'baseUrl': 'url',
|
|
1022
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/perms/detail',
|
|
1023
|
+ 'useUrl': true,
|
|
1024
|
+ 'params': {},
|
|
1025
|
+ 'callback': _scb,
|
|
1026
|
+ 'req': req,
|
|
1027
|
+ 'res': res,
|
|
1028
|
+ 'options': {}
|
|
1029
|
+ });
|
|
1030
|
+ });
|
|
1031
|
+ function _scb(data1, response) {
|
|
1032
|
+ if (response.statusCode < 300 && data1.items) {
|
|
1033
|
+ req.session.passport.user.user_info.perms = data1.items;
|
|
1034
|
+ req.session.save(function (err) {
|
|
1035
|
+ if (params.redirect_page) {
|
|
1036
|
+ res.redirect(301, settings.prefix + '#' + params.redirect_page); //登陆成功跳转首页
|
|
1037
|
+ } else {
|
|
1038
|
+ res.redirect(301, settings.prefix + '#container/home'); //登陆成功跳转首页
|
|
1039
|
+ }
|
|
1040
|
+ })
|
|
1041
|
+ } else {
|
|
1042
|
+ if (params.redirect_page) {
|
|
1043
|
+ res.redirect(301, settings.prefix + '#' + params.redirect_page); //登陆成功跳转首页
|
|
1044
|
+ } else {
|
|
1045
|
+ res.redirect(301, settings.prefix + '#container/home'); //登陆成功跳转首页
|
|
1046
|
+ }
|
|
1047
|
+ }
|
|
1048
|
+ }
|
|
1049
|
+ }
|
|
1050
|
+ });
|
|
1051
|
+ }
|
|
1052
|
+
|
|
1053
|
+ }
|
|
1054
|
+
|
|
1055
|
+ function getTastLink(req, res, next) {
|
|
1056
|
+ var url = crypto.createHash('md5').update(req.body.id).digest('hex');
|
|
1057
|
+ if (settings.prefix && settings.prefix.length > 1) {
|
|
1058
|
+ res.send(req.protocol + '://' + req.get('host') + settings.prefix.substring(0, settings.prefix.length - 1) + "/socialwork/freedom-jobs/emps/" + req.body.id + "/" + url);
|
|
1059
|
+ } else {
|
|
1060
|
+ res.send({ 'url': req.protocol + '://' + req.get('host') + "/socialwork/freedom-jobs/emps/" + req.body.id + "/" + url });
|
|
1061
|
+ }
|
|
1062
|
+ }
|
|
1063
|
+
|
|
1064
|
+ function freedomJobsEmp(req, res, next) {
|
|
1065
|
+ var id = req.params.id;
|
|
1066
|
+ var verification = req.params.verification;
|
|
1067
|
+ // var url = crypto.createHash('md5').update(id).digest('hex');
|
|
1068
|
+ if (false) {//验证未通过verification != url
|
|
1069
|
+ if (settings.prefix && settings.prefix.length > 1) {
|
|
1070
|
+ res.redirect(settings.prefix.substring(0, settings.prefix.length - 1));
|
|
1071
|
+ } else {
|
|
1072
|
+ res.redirect('/');
|
|
1073
|
+ }
|
|
1074
|
+ } else {//验证通过跳转,获取token存到session里
|
|
1075
|
+ var passport = {
|
|
1076
|
+ user: {
|
|
1077
|
+ refreshToken: "",
|
|
1078
|
+ token: "",
|
|
1079
|
+ service_catalog: {},
|
|
1080
|
+ user_info: {},
|
|
1081
|
+ err: null
|
|
1082
|
+ }
|
|
1083
|
+ };
|
|
1084
|
+ var tempParams = {
|
|
1085
|
+ "grant_type": "client_credential",
|
|
1086
|
+ "client_id": "340161778618994688",//多宝鱼环境
|
|
1087
|
+ "client_secret": "0f8c30aa3d15332652f62c3eaf22fdea"
|
|
1088
|
+ };
|
|
1089
|
+ rest.restful.postJson(settings.restful.url + 'uaa/v1/auth/tokens', tempParams, {
|
|
1090
|
+ headers:rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req)
|
|
1091
|
+ }).on('success', function (data, response) {
|
|
1092
|
+ if (data.access_token) {
|
|
1093
|
+ var scopes = data.scope.split(",");
|
|
1094
|
+ passport.user.token = data.access_token;
|
|
1095
|
+ passport.user.refreshToken = data.refresh_token;
|
|
1096
|
+ passport.user.user_info = data.user;
|
|
1097
|
+ passport.user.tenant_info = data.tenant;
|
|
1098
|
+ passport.user.customer_info = data.customer;
|
|
1099
|
+ passport.user.user_info.perms = data.perms;
|
|
1100
|
+ passport.user.type = data.user.type;
|
|
1101
|
+ passport.user.real_auth_status = data.user.real_auth_status;
|
|
1102
|
+ passport.user.credential_status = data.user.credential_status;
|
|
1103
|
+ passport.user.user_info.scope = scopes[0];
|
|
1104
|
+ req.session.passport = passport;
|
|
1105
|
+ req.session.save(function (err) {
|
|
1106
|
+ if (settings.prefix && settings.prefix.length > 1) {
|
|
1107
|
+ res.redirect(301, settings.prefix.substring(0, settings.prefix.length - 1) + '/#task_assign/' + id);
|
|
1108
|
+ } else {
|
|
1109
|
+ res.redirect(301, '/#task_assign/' + id);
|
|
1110
|
+ }
|
|
1111
|
+ });
|
|
1112
|
+ } else {
|
|
1113
|
+ var err = new Error('Third login err');
|
|
1114
|
+ passport.user.err = data.message;
|
|
1115
|
+ }
|
|
1116
|
+ rest.proxyLog(data,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
1117
|
+ }).on('error', function (err, response) {
|
|
1118
|
+ logger.debug("Third login error", err);
|
|
1119
|
+ var err = new Error('Third login err');
|
|
1120
|
+ callback(err, response);
|
|
1121
|
+ rest.proxyLog(err,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
1122
|
+ }).on('fail', function (data, response) {
|
|
1123
|
+ logger.debug("Third login fail", data);
|
|
1124
|
+ var err = new Error('Third login err');
|
|
1125
|
+ rest.proxyLog(err,response,req,{headers: rest.addHeaders({ 'Content-Type': 'application/json', "Accept": "application/json" },req),'data':tempParams,url:settings.restful.url + 'uaa/v1/auth/tokens'})
|
|
1126
|
+ });
|
|
1127
|
+ }
|
|
1128
|
+
|
|
1129
|
+ }
|
|
1130
|
+
|
|
1131
|
+ function getShortToken(req, res, next) {
|
|
1132
|
+ var params = {
|
|
1133
|
+ grant_type: 'refresh_token',
|
|
1134
|
+ scope: req.session.passport.user.scope,
|
|
1135
|
+ refresh_token: req.session.passport.user.refreshToken
|
|
1136
|
+ }
|
|
1137
|
+ logger.debug("getShortToken:", params);
|
|
1138
|
+ rest.postJson({
|
|
1139
|
+ 'baseUrl': 'url',
|
|
1140
|
+ 'url': settings.restful.url + 'uaa' + settings.restful.version + '/auth/tokens',
|
|
1141
|
+ 'useUrl': true,
|
|
1142
|
+ 'params': params,
|
|
1143
|
+ 'callback': _cb,
|
|
1144
|
+ 'req': req,
|
|
1145
|
+ 'res': res,
|
|
1146
|
+ 'options': {},
|
|
1147
|
+ 'excludeToken': true
|
|
1148
|
+ })
|
|
1149
|
+ function _cb(data, response) {
|
|
1150
|
+ logger.debug("back data:", data);
|
|
1151
|
+ res.send({ "code": response.statusCode, "access_token": data.access_token });
|
|
1152
|
+ };
|
|
1153
|
+ }
|
|
1154
|
+
|
|
1155
|
+ function loadYxlyToken(req, res) {
|
|
1156
|
+ let hroToken = '';
|
|
1157
|
+ if (req.session.passport && req.session.passport.user && req.session.passport.user && req.session.passport.user.token) {
|
|
1158
|
+ hroToken = req.session.passport.user.token;
|
|
1159
|
+ }
|
|
1160
|
+ let params = {
|
|
1161
|
+ way: 'tenant',
|
|
1162
|
+ tenantToken: hroToken,
|
|
1163
|
+ };
|
|
1164
|
+
|
|
1165
|
+ rest.postJson({
|
|
1166
|
+ 'baseUrl': 'url',
|
|
1167
|
+ 'url': settings.excellentRestful.url + 'auth' + settings.excellentRestful.version + '/login',
|
|
1168
|
+ 'useUrl': true,
|
|
1169
|
+ 'params': params,
|
|
1170
|
+ 'callback': _cb,
|
|
1171
|
+ 'req': req,
|
|
1172
|
+ 'res': res,
|
|
1173
|
+ 'options': {},
|
|
1174
|
+ 'headers': {
|
|
1175
|
+ "Accept": "application/json",
|
|
1176
|
+ "Content-Type": "application/json",
|
|
1177
|
+ 'User-Agent': 'Request for Express',
|
|
1178
|
+ 'Authorization': 'Basic d29ya2FpOjEyMzQ1Ng=='
|
|
1179
|
+ },
|
|
1180
|
+ 'excludeToken': true
|
|
1181
|
+ });
|
|
1182
|
+
|
|
1183
|
+ function _cb(result, response) {
|
|
1184
|
+
|
|
1185
|
+ if (response.statusCode < 300 && result && result.data) {
|
|
1186
|
+ let key = `${req.session.passport.user.user_info.user.id}_yxly_token`;
|
|
1187
|
+ redis.set(key, result.data.access_token);
|
|
1188
|
+ logger.debug("loadYxlyToken......", key, result.data.access_token);
|
|
1189
|
+ } else {
|
|
1190
|
+ // res.send({ "code": 200, "message": "切换租户失败" });
|
|
1191
|
+ }
|
|
1192
|
+ }
|
|
1193
|
+ }
|
|
1194
|
+
|
|
1195
|
+ function redirectContract(req, res) {
|
|
1196
|
+ logger.warn("00000000000......",req.path);
|
|
1197
|
+ let deviceArray = ['android', 'Android', 'iPhone', 'windows phone'];
|
|
1198
|
+ let userAgent = req.headers['user-agent'];
|
|
1199
|
+ logger.warn("user-agent......", userAgent);
|
|
1200
|
+
|
|
1201
|
+ let isMobile = false;
|
|
1202
|
+ deviceArray.map((item, index) => {
|
|
1203
|
+ if (userAgent.indexOf(item) > 0) {
|
|
1204
|
+ isMobile = true;
|
|
1205
|
+ }
|
|
1206
|
+ })
|
|
1207
|
+
|
|
1208
|
+ logger.warn("isMobile......", isMobile);
|
|
1209
|
+ logger.warn("req.session......", req.session);
|
|
1210
|
+
|
|
1211
|
+ if (isMobile) {
|
|
1212
|
+ logger.warn("44444444......", settings.restful);
|
|
1213
|
+ logger.warn("req.query......", req.query);
|
|
1214
|
+
|
|
1215
|
+ return res.redirect(301, `${settings.restful.redirectMobileUrl}?state=contracts&code=${req.query.code}&scope=${req.query.scope}`);
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+ } else {
|
|
1219
|
+
|
|
1220
|
+ // return res.redirect(`/#/main/labor-contract/manage`);
|
|
1221
|
+ return res.redirect(`https://www.baidu.com`);
|
|
1222
|
+
|
|
1223
|
+ // logger.warn("req.session......", req.session);
|
|
1224
|
+ // if(req.session.passport && req.session.passport.user && req.session.passport.user.user_info && req.session.passport.user.user_info.user) {
|
|
1225
|
+ // logger.warn("11111111......");
|
|
1226
|
+ // return res.redirect(`/#/main/labor-contract/manage`);
|
|
1227
|
+ // } else {
|
|
1228
|
+ // logger.warn("22222222......");
|
|
1229
|
+ // return res.redirect(`/#/`);
|
|
1230
|
+ // }
|
|
1231
|
+ }
|
|
1232
|
+ }
|
|
1233
|
+
|
|
1234
|
+ return {
|
|
1235
|
+ refreshToken:refreshToken,
|
|
1236
|
+ index: index,
|
|
1237
|
+ indexPrefix,
|
|
1238
|
+ register: register,
|
|
1239
|
+ signIn: signIn,
|
|
1240
|
+ doLogin: doLogin,
|
|
1241
|
+ signOut: signOut,
|
|
1242
|
+ smsCodes: smsCodes,
|
|
1243
|
+ tenants: tenants,
|
|
1244
|
+ productDes: productDes,
|
|
1245
|
+ resetPass: resetPass,
|
|
1246
|
+ updatePassword: updatePassword,
|
|
1247
|
+ loadUserInfo: loadUserInfo,
|
|
1248
|
+ getUploaderToken: getUploaderToken,
|
|
1249
|
+ getObjectTokenByID,
|
|
1250
|
+ delOSSObject: delOSSObject,
|
|
1251
|
+ healthMonitor,
|
|
1252
|
+ smsVerification,
|
|
1253
|
+ updateUserRoles,
|
|
1254
|
+ getRoles,
|
|
1255
|
+ getUserRoles,
|
|
1256
|
+ getTenant,
|
|
1257
|
+ updateTenant,
|
|
1258
|
+ offer,
|
|
1259
|
+ onboardStatus,
|
|
1260
|
+ dowloadApp,
|
|
1261
|
+ mobileRegister,
|
|
1262
|
+ mobileRegisterSuccess,
|
|
1263
|
+ softwareLicense,
|
|
1264
|
+ recharge,
|
|
1265
|
+ changePassForRegister,
|
|
1266
|
+ changeTenant,
|
|
1267
|
+ sendRejectOffer,
|
|
1268
|
+ acceptOffer,
|
|
1269
|
+ imTokens,
|
|
1270
|
+ listChannels,
|
|
1271
|
+ filemeta,
|
|
1272
|
+ getCustomerQrcode,
|
|
1273
|
+ getPositionQrcode,
|
|
1274
|
+ getOSSConfig,
|
|
1275
|
+ weidianTempLate,
|
|
1276
|
+ workaiSecurityOAuth,
|
|
1277
|
+ getTastLink,
|
|
1278
|
+ freedomJobsEmp,
|
|
1279
|
+ getShortToken,
|
|
1280
|
+ loadYxlyToken,
|
|
1281
|
+ redirectContract,
|
|
1282
|
+ };
|
1236
|
1283
|
};
|
1237
|
1284
|
|
1238
|
|
-exports["@singleton"] = true;
|
1239
|
|
-exports["@require"] = ["igloo/logger", "utils/rest", "igloo/settings"]; |
|
1285
|
+exports['@singleton'] = true;
|
|
1286
|
+exports['@require'] = ['igloo/logger', 'utils/rest', 'utils/redis', 'igloo/settings']; |
...
|
...
|
|