Mise à jour de controleurs, models et routes

This commit is contained in:
Rampeur
2025-08-19 05:13:24 +02:00
parent f8d8ff2329
commit b1513dccdd
21 changed files with 905 additions and 113 deletions
+21 -20
View File
@@ -33,16 +33,16 @@ const UserModel = () => {
type: DataTypes.STRING(255),
allowNull: true
},
bio: {
type: DataTypes.TEXT,
phone: {
type: DataTypes.STRING(20),
allowNull: true
},
image: {
type: DataTypes.TEXT,
type: DataTypes.STRING(128),
allowNull: true
},
role: {
type: DataTypes.STRING(255),
type: DataTypes.STRING(20),
allowNull: true
},
salt: {
@@ -87,6 +87,14 @@ const UserModel = () => {
}
);
User.beforeCreate((user) => {
if (typeof user.username === 'undefined') {
user.username = `${user.firstname}_${user.lastname}`;
}
user.setPassword(user.password);
user.role = 'User';
});
User.prototype.validPassword = function (password) {
let hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
return this.hash === hash;
@@ -112,16 +120,13 @@ const UserModel = () => {
return {
id: this.id,
email: this.email,
role: this.role,
token: this.generateJWT(),
username: this.username,
firstname: this.firstname,
lastname: this.lastname,
/*phone: this.phone,
licence: this.licence,
poids: this.poids,*/
username: this.username,
image: this.image || '/assets/images/users/user.jpg',
bg_image: this.bg_image || '/assets/images/users/bg_user.jpg'
phone: this.phone,
image: this.image || '/assets/images/avatars/default.jpg',
role: this.role,
token: this.generateJWT()
};
};
@@ -132,24 +137,20 @@ const UserModel = () => {
username: this.username,
firstname: this.firstname,
lastname: this.lastname,
bio: this.bio,
phone: this.phone,
image: this.image,
role: this.role
};
};
User.prototype.toProfileJSONFor = function (user) {
User.prototype.toProfileJSONFor = function () {
return {
email: this.email,
username: this.username,
firstname: this.firstname,
lastname: this.lastname,
phone: this.phone,
licence: this.licence,
poids: this.poids,
username: this.username,
image: this.image || '/assets/images/users/user.jpg',
bg_image: this.bg_image || '/assets/images/users/bg_user.jpg',
following: user ? user.isFollowing(this.id) : false
image: this.image || '/assets/images/avatars/default.jpg'
};
};