Version 1.0.0 - Basic Web Application

This commit is contained in:
2024-12-29 15:18:12 +01:00
parent 0ffcafdf3f
commit 6f637968bd
50 changed files with 42 additions and 6643 deletions

View File

@ -50,10 +50,8 @@ module.exports.fetchUsers = function () {
username: userFetched.username,
password: userFetched.password,
display_name: userFetched.display_name,
permission: userFetched.permission,
tokens: userFetched.tokens,
lastLogin: userFetched.lastLogin,
picture: userFetched.picture
})
@ -63,21 +61,10 @@ module.exports.fetchUsers = function () {
if(usersList.size == 0) {
const adminUser = new this.User({
"username": "admin",
"password": "neutral",
"password": "inventory",
"display_name": "Administrateur",
"permission": [
"FILES_EXPLORER",
"SERVICES",
"SERVERS",
"PIPELINES",
"METRICS",
"USERS",
"LINKS",
"SETTINGS"
],
"tokens": [],
"lastLogin": "DEFAULT ACCOUNT",
"picture": "/images/default.jpg"
})
@ -94,16 +81,14 @@ module.exports.fetchUsers = function () {
/**
* User Class is used to access to default user's properties and methods
* @param {object} properties User properties with : username, password, display_name, permission...
* @param {object} properties User properties with : username, password, display_name
*/
module.exports.User = class {
username = null
password = null;
display_name = null
permission = []
tokens = []
lastLogin = new Date()
picture = "/images/default.jpg"
constructor(properties) {
@ -112,10 +97,8 @@ module.exports.User = class {
this.username = properties.username
this.password = keygen.encrypt(properties.password)
this.display_name = properties.display_name
this.permission = properties.permission
this.tokens = properties.tokens
this.lastLogin = properties.lastLogin
this.picture = properties.picture
const userFile = getFile()
@ -125,7 +108,6 @@ module.exports.User = class {
this.username = userFetched.username
this.password = userFetched.password
this.display_name = userFetched.display_name
this.permission = userFetched.permission
this.tokens = userFetched.tokens
this.lastLogin = userFetched.lastLogin
}
@ -150,22 +132,14 @@ module.exports.User = class {
ulog.warn("'" + this.username + "' is without display name !")
this.display_name = this.username
}
if(this.permission == null) {
ulog.warn("'" + this.username + "' has no longer permission !")
}
if(this.tokens == null) {
this.tokens = []
}
if(this.permission == null) {
this.permission = []
}
if(this.lastLogin == null) {
this.lastLogin = new Date()
}
if(this.picture == null) {
this.picture = "/images/default.jpg"
}
}
@ -211,47 +185,7 @@ module.exports.User = class {
usersList.delete(this.username)
}
checkPermission(name) {
this.#sync()
if(this.permission.includes(name)) {
return true
} else {
return false
}
}
addPermission(name) {
this.#sync()
for(var perms of this.permission) {
if(name == perms) {
ulog.warn("'" + this.username + "' a déjà la permission : " + name)
return false
}
}
this.permission.push(name)
this.register()
}
removePermission(name) {
this.#sync()
var havePermission = false
for(var perms of this.permission) {
if(name == perms) {
havePermission = true
}
}
if(havePermission) {
this.permission.splice(this.permission.indexOf(name), 1)
this.register()
} else {
ulog.warn("'" + this.username + "' n'a pas la permission : " + name)
return false
}
}
setPassword(newPassword) {
this.#sync()
@ -293,14 +227,6 @@ module.exports.User = class {
}
setPicture(text) {
this.#sync()
this.picture = text
this.register()
ulog.log("La photo de l'utilisateur a été modifié : " + this.username)
}
setDisplayName(text) {
this.#sync()
this.display_name = text
@ -325,24 +251,6 @@ module.exports.User = class {
this.register()
}
setPicture(file) {
this.#sync()
var pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
if(!fs.existsSync(__glob.USERS_IMAGES)) {
fs.mkdirSync(__glob.USERS_IMAGES)
}
fs.writeFileSync(pictureDir, file)
this.picture = pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/users/")
this.register()
}
setPermissions(permissions) {
this.#sync()
this.permission = permissions
this.register()
}
clearTokens() {
this.#sync()
this.tokens = []
@ -357,7 +265,6 @@ module.exports.User = class {
this.username = userFetched.username
this.password = userFetched.password
this.display_name = userFetched.display_name
this.permission = userFetched.permission
this.tokens = userFetched.tokens
this.lastLogin = userFetched.lastLogin
}
@ -382,23 +289,10 @@ module.exports.addUser = function(settings) {
return "ALREADY_EXIST"
} else {
ulog.step.init("add_user", "Ajout d'un utilisateur dans la base de donnée : " + settings.username)
var pictureDir = null
if(settings.picture == null) {
pictureDir = "/images/default.jpg"
} else {
pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
fs.writeFileSync(pictureDir, settings.picture)
}
const user = new this.User({
username: settings.username,
display_name: settings.display_name,
permission: settings.permissions,
picture: pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/images/users/")
display_name: settings.display_name
})
@ -451,13 +345,8 @@ module.exports.editUser = function(settings) {
user.setPassword(settings.password)
}
if(settings.picture) {
user.setPicture(settings.picture)
}
if(settings.permissions) {
user.setPermissions(settings.permissions)
}
ulog.step.end("edit_user")
return "OK"
} else {
@ -497,10 +386,7 @@ module.exports.editMySelf = function (settings, user) {
if(settings.password) {
user.setPassword(settings.password)
}
if(settings.picture) {
user.setPicture(settings.picture)
}
ulog.step.end("edit_user")
return "OK"
} else {