Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Application
- router.post("/authApp", (req, res) => {
- let macAddress = (req.body.macAddress);
- let code = (req.body.code);
- try {
- getAccessTokenApp(code, macAddress, res);
- return;
- } catch (error) {
- res.json({error: "error"})
- }
- });
- function getAccessTokenApp(code, macAddress, res) {
- //Getting Access Token
- const redirect = encodeURIComponent('https://botbuddy.xyz/dashboard');
- var options = {
- method: 'POST',
- url: `https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`,
- headers: {
- Authorization: `Basic ${creds}`,
- }
- };
- request(options, function(error, response, body, res) {
- if (error) throw new Error(error);
- var jsonObject = JSON.parse(body);
- let accessToken = (jsonObject["access_token"]);
- //Get user Data
- getUser(accessToken, macAddress, res);
- return;
- });
- }
- //This function gets the users Discord data
- function getUserApp(accessToken, macAddress, res) {
- request({
- url: "https://discordapp.com/api/users/@me",
- headers: {
- Authorization: `Bearer ${accessToken}`,
- }
- },
- function(error, response, body) {
- if (error) throw new Error(error);
- var jsonObject = JSON.parse(body);
- let userId = jsonObject["id"];
- let avatar = `https://cdn.discordapp.com/avatars/${userId}/${jsonObject["avatar"]}.png`;
- let username = `${jsonObject["username"]}#${jsonObject["discriminator"]}`;
- //Checking if the user is in the database or not!
- findId(userId, username, avatar, macAddress, res);
- return;
- }
- );
- }
- function findIdApp(userId, username, avatar, macAddress, res) {
- //console.log(userId)
- let apiKey = "w1wA_FNu_Mc38FwuaD4ucVJN4gxeqFy_";
- request.get({
- headers: {
- 'content-type': 'application/json'
- },
- url: `https://api.mlab.com/api/1/databases/heroku_mv21lspx/collections/lifetime/?f={"_id": 0}&apiKey=${apiKey}`,
- }, function(error, response, body) {
- if (error) throw new Error(error);
- let data = JSON.parse(body);
- var hasKey = false;
- var key;
- var mac;
- for (var i = 0; i < data.length; i++) {
- let doc = data[i];
- let discord = doc.discord;
- if (discord == userId) {
- hasKey = true;
- key = doc.key;
- mac = doc.mac;
- break;
- }
- }
- if (hasKey == true) {
- if (mac == macAddress || mac == "") {
- //return the users data encrypted and save it into the file
- res.json({
- activated: true,
- key: key,
- username: username,
- id: userId,
- avatar: avatar,
- });
- } else {
- //another device is active
- res.json({
- activated: false,
- error: "Active on Another Device"
- });
- }
- } else {
- //return message that user needs to bind key to a Discord account
- res.json({
- activated: false,
- error: "Account has no Key Binded"
- });
- }
- return;
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement