Compare commits
2 commits
23036ca0aa
...
80ed58c856
Author | SHA1 | Date | |
---|---|---|---|
|
80ed58c856 | ||
|
c101db1de6 |
4 changed files with 10 additions and 43 deletions
|
@ -87,13 +87,12 @@ app.post("/account/create", [
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
role: startingRole,
|
role: startingRole
|
||||||
color: User.generateColorFromUsername(username)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const userObject = await user.getPublicObject();
|
const userObject = await user.getPublicObject();
|
||||||
|
|
||||||
console.log("[*] [logger] [users] [create] User created", userObject);
|
if (config.logAccountCreation) console.log("users: user created", userObject);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
error: false,
|
error: false,
|
||||||
|
@ -152,7 +151,7 @@ app.post("/token/create", [
|
||||||
|
|
||||||
const userObject = await existingUser.getPublicObject();
|
const userObject = await existingUser.getPublicObject();
|
||||||
|
|
||||||
console.log("[*] [logger] [users] [token create] Token created", userObject);
|
if (config.logAccountCreation) console.log("users: token created", userObject);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
error: false,
|
error: false,
|
||||||
|
|
|
@ -18,9 +18,9 @@ module.exports = {
|
||||||
allowAccountCreation: true,
|
allowAccountCreation: true,
|
||||||
allowLogin: true,
|
allowLogin: true,
|
||||||
allowGatewayConnection: true,
|
allowGatewayConnection: true,
|
||||||
// The policy below will make all messages sent over the gateway to be in plain text saved to the database.
|
// The policy below will make all messages sent over the gateway to be saved in plain text in the database.
|
||||||
// This is experimental and dangerous, and, as such, should generally not be used.
|
// This is experimental and dangerous, and, as such, should generally not be used.
|
||||||
allowSavingMessages: false,
|
allowSavingMessages: true,
|
||||||
perUserMaxGatewayConnections: 4
|
perUserMaxGatewayConnections: 4
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
|
@ -40,6 +40,8 @@ module.exports = {
|
||||||
gatewayMaxPayloadBytes: 4096,
|
gatewayMaxPayloadBytes: 4096,
|
||||||
clientFacingPingInterval: 14750,
|
clientFacingPingInterval: 14750,
|
||||||
bcryptRounds: 10,
|
bcryptRounds: 10,
|
||||||
|
// displays a message containing the username, role, etc. of a new created user or token (tokens and passwords should be stripped)
|
||||||
|
logAccountCreation: false,
|
||||||
experiments: {
|
experiments: {
|
||||||
voiceSFUTesting: false
|
voiceSFUTesting: false
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,6 @@ const userSchema = new mongoose.Schema({
|
||||||
password: String,
|
password: String,
|
||||||
email: String,
|
email: String,
|
||||||
role: String,
|
role: String,
|
||||||
color: String
|
|
||||||
});
|
});
|
||||||
|
|
||||||
userSchema.method("getPublicObject", function() {
|
userSchema.method("getPublicObject", function() {
|
||||||
|
@ -15,7 +14,6 @@ userSchema.method("getPublicObject", function() {
|
||||||
username: this.username,
|
username: this.username,
|
||||||
permissionLevel: config.roleMap[this.role],
|
permissionLevel: config.roleMap[this.role],
|
||||||
role: this.role,
|
role: this.role,
|
||||||
color: this.color,
|
|
||||||
_id: this._id
|
_id: this._id
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -27,51 +25,20 @@ userSchema.method("getFullObject", function() {
|
||||||
email: this.email,
|
email: this.email,
|
||||||
permissionLevel: config.roleMap[this.role],
|
permissionLevel: config.roleMap[this.role],
|
||||||
role: this.role,
|
role: this.role,
|
||||||
color: this.color,
|
|
||||||
_id: this._id
|
_id: this._id
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const User = mongoose.model("User", userSchema);
|
const User = mongoose.model("User", userSchema);
|
||||||
|
|
||||||
// NOTE(hippoz): These are all actually material design colors, taken from https://material-ui.com/customization/color/#playground
|
|
||||||
const colors = [
|
|
||||||
"#f44336",
|
|
||||||
"#e91e63",
|
|
||||||
"#9c27b0",
|
|
||||||
"#673ab7",
|
|
||||||
"#3f51b5",
|
|
||||||
"#2196f3",
|
|
||||||
"#03a9f4",
|
|
||||||
"#00bcd4",
|
|
||||||
"#009688",
|
|
||||||
"#4caf50",
|
|
||||||
"#8bc34a",
|
|
||||||
"#cddc39",
|
|
||||||
"#ffeb3b",
|
|
||||||
"#ffc107",
|
|
||||||
"#ff9800",
|
|
||||||
"#ff5722"
|
|
||||||
];
|
|
||||||
|
|
||||||
User.generateColorFromUsername = function(username) {
|
|
||||||
let sum = 0;
|
|
||||||
for (let i in username) {
|
|
||||||
sum += username.charCodeAt(i);
|
|
||||||
}
|
|
||||||
const colorIndex = sum % colors.length;
|
|
||||||
return colors[colorIndex];
|
|
||||||
};
|
|
||||||
|
|
||||||
User.findByUsername = async function(username) {
|
User.findByUsername = async function(username) {
|
||||||
return await User.findOne({ username }).exec();
|
return await User.findOne({ username }).exec();
|
||||||
};
|
};
|
||||||
|
|
||||||
User.getPulicFields = function(isPartial=false) {
|
User.getPulicFields = function(isPartial=false) {
|
||||||
if (isPartial) {
|
if (isPartial)
|
||||||
return "username _id color";
|
return "username _id";
|
||||||
}
|
return "username role _id";
|
||||||
return "username role _id color";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = User;
|
module.exports = User;
|
|
@ -223,7 +223,6 @@ Used mostly for messages.
|
||||||
| - | - |
|
| - | - |
|
||||||
| _id | The id of the user |
|
| _id | The id of the user |
|
||||||
| name | The name of the user |
|
| name | The name of the user |
|
||||||
| color | A hex color that represents that user |
|
|
||||||
|
|
||||||
## Message author object
|
## Message author object
|
||||||
|
|
||||||
|
|
Reference in a new issue