提交 a0b71f68bce43f1bfc210dc974ef7c4a9768a142

作者 weiyy
1 个父辈 67589100

yun - tijiao

  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 + };
  1236 +};
  1237 +
  1238 +exports["@singleton"] = true;
  1239 +exports["@require"] = ["igloo/logger", "utils/rest", "igloo/settings"];
... ...
... ... @@ -119,7 +119,6 @@ class ProxyController extends Controller {
119 119 return ctx.body;
120 120 }
121 121
122   -
123 122 async post() {
124 123 const { ctx, config, logger } = this;
125 124 const { originalUrl, session, curl, request } = ctx;
... ...
... ... @@ -6,8 +6,8 @@ module.exports = app => {
6 6
7 7 // 给proxy设置token
8 8 router.get(/^\/api\/[\w/]+/, 'proxy.get');
9   - // router.post(/^\/api\/[\w/]+/, 'proxy.post');
10   - // router.put(/^\/api\/[\w/]+/, 'proxy.put');
11   - // router.head(/^\/api\/[\w/]+/, 'proxy.head');
12   - // router.delete(/^\/api\/[\w/]+/, 'proxy.del');
  9 + router.post(/^\/api\/[\w/]+/, 'proxy.post');
  10 + router.put(/^\/api\/[\w/]+/, 'proxy.put');
  11 + router.head(/^\/api\/[\w/]+/, 'proxy.head');
  12 + router.delete(/^\/api\/[\w/]+/, 'proxy.del');
13 13 }
\ No newline at end of file
... ...
  1 +var express = require("express");
  2 +var payRoll = require("../json/payRoll.json");
  3 +
  4 +exports = module.exports = function (IoC, policies, settings) {
  5 + var app = this;
  6 + var router = express.Router();
  7 + var router2 = express.Router();
  8 + var controller = IoC.create("controllers/auth");
  9 +
  10 + if (settings.prefix.length > 0) {
  11 + // router.get("/index", controller.index);
  12 + router.get("/signOut", controller.signOut);
  13 + }
  14 +
  15 + router.get("/img/*", controller.getImg);
  16 +
  17 + router2.get("/", controller.indexPrefix);
  18 +
  19 + router.get("/productDes", controller.productDes);
  20 +
  21 + router.get("/register", controller.register);
  22 +
  23 + router.get("/mobileRegister", controller.mobileRegister);
  24 +
  25 + router.get("/mobileRegisterSuccess", controller.mobileRegisterSuccess);
  26 +
  27 + router.get("/signIn", controller.signIn);
  28 +
  29 + router.post("/doLogin", controller.doLogin);
  30 +
  31 + router2.get("/signOut", controller.signOut);
  32 +
  33 + router.post("/smsCodes", controller.smsCodes);
  34 +
  35 + router.post("/tenants", controller.tenants);
  36 +
  37 + router.post("/resetPass", policies.ensureLoggedOut(), controller.resetPass);
  38 +
  39 + router.post(
  40 + "/updatePassword",
  41 + policies.ensureLoggedOut(),
  42 + controller.updatePassword
  43 + );
  44 +
  45 + router.post(
  46 + "/loadUserInfo",
  47 + policies.ensureLoggedOut(),
  48 + controller.loadUserInfo
  49 + );
  50 +
  51 + router.post(
  52 + "/getUploaderToken",
  53 + policies.ensureLoggedOut(),
  54 + controller.getUploaderToken
  55 + );
  56 +
  57 + router.post(
  58 + "/delOSSObject",
  59 + policies.ensureLoggedOut(),
  60 + controller.delOSSObject
  61 + );
  62 +
  63 + router.post("/smsVerification", controller.smsVerification);
  64 +
  65 + router.post("/getObjectTokenByID", controller.getObjectTokenByID);
  66 +
  67 + // router.get(
  68 + // '/healthMonitor',
  69 + // controller.healthMonitor
  70 + // )
  71 +
  72 + // router.head(
  73 + // '/healthMonitor',
  74 + // controller.healthMonitor
  75 + // )
  76 +
  77 + router.post(
  78 + "/getUserRoles",
  79 + policies.ensureLoggedOut(),
  80 + controller.getUserRoles
  81 + );
  82 +
  83 + router.post("/getRoles", policies.ensureLoggedOut(), controller.getRoles);
  84 +
  85 + router.post(
  86 + "/updateUserRoles",
  87 + policies.ensureLoggedOut(),
  88 + controller.updateUserRoles
  89 + );
  90 +
  91 + router.post("/getTenant", policies.ensureLoggedOut(), controller.getTenant);
  92 +
  93 + router.post(
  94 + "/updateTenant",
  95 + policies.ensureLoggedOut(),
  96 + controller.updateTenant
  97 + );
  98 +
  99 + router.get("/offer/:requestId", controller.offer);
  100 +
  101 + router.post(
  102 + "/onboardStatus",
  103 + policies.ensureLoggedOut(),
  104 + controller.onboardStatus
  105 + );
  106 +
  107 + router.get("/downloadApp", controller.dowloadApp);
  108 +
  109 + router.get("/info/policy", controller.softwareLicense);
  110 +
  111 + router.get("/payRoll", function (req, res, next) {
  112 + res.send(payRoll);
  113 + });
  114 +
  115 + router.get("/recharge", controller.recharge);
  116 +
  117 + router.post("/changePassForRegister", controller.changePassForRegister);
  118 +
  119 + router.post(
  120 + "/changeTenant",
  121 + policies.ensureLoggedOut(),
  122 + controller.changeTenant
  123 + );
  124 +
  125 + router.post("/hr/sendRejectOffer", controller.sendRejectOffer);
  126 +
  127 + router.post("/hr/acceptOffer", controller.acceptOffer);
  128 +
  129 + router.post("/imTokens", policies.ensureLoggedOut(), controller.imTokens);
  130 +
  131 + router.post(
  132 + "/listChannels",
  133 + policies.ensureLoggedOut(),
  134 + controller.listChannels
  135 + );
  136 +
  137 + router.post(
  138 + "/getTastLink",
  139 + policies.ensureLoggedOut(),
  140 + controller.getTastLink
  141 + );
  142 +
  143 + router.get("/filemeta", policies.ensureLoggedOut(), controller.filemeta);
  144 +
  145 + router.get(
  146 + "/getCustomerQrcode",
  147 + policies.ensureLoggedOut(),
  148 + controller.getCustomerQrcode
  149 + );
  150 +
  151 + router.get(
  152 + "/getPositionQrcode",
  153 + policies.ensureLoggedOut(),
  154 + controller.getPositionQrcode
  155 + );
  156 + router.get(
  157 + //微店模板路由
  158 + "/minishop/:id",
  159 + controller.weidianTempLate
  160 + );
  161 +
  162 + router.get("/wso-workai", controller.workaiSecurityOAuth);
  163 +
  164 + router.get(
  165 + "/socialwork/freedom-jobs/emps/:id/:verification",
  166 + controller.freedomJobsEmp
  167 + );
  168 +
  169 + router.get("/socialwork/freedom-jobs/emps/:id", controller.freedomJobsEmp);
  170 +
  171 + router.get("/getShortToken", controller.getShortToken);
  172 +
  173 + router.get("/gainianrenli/*",controller.getImg)
  174 + router.get("/waifu_img/*",controller.getImg)
  175 + router.get("/my_img/*",controller.getImg)
  176 + router.get("/invoice_file_icon/*",controller.getImg)
  177 + router.get("/gainianrenli/*",controller.getImg)
  178 + router.get("/claim_icons/*",controller.getImg)
  179 +
  180 + app.use("/", router);
  181 +
  182 + app.use("/index", router2);
  183 +};
  184 +
  185 +exports["@require"] = ["$container", "policies", "igloo/settings"];
  186 +exports["@singleton"] = true;
... ...
注册登录 后发表评论