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