Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed Apr 27, 2024
1 parent 61d9ea0 commit 9ac5273
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 25 deletions.
3 changes: 2 additions & 1 deletion config/web-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
host:process.env.HOST,
product1: require('./product.json').product1,
product2:require('./product.json').product2,
product3:require('./product.json').product3
product3:require('./product.json').product3,
loginURL: 'https://discord.com/oauth2/authorize?client_id=1210894508028338197&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Fauth%2Fcallback&scope=identify+guilds+email+guilds.join'
}
77 changes: 61 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,36 @@ app.get('/dashboard', async (req, res) => {
if (req.session.uid) {
let user = await db.findOne({ colecao: 'users', doc: req.session.uid })
let server = await functions.reqServerByTime(user, functions.findServers)
if (server.error) {
res.redirect('/')
return
}
let servidoresEnd = []
for (let i = 0; i < server.length; i++) {
let element = server[i]

let Findserver = await db.findOne({ colecao: 'servers', doc: element.id })
if (Findserver.error == false) {
servidoresEnd.push(Findserver)
} else {
servidoresEnd.push(element)
if (server.error) {
if (user.lastServers) {
for (let index = 0; index < user.lastServers.length; index++) {
const element = user.lastServers[index];
let Findserver = await db.findOne({ colecao: 'servers', doc: element })
if (Findserver.error == false) {
servidoresEnd.push(Findserver)
}
}
}else{
res.redirect('/')
}
}else{
let lastServers = []
for (let i = 0; i < server.length; i++) {
let element = server[i]

let Findserver = await db.findOne({ colecao: 'servers', doc: element.id })
if (Findserver.error == false) {
servidoresEnd.push(Findserver)
lastServers.push(Findserver.id)
} else {
servidoresEnd.push(element)
}

}
db.update('users',user.id,{
lastServers:lastServers
})
}
res.render('dashboard', { host: `${webConfig.host}`, user: user, servers: servidoresEnd })

Expand All @@ -147,6 +163,34 @@ app.get('/dashboard', async (req, res) => {



app.get('/auth/verify/:acesstoken', async (req, res) => {
let param = req.params.acesstoken
if (param) {
try {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'application/x-www-form-urlencoded'
};
let userResponse = await axios.get('https://discord.com/api/users/@me', {
headers: {
Authorization: `Bearer ${param}`,
...headers
}
}).then((res) => { return res.data })
if (userResponse) {
req.session.uid = userResponse.id
res.redirect('/dashboard')
}else{
res.redirect(webConfig.loginURL)
}
} catch (error) {
res.redirect(webConfig.loginURL)
}
} else {
res.redirect(webConfig.loginURL)
}
})

app.get('/auth/callback', async (req, res) => {
try {
if (req.session.uid) {
Expand All @@ -166,8 +210,9 @@ app.get('/auth/callback', async (req, res) => {
'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)})
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('/logout')
return
Expand Down Expand Up @@ -212,7 +257,7 @@ app.get('/logout', async (req, res) => {
res.redirect('/')
}
})
}else{
} else {
res.redirect('/')
}
} catch (error) {
Expand Down Expand Up @@ -421,7 +466,7 @@ app.get('/server/config/:id', functions.subscriptionStatus, async (req, res) =>



app.get('/help',(req,res)=>{
app.get('/help', (req, res) => {
res.redirect('https://discord.com/channels/1210714138838568960/1210927599669485648')
})

Expand Down
9 changes: 9 additions & 0 deletions public/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const botedit = new URLSearchParams(new URL(location.href).search).get('botedit', 0)
if (botedit == 'false') {
errorNotify('Você não tem permissão para editar o bot!')
const novaURL = window.location.protocol + '//' + window.location.host + window.location.pathname
window.history.pushState({ path: novaURL }, '', novaURL);
}



9 changes: 2 additions & 7 deletions views/dashboard.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@
<%- include('./reusable/script.ejs') %>
<script src="<%= host %>/public/js/dashboard.js"></script>
<script>
const botedit = new URLSearchParams(new URL(location.href).search).get('botedit',0)
console.log(botedit);
if (botedit == 'false') {
errorNotify('Você não tem permissão para editar o bot!')
const novaURL = window.location.protocol + '//' + window.location.host + window.location.pathname
window.history.pushState({ path: novaURL }, '', novaURL);
}
localStorage.setItem('access_token','<%= user.access_token %>')
let serverList = document.querySelectorAll('#serversID-list .serverID-col')
</script>
</body>
</html>
8 changes: 7 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@
<%- include('./reusable/script.ejs') %>
<div>
<script>
let discordUrl = `https://discord.com/oauth2/authorize?client_id=1210894508028338197&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Fauth%2Fcallback&scope=identify+guilds+email+guilds.join`
let discordUrl
if (localStorage.getItem('access_token')) {
discordUrl = `/auth/verify/${localStorage.getItem('access_token')}`
}else{
discordUrl = "https://discord.com/oauth2/authorize?client_id=1210894508028338197&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Fauth%2Fcallback&scope=identify+guilds+email+guilds.join"
}
let isloged = '<%= isloged %>'
document.querySelectorAll('.button-assinar').forEach(element=>{
if (isloged == 'true') {
Expand Down

0 comments on commit 9ac5273

Please sign in to comment.