Skip to content

Commit

Permalink
cherry-pick from account branch, a non wip copy from javi
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaps committed Nov 18, 2023
1 parent 2288b1f commit da3f74f
Show file tree
Hide file tree
Showing 22 changed files with 738 additions and 1,394 deletions.
25 changes: 11 additions & 14 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ app.use("/news", newsRouter)
// --- UNPROTECTED ROUTES ---
const appGetRouteArray = [
// This first '' is the home/index page
'', 'newshub', 'campaign-missions', 'scfa-vs-faf', 'donation', 'tutorials-guides', 'ai', 'patchnotes', 'faf-teams', 'contribution', 'content-creators', 'tournaments', 'training', 'leaderboards', 'play', 'clans',];
'', 'newshub', 'campaign-missions', 'scfa-vs-faf', 'donation', 'tutorials-guides', 'ai', 'patchnotes', 'faf-teams', 'contribution', 'content-creators', 'tournaments', 'training', 'leaderboards', 'play'];

//Renders every page written above
appGetRouteArray.forEach(page => app.get(`/${page}`, (req, res) => {
// disabled due https://github.com/FAForever/website/issues/445
if (['leaderboards', 'clans'].includes(page)) {
if (['leaderboards'].includes(page)) {
return res.status(503).render('errors/503-known-issue')
}
res.render(page);
Expand Down Expand Up @@ -150,24 +150,21 @@ const routes = './routes/views/';

const clansRoutesGet = [
'create', 'manage', 'accept_invite',];
// disabled due https://github.com/FAForever/website/issues/445
// clansRoutesGet.forEach(page => app.get(`/clans/${page}`, loggedIn, require(`${routes}clans/get/${page}`)));
clansRoutesGet.forEach(page => app.get(`/clans/${page}`, loggedIn, (req, res) => res.status(503).render('errors/503-known-issue')));
clansRoutesGet.forEach(page => app.get(`/clans/${page}`, loggedIn, require(`${routes}clans/get/${page}`)));

const clansRoutesPost = [
'create', 'destroy', 'invite', 'kick', 'transfer', 'update', 'leave', 'join',];
// disabled due https://github.com/FAForever/website/issues/445
// clansRoutesPost.forEach(page => app.post(`/clans/${page}`, loggedIn, require(`${routes}clans/post/${page}`)));
clansRoutesPost.forEach(page => app.post(`/clans/${page}`, loggedIn, (req, res) => res.status(503).render('errors/503-known-issue')));
clansRoutesPost.forEach(page => app.post(`/clans/${page}`, loggedIn, require(`${routes}clans/post/${page}`)));

app.get('/clans/*', (req, res) => {
let id = req.path.slice(-3);
res.redirect(`/clans/getClan?tag=${id}`);
});

// disabled due https://github.com/FAForever/website/issues/445
//Unprotected clan routes
app.get('/clans', require(`${routes}clans/get/clans`));
app.get('/clans/getClan', require(`${routes}clans/get/getClan`));
//When searching for a specific clan
// app.get('/clans/*', (req, res) => {
// res.render(`clans/seeClan`);
// });
app.get('/clans/*', (req, res) => res.status(503).render('errors/503-known-issue'));


// Markdown Routes

Expand Down
1 change: 0 additions & 1 deletion public/js/app/clans.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function clanUpdate() {
for (clanIndex; clanIndex < next100Players; clanIndex++) {
if (clanIndex < 0) {
clanIndex = 0;
console.log('There are no more players left.');
}
// Gets the player data and inserts it into the li element

Expand Down
72 changes: 0 additions & 72 deletions public/js/app/getClans.js

This file was deleted.

9 changes: 0 additions & 9 deletions public/styles/site/clans.sass
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ input
textarea
width: 40vw

.clanManagementDanger
background-color: variables.$Cybran-dark
border-radius: 20px
ul
text-align: center
li
display: inline-block
list-style: none
text-align: left
.clanManagementTable
padding: 1.5em
display: inline-block
Expand Down
29 changes: 29 additions & 0 deletions routes/views/clans/get/clans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
exports = module.exports = function (req, res) {
let flash = {};
if (req.query.flash) {

flash.class = 'alert-success';
flash.type = 'Success!';
switch (req.query.flash) {
case 'leave':
flash.messages = 'You left your clan.';
break;

case 'destroy':
flash.messages = 'You deleted your clan.';
break;

case 'transfer':
flash.messages = `You have transferred your clan to ${req.query.newLeader}.`;
break;

case 'error':
flash.class = 'alert-danger';
flash.messages = 'There was an issue with your request.';
flash.type = 'Error!';
break;
}
}
res.render('clans', {flash: flash});

};
8 changes: 4 additions & 4 deletions routes/views/clans/get/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exports = module.exports = function(req, res) {

request.get(
{
url: process.env.API_URL + '/clans/me',
headers: {
'Authorization': 'Bearer ' + req.user.data.attributes.token
}
url: process.env.API_URL + '/clans/me',
headers: {
'Authorization': 'Bearer ' + req.user.token
}
},
function (err, childRes, body) {

Expand Down
64 changes: 64 additions & 0 deletions routes/views/clans/get/getClan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const axios = require('axios');
require('dotenv').config();
exports = module.exports = function(req, res) {

if (!req.query.tag) res.redirect('../clans?flash=error');
else {


//We call the API and get the info needed
axios.get(`${process.env.API_URL}/data/clan?include=memberships.player&filter=tag==${req.query.tag.toLowerCase()}`
).then(response => {
const {attributes} = response.data.data[0];
const {name, description, createTime} = attributes;

// first lets check user is logged in and has a clan
if (req.user && req.user.data.attributes.clan !== undefined) {
// lets check if the user belongs to the clan
if (req.user.data.attributes.clan.tag.toLowerCase() === req.query.tag.toLowerCase()) {
res.locals.leaveButton = true;
}
}

//We set the values as local variables in our response
res.locals.clanName = name;
res.locals.clanDescription = description;
res.locals.clanCreation = createTime.slice(0, 10);
res.locals.clanTag = req.query.tag.toUpperCase();


//We add in the clan members
let clanMembers = [];
response.data.included.forEach((member, index) => {
// We only allow odd numbers because the API brings extra information on even numbers that don't include a members login/username
if (index % 2 !== 0) {
clanMembers.push(member.attributes.login);
}
});
res.locals.clanMembers = clanMembers;

//We find the clan leader
const leaderID = response.data.data[0].relationships.leader.data.id;
response.data.included.forEach((element, index) => {
if (index % 2 !== 0) {
if (element.id === leaderID) {
res.locals.clanLeaderName = element.attributes.login;
}
}
});




}).catch((e) => {

res.redirect('../clans?flash=error');

}).finally(() => {



res.render('clans/getClan');
});
}
};
Loading

0 comments on commit da3f74f

Please sign in to comment.