Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. //Application
  2. router.post("/authApp", (req, res) => {
  3. let macAddress = (req.body.macAddress);
  4. let code = (req.body.code);
  5. try {
  6. getAccessTokenApp(code, macAddress, res);
  7. return;
  8. } catch (error) {
  9. res.json({error: "error"})
  10. }
  11.  
  12. });
  13.  
  14. function getAccessTokenApp(code, macAddress, res) {
  15. //Getting Access Token
  16. const redirect = encodeURIComponent('https://botbuddy.xyz/dashboard');
  17. var options = {
  18. method: 'POST',
  19. url: `https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`,
  20. headers: {
  21. Authorization: `Basic ${creds}`,
  22. }
  23. };
  24.  
  25. request(options, function(error, response, body, res) {
  26. if (error) throw new Error(error);
  27. var jsonObject = JSON.parse(body);
  28. let accessToken = (jsonObject["access_token"]);
  29. //Get user Data
  30. getUser(accessToken, macAddress, res);
  31. return;
  32. });
  33. }
  34.  
  35. //This function gets the users Discord data
  36. function getUserApp(accessToken, macAddress, res) {
  37. request({
  38. url: "https://discordapp.com/api/users/@me",
  39. headers: {
  40. Authorization: `Bearer ${accessToken}`,
  41. }
  42. },
  43. function(error, response, body) {
  44. if (error) throw new Error(error);
  45. var jsonObject = JSON.parse(body);
  46. let userId = jsonObject["id"];
  47. let avatar = `https://cdn.discordapp.com/avatars/${userId}/${jsonObject["avatar"]}.png`;
  48. let username = `${jsonObject["username"]}#${jsonObject["discriminator"]}`;
  49. //Checking if the user is in the database or not!
  50. findId(userId, username, avatar, macAddress, res);
  51. return;
  52. }
  53. );
  54. }
  55.  
  56.  
  57. function findIdApp(userId, username, avatar, macAddress, res) {
  58. //console.log(userId)
  59. let apiKey = "w1wA_FNu_Mc38FwuaD4ucVJN4gxeqFy_";
  60. request.get({
  61. headers: {
  62. 'content-type': 'application/json'
  63. },
  64. url: `https://api.mlab.com/api/1/databases/heroku_mv21lspx/collections/lifetime/?f={"_id": 0}&apiKey=${apiKey}`,
  65. }, function(error, response, body) {
  66. if (error) throw new Error(error);
  67. let data = JSON.parse(body);
  68. var hasKey = false;
  69. var key;
  70. var mac;
  71. for (var i = 0; i < data.length; i++) {
  72. let doc = data[i];
  73. let discord = doc.discord;
  74. if (discord == userId) {
  75. hasKey = true;
  76. key = doc.key;
  77. mac = doc.mac;
  78. break;
  79. }
  80. }
  81. if (hasKey == true) {
  82. if (mac == macAddress || mac == "") {
  83. //return the users data encrypted and save it into the file
  84. res.json({
  85. activated: true,
  86. key: key,
  87. username: username,
  88. id: userId,
  89. avatar: avatar,
  90. });
  91. } else {
  92. //another device is active
  93. res.json({
  94. activated: false,
  95. error: "Active on Another Device"
  96. });
  97. }
  98.  
  99. } else {
  100. //return message that user needs to bind key to a Discord account
  101. res.json({
  102. activated: false,
  103. error: "Account has no Key Binded"
  104. });
  105. }
  106. return;
  107. })
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement