mirror of https://gitgud.io/fatchan/jschan.git
merge-requests/208/head
parent
ff22b3650c
commit
2b4e631756
20 changed files with 263 additions and 36 deletions
@ -1,21 +1,67 @@ |
|||||||
'use strict'; |
'use strict'; |
||||||
|
|
||||||
const { Accounts } = require(__dirname+'/../../db/'); |
const { Accounts, Boards } = require(__dirname+'/../../db/') |
||||||
|
, cache = require(__dirname+'/../../redis.js') |
||||||
|
|
||||||
module.exports = async (req, res, next) => { |
module.exports = async (req, res, next) => { |
||||||
|
|
||||||
//edit the accounts
|
//edit the accounts
|
||||||
let amount = 0; |
let amount = 0; |
||||||
if (req.body.delete_account) { |
if (req.body.delete_account) { |
||||||
|
const accountsWithBoards = await Accounts.getOwnedOrModBoards(req.body.checkedaccounts); |
||||||
|
if (accountsWithBoards.length > 0) { |
||||||
|
const bulkWrites = []; |
||||||
|
for (let i = 0; i < accountsWithBoards.length; i++) { |
||||||
|
const acc = accountsWithBoards[i]; |
||||||
|
if (acc.modBoards.length > 0) { |
||||||
|
//remove from moderators of any boards they are mod on
|
||||||
|
bulkWrites.push({ |
||||||
|
'updateMany': { |
||||||
|
'filter': { |
||||||
|
'_id': { |
||||||
|
'$in': acc.modBoards |
||||||
|
} |
||||||
|
}, |
||||||
|
'update': { |
||||||
|
'$pull': { |
||||||
|
'settings.moderators': acc._id |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
cache.del(acc.modBoards.map(b => `board_${b}`)); |
||||||
|
} |
||||||
|
if (acc.ownedBoards.length > 0) { |
||||||
|
//remove from moderators of any boards they are mod on
|
||||||
|
bulkWrites.push({ |
||||||
|
'updateMany': { |
||||||
|
'filter': { |
||||||
|
'_id': { |
||||||
|
'$in': acc.ownedBoards |
||||||
|
} |
||||||
|
}, |
||||||
|
'update': { |
||||||
|
'$set': { |
||||||
|
'owner': null //board has no owner
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
cache.del(acc.ownedBoards.map(b => `board_${b}`)); |
||||||
|
//todo: use list of board with no owners for claims
|
||||||
|
} |
||||||
|
} |
||||||
|
await Boards.db.bulkWrite(bulkWrites); |
||||||
|
} |
||||||
amount = await Accounts.deleteMany(req.body.checkedaccounts).then(res => res.deletedCount); |
amount = await Accounts.deleteMany(req.body.checkedaccounts).then(res => res.deletedCount); |
||||||
} else { |
} else { |
||||||
amount = await Accounts.setLevel(req.body.checkedaccounts, req.body.auth_level).then(res => res.modifiedCount); |
amount = await Accounts.setLevel(req.body.checkedaccounts, req.body.auth_level).then(res => res.modifiedCount); |
||||||
} |
} |
||||||
|
|
||||||
return res.render('message', { |
return res.render('message', { |
||||||
'title': 'Success', |
'title': 'Success', |
||||||
'message': `${req.body.delete_account ? 'Deleted' : 'Edited'} ${amount} accounts`, |
'message': `${req.body.delete_account ? 'Deleted' : 'Edited'} ${amount} accounts`, |
||||||
'redirect': '/globalmanage/accounts.html' |
'redirect': '/globalmanage/accounts.html' |
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,9 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = async (req, res, next) => { |
||||||
|
|
||||||
|
return res.render('account', { |
||||||
|
user: req.session.user
|
||||||
|
}); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
extends ../layout.pug |
||||||
|
|
||||||
|
block head |
||||||
|
script(src='/js/all.js') |
||||||
|
title Manage |
||||||
|
|
||||||
|
block content |
||||||
|
.board-header |
||||||
|
h1.board-title Welcome, #{user.username} |
||||||
|
h4.board-description Auth level: #{user.authLevel} |
||||||
|
br |
||||||
|
hr(size=1) |
||||||
|
h4.no-m-p General: |
||||||
|
ul |
||||||
|
if user.authLevel <= 1 |
||||||
|
li: a(href='/globalmanage/recent.html') Global management |
||||||
|
li: a(href='/create.html') Create a board |
||||||
|
li: a(href='/changepassword.html') Change password |
||||||
|
li: a(href='/logout') Log out |
||||||
|
hr(size=1) |
||||||
|
h4.no-m-p Boards you own: |
||||||
|
if user.ownedBoards && user.ownedBoards.length > 0 |
||||||
|
ul |
||||||
|
for b in user.ownedBoards |
||||||
|
li |
||||||
|
a(href=`/${b}/index.html`) /#{b}/ |
||||||
|
| - |
||||||
|
a(href=`/${b}/manage/reports.html`) Reports |
||||||
|
| , |
||||||
|
a(href=`/${b}/manage/bans.html`) Bans |
||||||
|
| , |
||||||
|
a(href=`/${b}/manage/settings.html`) Settings |
||||||
|
| , |
||||||
|
a(href=`/${b}/manage/banners.html`) Banners |
||||||
|
else |
||||||
|
p None |
||||||
|
hr(size=1) |
||||||
|
h4.no-m-p Boards you moderate: |
||||||
|
if user.modBoards && user.modBoards.length > 0 |
||||||
|
ul |
||||||
|
for b in user.modBoards |
||||||
|
li |
||||||
|
a(href=`/${b}/index.html`) /#{b}/ |
||||||
|
| - |
||||||
|
a(href=`/${b}/manage/reports.html`) Reports |
||||||
|
| , |
||||||
|
a(href=`/${b}/manage/bans.html`) Bans |
||||||
|
else |
||||||
|
p None |
Loading…
Reference in new issue