Version 1.0.0 - Ajout de WebMetrics et de l'édit utilisateur
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
57
bin/users.js
57
bin/users.js
@ -77,7 +77,7 @@ module.exports.fetchUsers = function () {
|
||||
],
|
||||
"tokens": [],
|
||||
"lastLogin": "DEFAULT ACCOUNT",
|
||||
"picture": "/images/users/default.jpg"
|
||||
"picture": "/images/default.jpg"
|
||||
})
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ module.exports.User = class {
|
||||
permission = []
|
||||
tokens = []
|
||||
lastLogin = new Date()
|
||||
picture = "/images/users/default.jpg"
|
||||
picture = "/images/default.jpg"
|
||||
|
||||
constructor(properties) {
|
||||
|
||||
@ -164,7 +164,7 @@ module.exports.User = class {
|
||||
this.lastLogin = new Date()
|
||||
}
|
||||
if(this.picture == null) {
|
||||
this.picture = "/images/users/default.jpg"
|
||||
this.picture = "/images/default.jpg"
|
||||
}
|
||||
|
||||
|
||||
@ -330,7 +330,7 @@ module.exports.User = class {
|
||||
var pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
|
||||
fs.writeFileSync(pictureDir, file)
|
||||
|
||||
this.picture = pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/images/users/")
|
||||
this.picture = pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/users/")
|
||||
this.register()
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ module.exports.addUser = function(settings) {
|
||||
|
||||
|
||||
if(settings.picture == null) {
|
||||
pictureDir = "/images/users/default.jpg"
|
||||
pictureDir = "/images/default.jpg"
|
||||
} else {
|
||||
pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
|
||||
fs.writeFileSync(pictureDir, settings.picture)
|
||||
@ -465,6 +465,53 @@ module.exports.editUser = function(settings) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.editMySelf = function (settings, user) {
|
||||
if(user.username == settings.actualUsername) {
|
||||
if(settings.username == '') {
|
||||
ulog.error("Le nom d'utilisateur est manquant")
|
||||
return "USERNAME_MISSING"
|
||||
} else if(settings.display_name == '') {
|
||||
ulog.error("Le nom d'affichage est manquant")
|
||||
return "DISPLAY_NAME_MISSING"
|
||||
} else {
|
||||
ulog.step.init("edit_user", "Modification d'un utilisateur dans la base de donnée : " + settings.username)
|
||||
const user = this.fetchUsers().get(settings.username)
|
||||
if(user) {
|
||||
console.log(settings)
|
||||
if(settings.newusername && settings.newusername != settings.username) {
|
||||
if(this.getUser(settings.newusername)) {
|
||||
ulog.error("L'utilisateur existe déjà : " + settings.username)
|
||||
return "ALREADY_EXIST"
|
||||
} else {
|
||||
|
||||
user.setNewUsername(settings.newusername)
|
||||
}
|
||||
}
|
||||
if(settings.display_name) {
|
||||
user.setDisplayName(settings.display_name)
|
||||
}
|
||||
|
||||
if(settings.password) {
|
||||
user.setPassword(settings.password)
|
||||
}
|
||||
|
||||
if(settings.picture) {
|
||||
user.setPicture(settings.picture)
|
||||
}
|
||||
ulog.step.end("edit_user")
|
||||
return "OK"
|
||||
} else {
|
||||
ulog.step.end("edit_user")
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
ulog.error("Vous ne pouvez pas modifier les informations d'un autre utilisateur !")
|
||||
return "NOT_ALLOWED"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.clearTokens = function(username) {
|
||||
|
||||
const user = this.fetchUsers().get(username)
|
||||
|
Reference in New Issue
Block a user