-
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.
- Loading branch information
Showing
28 changed files
with
487 additions
and
543 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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
const create = require('../views/clans/create') | ||
const invite = require('./clans/invite') | ||
const leave = require('./clans/leave') | ||
const express = require('../../ExpressApp') | ||
const router = express.Router() | ||
const middlewares = require('../middleware') | ||
|
||
// This will be replaced soon, therefor I did not spend time on it | ||
router.get('/', (req, res) => res.render('clans/clans')) | ||
router.get('/view/:id', async (req, res) => { | ||
const clanId = parseInt(req.params.id || null) | ||
if (!clanId) { | ||
return res.redirect('/clans') | ||
} | ||
router.get('/view/:id', require('./clans/view')) | ||
|
||
return res.render('clans/clan', { clan: await req.appContainer.get('ClanService').getClan(clanId) }) | ||
}) | ||
|
||
router.get('/create', create) | ||
router.post('/create', create) | ||
router.get('/create', middlewares.isAuthenticated(), create) | ||
router.post('/create', middlewares.isAuthenticated(), create) | ||
router.get('/manage', middlewares.isAuthenticated(), require('./clans/get/manage')) | ||
router.post('/update', middlewares.isAuthenticated(), require('./clans/post/update')) | ||
router.post('/destroy', middlewares.isAuthenticated(), require('./clans/post/destroy')) | ||
|
||
router.get('/invite', middlewares.isAuthenticated(), invite) | ||
router.post('/invite', middlewares.isAuthenticated(), invite) | ||
router.get('/kick/:memberId', middlewares.isAuthenticated(), require('./clans/kick')) | ||
router.get('/leave', middlewares.isAuthenticated(), leave) | ||
router.post('/leave', middlewares.isAuthenticated(), leave) | ||
router.get('/join', middlewares.isAuthenticated(), require('./clans/join')) | ||
router.get('/invite-accept', middlewares.isAuthenticated(), require('./clans/inviteAccept')) | ||
router.get('*', (req, res) => res.status(503).render('errors/503-known-issue')) | ||
|
||
module.exports = router |
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,46 @@ | ||
const { JavaApiError } = require('../../../services/ApiErrors') | ||
const { body } = require('express-validator') | ||
const url = require('url') | ||
|
||
exports = module.exports = [ | ||
body('invited_player', 'Please select a player').notEmpty().isLength({ max: 20 }), | ||
async (req, res) => { | ||
if (req.method === 'POST') { | ||
const user = await req.appContainer.get('DataRepository').fetchUserByName(req.body.invited_player) | ||
|
||
if (!user) { | ||
await req.asyncFlash('error', 'User not found') | ||
return res.render('clans/invite', { | ||
invited_player: req.body.invited_player | ||
}) | ||
} | ||
|
||
try { | ||
const invitation = await req.requestContainer.get('ClanManagementService').createInvite(user.id) | ||
|
||
return res.render('clans/invite', { | ||
invited_player: req.body.invited_player, | ||
link: url.format({ | ||
pathname: '/clans/invite-accept', | ||
query: { | ||
token: encodeURIComponent(invitation) | ||
} | ||
}) | ||
}) | ||
} catch (e) { | ||
let message = e.toString() | ||
if (e instanceof JavaApiError && e.error?.errors) { | ||
message = e.error.errors[0].detail | ||
} | ||
|
||
await req.asyncFlash('error', message) | ||
|
||
return res.redirect('/clans/manage') | ||
} | ||
} | ||
|
||
return res.render('clans/invite', { | ||
invited_player: '' | ||
}) | ||
} | ||
] |
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,36 @@ | ||
const decodingJWT = (token) => { | ||
if (token !== null) { | ||
const base64String = token.split('.')[1] | ||
return JSON.parse(Buffer.from(base64String, | ||
'base64').toString('ascii')) | ||
} | ||
return null | ||
} | ||
|
||
exports = module.exports = async function (req, res) { | ||
if (!req.query.token) { | ||
await req.asyncFlash('error', 'The invitation link is invalid!') | ||
|
||
return res.redirect('/clans') | ||
} | ||
const token = req.query.token | ||
|
||
const decodedToken = decodingJWT(req.query.token) | ||
|
||
if (decodedToken === null || decodedToken.clan?.name === undefined) { | ||
await req.asyncFlash('error', 'The invitation link is invalid!') | ||
|
||
return res.redirect('/clans') | ||
} | ||
|
||
if (req.requestContainer.get('UserService').getUser()?.clan) { | ||
await req.asyncFlash('error', 'You are already in a clan') | ||
|
||
return res.redirect('/clans/view/' + req.requestContainer.get('UserService').getUser().clan.id) | ||
} | ||
|
||
res.render('clans/accept_invite', { | ||
acceptURL: `/clans/join?token=${token}`, | ||
clanName: decodedToken.clan.name | ||
}) | ||
} |
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,33 @@ | ||
const { JavaApiError } = require('../../../services/ApiErrors') | ||
|
||
exports = module.exports = async function (req, res) { | ||
if (!req.query.token) { | ||
await req.asyncFlash('error', 'The invitation link is invalid!') | ||
|
||
return res.redirect('/clans') | ||
} | ||
const token = req.query.token | ||
|
||
try { | ||
await req.requestContainer.get('ClanManagementService').acceptInvitation(token) | ||
await req.asyncFlash('info', 'Clan joined!') | ||
|
||
return res.redirect('/clans/view/' + req.requestContainer.get('UserService').getUser().clan.id) | ||
} catch (e) { | ||
console.log(e.stack) | ||
let message = e.toString() | ||
|
||
if (e instanceof JavaApiError && e.error?.errors) { | ||
message = e.error.errors[0].detail | ||
|
||
if (e.error.errors[0].code === '152') { | ||
await req.asyncFlash('error', message) | ||
return res.redirect('/clans') | ||
} | ||
} | ||
|
||
await req.asyncFlash('error', message) | ||
|
||
return res.redirect('/clans') | ||
} | ||
} |
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,33 @@ | ||
const { JavaApiError } = require('../../../services/ApiErrors') | ||
|
||
exports = module.exports = async function (req, res) { | ||
const memberId = parseInt(req.params.memberId || null) | ||
if (!memberId) { | ||
await req.asyncFlash('error', 'memberId is required') | ||
|
||
return res.redirect('/clans') | ||
} | ||
|
||
const user = req.requestContainer.get('UserService').getUser() | ||
|
||
if (!user.clan) { | ||
await req.asyncFlash('info', 'You are not in a clan') | ||
|
||
return res.redirect('/clans') | ||
} | ||
|
||
try { | ||
await req.requestContainer.get('ClanManagementService').kickMember(memberId) | ||
|
||
return res.redirect('/clans/view/' + req.requestContainer.get('UserService').getUser().clan.id) | ||
} catch (e) { | ||
let message = e.toString() | ||
if (e instanceof JavaApiError && e.error?.errors) { | ||
message = e.error.errors[0].detail | ||
} | ||
|
||
await req.asyncFlash('error', message) | ||
|
||
return res.redirect('/clans/view/' + req.requestContainer.get('UserService').getUser().clan.id) | ||
} | ||
} |
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,32 @@ | ||
const { JavaApiError } = require('../../../services/ApiErrors') | ||
|
||
exports = module.exports = async function (req, res) { | ||
const user = req.requestContainer.get('UserService').getUser() | ||
|
||
if (!user.clan.membershipId) { | ||
await req.asyncFlash('info', 'You are not in a clan') | ||
|
||
return res.redirect('/clans') | ||
} | ||
|
||
if (req.method === 'POST') { | ||
try { | ||
await req.requestContainer.get('ClanManagementService').leaveClan() | ||
await req.asyncFlash('info', 'Clan left') | ||
|
||
return res.redirect('/clans') | ||
} catch (e) { | ||
console.error(e.stack) | ||
let message = e.toString() | ||
if (e instanceof JavaApiError && e.error?.errors) { | ||
message = e.error.errors[0].detail | ||
} | ||
|
||
await req.asyncFlash('error', message) | ||
|
||
return res.redirect('/clans') | ||
} | ||
} | ||
|
||
return res.render('clans/leave') | ||
} |
Oops, something went wrong.