Advertisement
devlargss

Untitled

Jul 11th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. var nodemailer = require('nodemailer');
  2. var smtpTransport = require('nodemailer-smtp-transport');
  3. var crypto = require('crypto');
  4. <<<<<<< HEAD
  5. var basicAuth = require('basic-auth');
  6. var os = require('os');
  7. =======
  8. var xml2js = require('xml2js');
  9. >>>>>>> user-access
  10.  
  11. var environment = exports.environment = process.env.NODE_ENV;
  12. var apiEmailAddress = exports.apiEmailAddress = 'no-reply@volenday.com';
  13. var apiPassword = exports.apiPassword = 'GsvHkpwjhDp&XH^=&qTgk7FYE9C#j&E*qA%q68w-KuVrf&K?$NPwg2&c-eDSq9c#a*zFyn4_f_s4yRE#@&racYBnj-_hExdGxySVg7Tf5qJB*-ZWVH^Mua8Nrq?sbE?b';
  14. var applicationId = exports.applicationId = '523ba9e0-b5c7-11e6-9337-f9d3629af5c1';
  15.  
  16. if (environment == "development") {
  17. var siteUrl = exports.siteUrl = 'http://localhost:8003/';
  18. var adminUrl = exports.adminUrl = 'http://admin.localhost:8003/';
  19. var apiUrl = exports.apiUrl = "http://localhost:3501/";
  20. var facebookAppId = exports.facebookAppId = "1302274103141628";
  21. }
  22.  
  23. if (environment == "staging") {
  24. var siteUrl = exports.siteUrl = 'http://test.asia-ceo-awards.volenday.com/';
  25. var adminUrl = exports.adminUrl = 'http://test.admin.asia-ceo-awards.volenday.com/';
  26. var apiUrl = exports.apiUrl = "http://test.api.aha.volenday.com/";
  27. var facebookAppId = exports.facebookAppId = "1302274103141628";
  28. }
  29.  
  30. if (environment == "production") {
  31. var siteUrl = exports.siteUrl = 'http://www.asia-ceo-awards.org/';
  32. var adminUrl = exports.adminUrl = 'http://admin.asia-ceo-awards.org/';
  33. var apiUrl = exports.apiUrl = "https://api.aha.volenday.com/";
  34. var facebookAppId = exports.facebookAppId = "1302271043141934";
  35. }
  36.  
  37. var imageUrl = exports.imageUrl = "http://images.aha.volenday.com/" + environment + "/applications/" + applicationId + "/";
  38.  
  39. var mailerEmail = exports.mailerEmail = 'no-reply@volenday.com';
  40. var mailerPassword = exports.mailerPassword = 'sYst3mAdm1n';
  41.  
  42. var transporter = exports.transporter = nodemailer.createTransport({
  43. service: "Gmail",
  44. auth: {
  45. type: 'OAuth2',
  46. user: mailerEmail,
  47. clientId: "763594980831-n5nse8pgcsh2c7ugpfb5hs2gdp1clemh.apps.googleusercontent.com",
  48. clientSecret: "Br-0KPmNKMxJs3A6_LZq6B4K",
  49. refreshToken: "1/a0ZIGVipe8QPfMQNIwdr3CzhbaC6OO5m1sV-2WN_GqE"
  50. }
  51. });
  52.  
  53. var generateXmlSignature = exports.generateXmlSignature = function (data, params) {
  54. var orderId = data.OrderId;
  55. var callbackUrl = siteUrl + 'registrations/callback';
  56. var responseUrl = siteUrl + 'registrations/response';
  57. var amount = data.TicketsCount * data.Events.RegistrationFee;
  58. var currency = 'PHP';
  59. var pageTimeout = '780';
  60.  
  61. <<<<<<< HEAD
  62. var forSignature = params.MerchantPassword + params.MerchantServiceID + orderId + responseUrl + callbackUrl +
  63. + amount + '.00' + currency + params.ip + pageTimeout;
  64. var signature = crypto.createHash('sha256').update(forSignature).digest("hex");
  65. return signature.toUpperCase();
  66. };
  67.  
  68. var authUser = exports.authUser = 'admin';
  69. var authPassword = exports.authPassword = 'jEhU56nM6dJ3u6Fk';
  70.  
  71. var auth = exports.auth = function (req, res, next) {
  72. function unauthorized(res) {
  73. res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
  74. return res.sendStatus(401);
  75. };
  76.  
  77. var user = basicAuth(req);
  78. if (!user || !user.name || !user.pass) {
  79. return unauthorized(res);
  80. };
  81.  
  82. if (user.name === authUser && user.pass === authPassword) {
  83. return next();
  84. } else {
  85. return unauthorized(res);
  86. };
  87. };
  88.  
  89. var getIP = exports.getIP = function () {
  90. var interfaces = os.networkInterfaces();
  91. var addresses = [];
  92. for (var k in interfaces) {
  93. for (var k2 in interfaces[k]) {
  94. var address = interfaces[k][k2];
  95. if (address.family === 'IPv4' && !address.internal) {
  96. addresses.push(address.address);
  97. }
  98. }
  99. }
  100.  
  101. return addresses[0];
  102. }
  103. =======
  104. return new Buffer(strxml).toString('base64');
  105. };
  106.  
  107. var verifySignature = exports.verifySignature = function (data, callback) {
  108. var response = data.split(' ').join('+');
  109. response = new Buffer(response, 'base64').toString("ascii");
  110.  
  111. xml2js.parseString(response, function (err, result) {
  112. var application = result.ServiceResponseWPF.application[0],
  113. responseStatus = result.ServiceResponseWPF.responseStatus[0];
  114.  
  115. var forSignature = application.merchantid[0] + application.request_id[0] + application.response_id[0] +
  116. responseStatus.response_code[0] + responseStatus.response_message[0] + responseStatus.response_advise[0] +
  117. application.timestamp[0] + application.rebill_id[0];
  118. var signature = crypto.createHash('sha512').update(forSignature + merchantKey).digest("hex");
  119.  
  120. if (signature == application.signature[0]) {
  121. if (responseStatus.response_code == "GR001" || responseStatus.response_code == "GR002") {
  122. callback('Successful', application.request_id[0], application.response_id[0]);
  123. } else if (responseStatus.response_code == "GR028" || responseStatus.response_code == "GR029" || responseStatus.response_code == "GR053") {
  124. callback('Cancelled', application.request_id[0], application.response_id[0]);
  125. } else {
  126. callback('Failed', application.request_id[0], application.response_id[0]);
  127. }
  128. } else {
  129. callback('Failed', application.request_id[0], application.response_id[0]);
  130. }
  131. });
  132. };
  133. >>>>>>> user-access
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement