diff --git a/src/controllers/adminPanelController.js b/src/controllers/adminPanelController.js index d0dd8ed..501a02b 100644 --- a/src/controllers/adminPanelController.js +++ b/src/controllers/adminPanelController.js @@ -16,15 +16,17 @@ along with this program. If not, see .*/ //Config const config = require('../../config.json'); +const userModel = require('../schemas/userSchema'); const channelModel = require('../schemas/channelSchema'); +const {exceptionHandler} = require("../utils/loggerUtils"); //register page functions module.exports.get = async function(req, res){ try{ const chanGuide = await channelModel.getChannelList(true); - return res.render('adminPanel', {instance: config.instanceName, user: req.session.user, chanGuide: chanGuide}); + const userList = await userModel.getUserList(true); + return res.render('adminPanel', {instance: config.instanceName, user: req.session.user, chanGuide: chanGuide, userList: userList}); }catch(err){ - res.status(500); - return res.send("Error indexing channels!"); + return exceptionHandler(res,err); } } \ No newline at end of file diff --git a/src/schemas/channelSchema.js b/src/schemas/channelSchema.js index 838d645..31a3a01 100644 --- a/src/schemas/channelSchema.js +++ b/src/schemas/channelSchema.js @@ -38,7 +38,7 @@ const channelSchema = new mongoose.Schema({ thumbnail: { type: mongoose.SchemaTypes.String, required: true, - default: "img/johnny.png" + default: "/img/johnny.png" }, settings: { hidden: { diff --git a/src/schemas/userSchema.js b/src/schemas/userSchema.js index 3613ede..11608fb 100644 --- a/src/schemas/userSchema.js +++ b/src/schemas/userSchema.js @@ -59,7 +59,7 @@ const userSchema = new mongoose.Schema({ img: { type: mongoose.SchemaTypes.String, required: true, - default: "img/johnny.png" + default: "/img/johnny.png" }, bio: { type: mongoose.SchemaTypes.String, @@ -167,6 +167,40 @@ userSchema.methods.getAuthenticatedSessions = async function(){ } +userSchema.statics.getUserList = async function(fullList = false){ + var userList = []; + //Get all of our users + const users = await this.find({}); + + //Return empty if we don't find nuthin' + if(users == null){ + return []; + } + + //For each user + users.forEach((user)=>{ + //create a user object with limited properties (safe for public consumption) + var userObj = { + id: user.id, + name: user.user, + img: user.img, + date: user.date + } + + //Put together a spicier version for admins when told so (permission checks should happen before this is called) + if(fullList){ + userObj.rank = user.rank, + userObj.email = user.email + } + + //Add user object to list + userList.push(userObj); + }); + + //return the userlist + return userList; +} + //note: if you gotta call this from a request authenticated by it's user, make sure to kill that session first! userSchema.methods.killAllSessions = async function(){ //get authenticated sessions diff --git a/src/utils/validators.js b/src/utils/validators.js index 2a461f9..b3c2da2 100644 --- a/src/utils/validators.js +++ b/src/utils/validators.js @@ -27,7 +27,7 @@ module.exports.accountValidator = { email: (field = 'email') => body(field).optional().isEmail().normalizeEmail(), - img: (field = 'img') => body(field).optional().isURL({require_tld: false}).trim(), + img: (field = 'img') => body(field).optional().isURL({require_tld: false, require_host: false}).trim(), signature: (field = 'signature') => body(field).optional().escape().trim().isLength({min: 1, max: 150}), diff --git a/src/views/adminPanel.ejs b/src/views/adminPanel.ejs index fc04197..f43cc43 100644 --- a/src/views/adminPanel.ejs +++ b/src/views/adminPanel.ejs @@ -22,39 +22,8 @@ along with this program. If not, see .--> <%- include('partial/navbar', {user}); %> -
-

Channel List:

- - - - - - - <% chanGuide.forEach((channel) => { %> - - - - - - <% }); %> -
-

Img

-
-

Name

-
-

Description

-
- - - - - - <%- channel.name %> - - -

<%- channel.description %>

-
-
+ <%- include('partial/adminPanel/channelList', {chanGuide}) %> + <%- include('partial/adminPanel/userList', {userList}) %>