Cleaned adminPanel and started adding User mgmt
This commit is contained in:
parent
cde60bb78d
commit
064109556c
11 changed files with 153 additions and 54 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue