-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clan invite links die whenever seen * Two step clan invitation * Log invite kills * Update Dockerfile * Update Dockerfile removed copy of env Co-authored-by: Louvenarde <[email protected]> Co-authored-by: Rowey <[email protected]>
- Loading branch information
1 parent
7947b89
commit 1ad6abc
Showing
7 changed files
with
150 additions
and
23 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 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,95 @@ | ||
const request = require('request'); | ||
|
||
exports = module.exports = function(req, res) { | ||
|
||
var locals = res.locals; | ||
|
||
// locals.section is used to set the currently selected | ||
// item in the header navigation. | ||
locals.section = 'clan'; | ||
let flash = {}; | ||
|
||
if (!req.query.i){ | ||
flash.type = 'Error!'; | ||
flash.class = 'alert-danger'; | ||
flash.messages = [{msg: 'The invitation link is wrong or truncated. Key informations are missing.'}]; | ||
|
||
let buff = Buffer.from(JSON.stringify(flash)); | ||
let data = buff.toString('base64'); | ||
|
||
return res.redirect('/clans?flash='+data); | ||
} | ||
|
||
const invitationId = req.query.i; | ||
|
||
if (!req.app.locals.clanInvitations[invitationId]){ | ||
flash.type = 'Error!'; | ||
flash.class = 'alert-danger'; | ||
flash.messages = [{msg: 'The invitation link is wrong or truncated. Invite code missing from website clan map.'}]; | ||
|
||
let buff = Buffer.from(JSON.stringify(flash)); | ||
let data = buff.toString('base64'); | ||
|
||
return res.redirect('/clans?flash='+data); | ||
} | ||
|
||
const invite = req.app.locals.clanInvitations[invitationId]; | ||
const clanId = invite.clan; | ||
|
||
if (req.user.data.attributes.clan != null){ | ||
// User is already in a clan! | ||
return res.redirect('/clans/see?id='+req.user.data.attributes.clan.id); | ||
} | ||
|
||
const queryUrl = process.env.API_URL | ||
+ '/data/clan/'+clanId | ||
+ '?include=memberships.player' | ||
+ '&fields[clan]=createTime,description,name,tag,updateTime,websiteUrl,founder,leader' | ||
+ '&fields[player]=login,updateTime' | ||
; | ||
|
||
request.get( | ||
{ | ||
url: queryUrl | ||
}, | ||
function (err, childRes, body) { | ||
|
||
const clan = JSON.parse(body); | ||
|
||
if (err || !clan.data){ | ||
flash.type = 'Error!'; | ||
flash.class = 'alert-danger'; | ||
flash.messages = [{msg: 'The clan you want to join is invalid or does no longer exist'}]; | ||
|
||
let buff = Buffer.from(JSON.stringify(flash)); | ||
let data = buff.toString('base64'); | ||
|
||
return res.redirect('./?flash='+data); | ||
} | ||
|
||
locals.clanName = clan.data.attributes.name; | ||
locals.clanLeaderName = "<unknown>"; | ||
|
||
for (k in clan.included){ | ||
switch(clan.included[k].type){ | ||
case "player": | ||
const player = clan.included[k]; | ||
|
||
// Getting the leader name | ||
if (player.id == clan.data.relationships.leader.data.id) | ||
{ | ||
locals.clanLeaderName = player.attributes.login; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
const token = invite.token; | ||
locals.acceptURL = `/clans/join?clan_id=${clanId}&token=${token}`; | ||
|
||
// Render the view | ||
res.render('clans/accept_invite'); | ||
} | ||
); | ||
}; |
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 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,19 @@ | ||
extends ../../layouts/default | ||
include ../../mixins/flash-messages | ||
|
||
block content | ||
.container.text-center | ||
.row | ||
.col-md-12 | ||
h1.account-title Accept invitation | ||
h4.account-subtitle.text-center Click the button below to accept the invitation from #{clanLeaderName} to join #{clanName} | ||
hr | ||
.row | ||
.col-md-offset-3.col-md-6 | ||
+flash-messages(flash) | ||
|
||
.row | ||
.col-md-offset-3.col-md-6 | ||
form(method='post', action=acceptURL, data-toggle="validator") | ||
button(type='submit').btn.btn-default.btn-lg.btn-outro.btn-danger Join #{clanName} | ||
|