Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed Oct 27, 2024
1 parent 0249490 commit 31093a2
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 392 deletions.
60 changes: 52 additions & 8 deletions Discord/discordRoutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const router = express.Router();

require('dotenv').config()
const stripe = require('stripe')(require('../config/web-config').stripe);
const Discord = require("discord.js");
const db = require('../Firebase/models')
Expand All @@ -13,6 +13,7 @@ const { default: axios } = require("axios");
const client = new Discord.Client({ intents: botConfig.intents })
client.login(botConfig.discordToken)


router.get('/auth/verify/:acesstoken', async (req, res) => {
let param = req.params.acesstoken
if (param) {
Expand Down Expand Up @@ -41,7 +42,50 @@ router.get('/auth/verify/:acesstoken', async (req, res) => {
}
})

router.get('/discord/verify', async (req, res) => {
try {
if (!req.query.code) {
res.redirect('/?error=Codigo invalido')
} else {
let param = new URLSearchParams({
client_id: webConfig.clientId,
client_secret: webConfig.secret,
grant_type: 'authorization_code',
code: req.query.code,
redirect_uri: process.env.DISCORDURI
})
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'application/x-www-form-urlencoded'
};
const response = await axios.post('https://discord.com/api/oauth2/token', param, { headers }).then((res) => { return res }).catch((err) => {
console.error(err)
})
if (!response) {
res.redirect('/?error=Erro ao autenticar')
return
}
let userResponse = await axios.get('https://discord.com/api/users/@me', {
headers: {
Authorization: `Bearer ${response.data.access_token}`,
...headers
}
}).then((res) => { return res.data }).catch((err) => {
console.error(err)
});



const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;


}
} catch (error) {
res.redirect('/logout')
console.log(error);

}
})

router.get('/auth/callback', async (req, res) => {
try {
Expand Down Expand Up @@ -86,7 +130,7 @@ router.get('/auth/callback', async (req, res) => {
let loginsOpen = 'loginsOpen' in user ? user.loginsOpen : {}
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
let userLoginAccept = 'usersLoginAccept' in user ? true : false
let findLogin = Object.values(loginsOpen).find(element=>element.ip == ip)
let findLogin = Object.values(loginsOpen).find(element => element.ip == ip)
if ('usersLoginAccept' in user && user.usersLoginBlock.includes(ip)) {
res.redirect('/logout?error=Seu acesso a essa conta foi bloqueado!')
return
Expand Down Expand Up @@ -231,10 +275,10 @@ router.get('/auth/callback', async (req, res) => {
ip: ip ? ip : null,
sessao: req.session.id ? req.session.id : null,
pais: data.country ? data.country : null,
estado: data.region ? data.region : null,
estado: data.region ? data.region : null,
cidade: data.city ? data.city : null,
os: os,
postal: data.postal ? data.postal :null,
postal: data.postal ? data.postal : null,
navegador: browser,
date: dataFormatada,
token: req.cookies.token ? req.cookies.token : null,
Expand All @@ -261,11 +305,11 @@ router.get('/auth/callback', async (req, res) => {
displayName: userResponse.global_name,
email: userResponse.email,
access_token: response.data.access_token,
usersLoginAccept:[ip],
usersLoginBlock:[]
usersLoginAccept: [ip],
usersLoginBlock: []
})
}

res.redirect('/dashboard')
}
}
Expand All @@ -279,7 +323,7 @@ router.get('/auth/callback', async (req, res) => {



router.get('/addbot/:serverID',functions.authGetState, (req, res) => {
router.get('/addbot/:serverID', functions.authGetState, (req, res) => {
if (!req.params.serverID) {
res.redirect(`/`)
return
Expand Down
43 changes: 43 additions & 0 deletions Discord/handler/commands/pullAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// let functions = require('../../../functions')
// const Discord = require("discord.js");
// let db = require('../../../Firebase/models');
// const { SlashCommandBuilder } = require('discord.js');

// const botConfig = require('../../../config/bot-config.js');
// const webConfig = require('../../../config/web-config.js');


// module.exports = {
// data: new SlashCommandBuilder()
// .setName('puxarAll')
// .setDescription('Puxa os usuarios verificados do AUTH!'),
// async execute(interaction,client) {
// // let verifyPermissions = await functions.verifyPermissions(interaction.user.id, interaction.guildId, null, client)
// // if (verifyPermissions.error == false && verifyPermissions.perms.commands == true) {
// let serverData = await db.findOne({ colecao: `servers`, doc: await interaction.guildId })


// interaction.reply({
// embeds: [
// new Discord.EmbedBuilder()
// .setColor("#6E58C7")
// .setTitle(`Configure o bot atraves da nossa plataforma acessando o link abaixo!`)
// ],
// components: [
// new Discord.ActionRowBuilder()
// .addComponents(
// new Discord.ButtonBuilder()
// .setStyle(5)
// .setLabel('Verificar')
// .setURL(`https://discord.com/oauth2/authorize?client_id=1272947467469459456&response_type=code&redirect_uri=https%3A%2F%2Fgame-violently-kitten.ngrok-free.app%2Fdiscord%2Fverify&scope=identify+guilds.join`)
// )
// ],
// ephemeral: true
// })
// // } else {
// // interaction.reply('Você não tem permissão para enviar comandos')
// // }
// }
// };


43 changes: 43 additions & 0 deletions Discord/handler/commands/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// let functions = require('../../../functions')
// const Discord = require("discord.js");
// let db = require('../../../Firebase/models');
// const { SlashCommandBuilder } = require('discord.js');

// const botConfig = require('../../../config/bot-config.js');
// const webConfig = require('../../../config/web-config.js');


// module.exports = {
// data: new SlashCommandBuilder()
// .setName('verify')
// .setDescription('Envie a mensagem de verificação do AUTH!'),
// async execute(interaction,client) {
// // let verifyPermissions = await functions.verifyPermissions(interaction.user.id, interaction.guildId, null, client)
// // if (verifyPermissions.error == false && verifyPermissions.perms.commands == true) {
// let serverData = await db.findOne({ colecao: `servers`, doc: await interaction.guildId })


// interaction.reply({
// embeds: [
// new Discord.EmbedBuilder()
// .setColor("#6E58C7")
// .setTitle(`Configure o bot atraves da nossa plataforma acessando o link abaixo!`)
// ],
// components: [
// new Discord.ActionRowBuilder()
// .addComponents(
// new Discord.ButtonBuilder()
// .setStyle(5)
// .setLabel('Verificar')
// .setURL(`https://discord.com/oauth2/authorize?client_id=1272947467469459456&response_type=code&redirect_uri=https%3A%2F%2Fgame-violently-kitten.ngrok-free.app%2Fdiscord%2Fverify&scope=identify+guilds.join`)
// )
// ],
// ephemeral: true
// })
// // } else {
// // interaction.reply('Você não tem permissão para enviar comandos')
// // }
// }
// };


13 changes: 1 addition & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,7 @@ app.get('/payment/:id', async (req, res) => {
if ('pass' in user == true) {
delete user.security
}
let server = await db.findOne({ colecao: 'servers', doc: req.params.id })
let exist = false
let type = null
if (server.error == false) {
exist = true
type = server.type
if (server.isPaymented == true) {
res.redirect('/dashboard')
return
}
}
res.render('payment', { host: `${webConfig.host}`, user: user, server: server, exist: exist, type: type })
res.render('payment', { host: `${webConfig.host}`, user: user})
})

app.get('/server/:id', functions.authGetState, functions.subscriptionStatus, async (req, res) => {
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"discord-html-transcripts": "^3.2.0",
"discord-oauth2": "^2.12.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.9",
"express": "^4.18.2",
Expand Down
4 changes: 2 additions & 2 deletions public/css/reusable/styleRoot.css
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ input[type=radio]:checked ~ .label-radius {

.dropdown {
width: 100%;
z-index: 9;

position: relative;
font-family: 'poppins', sans-serif;
font-weight: 300;
Expand Down Expand Up @@ -536,7 +536,7 @@ input[type=radio]:checked ~ .label-radius {
position: absolute;
top: 100%;
left: 0;
z-index: 9999999999999999;
z-index: 999;
width: 100%;
margin-top: 5px;
overflow-y: auto;
Expand Down
Loading

0 comments on commit 31093a2

Please sign in to comment.