-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry-pick from account branch, a non wip copy from javi
- Loading branch information
Showing
22 changed files
with
738 additions
and
1,394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.