mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Create new users management system.
This commit is contained in:
parent
239bfe896e
commit
d1c339c414
@ -133,6 +133,27 @@ function getMultipleUsersInfo(usersID, afterGetUserInfos, forceRequest){
|
||||
ComunicWeb.user.userInfos.getMultipleUsersInfo(usersID, afterGetUserInfos, forceRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about multiple users
|
||||
*
|
||||
* @param {Array~Object} users The list of users to get
|
||||
* @param {Boolean} force
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function getUsers(users, force) {
|
||||
return new Promise((resolve, error) => {
|
||||
getMultipleUsersInfo(users, result => {
|
||||
|
||||
if(result.error)
|
||||
error(result.error);
|
||||
|
||||
else
|
||||
resolve(new UsersList(result));
|
||||
|
||||
}, force);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a single user
|
||||
*
|
||||
|
70
assets/js/user/usersList.js
Normal file
70
assets/js/user/usersList.js
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Users list
|
||||
*
|
||||
* Contains a list of users
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
/**
|
||||
* User class - contains information about a single user
|
||||
*/
|
||||
class User {
|
||||
constructor(info){
|
||||
this.virtualDirectory = info.virtualDirectory;
|
||||
this.image = info.accountImage;
|
||||
this.firstName = info.firstName;
|
||||
this.lastName = info.lastName;
|
||||
this.isOpen = info.openPage == "true";
|
||||
this.isPublic = info.publicPage == "true";
|
||||
this.id = info.userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full name of the user
|
||||
*/
|
||||
get fullName() {
|
||||
return this.firstName + " " + this.lastName;
|
||||
}
|
||||
}
|
||||
|
||||
class UsersList {
|
||||
|
||||
/**
|
||||
* Initialize a list of users using the legacy users system
|
||||
*
|
||||
* @param {Users} list The list of users to add
|
||||
*/
|
||||
constructor(list){
|
||||
|
||||
/**
|
||||
* @type {User[]}
|
||||
*/
|
||||
this.list = [];
|
||||
|
||||
for (const num in list) {
|
||||
if (list.hasOwnProperty(num)) {
|
||||
this.list.push(new User(list[num]));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find and returns a user specified by its ID
|
||||
*
|
||||
* @param {Number} id The ID of the user to get
|
||||
* @return {User} target user / null in case of failure
|
||||
*/
|
||||
get(id){
|
||||
for (const num in this.list) {
|
||||
if (this.list.hasOwnProperty(num)) {
|
||||
const user = this.list[num];
|
||||
|
||||
if(user.id == id)
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -471,6 +471,7 @@ class Dev {
|
||||
"js/user/loginTokens.js",
|
||||
"js/user/userLogin.js",
|
||||
"js/user/userInfos.js",
|
||||
"js/user/usersList.js",
|
||||
|
||||
|
||||
//Pages scripts
|
||||
|
Loading…
Reference in New Issue
Block a user