- sistemazioni Email : registrazione, invio invito, email di benvenuto
- fix circuito - profilo
This commit is contained in:
@@ -197,7 +197,6 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario: {
|
||||
// da cancellare
|
||||
type: String,
|
||||
},
|
||||
verified_by_aportador: {
|
||||
@@ -599,7 +598,7 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
expiresIn: scadenzaRT,
|
||||
})
|
||||
.toString();
|
||||
|
||||
|
||||
const date_login = new Date();
|
||||
|
||||
// Controlla se il token è già presente per la coppia access-browser
|
||||
@@ -855,7 +854,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
code = server_constants.RIS_CODE_OK;
|
||||
} catch (err) {
|
||||
if (err.expiredAt) {
|
||||
code = server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED;
|
||||
code = server_constants.RIS_CODE_HTTP_TOKEN_EXPIRED;
|
||||
if (con_auth) return { user: null, code };
|
||||
} else {
|
||||
console.error('Err findByToken:', err);
|
||||
@@ -888,7 +887,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
|
||||
if (checkExpiry && decoded.exp < currentTime) {
|
||||
console.log('🔴 Il token è scaduto, generazione del nuovo token...');
|
||||
code = server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED;
|
||||
code = server_constants.RIS_CODE_HTTP_TOKEN_EXPIRED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1000,19 +999,18 @@ UserSchema.statics.findByCredentials = async function (idapp, username, password
|
||||
UserSchema.statics.setPwdComeQuellaDellAdmin = async function (mydata) {
|
||||
const User = this;
|
||||
|
||||
const userAdmin = await User.findOne({
|
||||
_id: mydata.myuserId
|
||||
const userAdmin = await User.findOne({
|
||||
_id: mydata.myuserId,
|
||||
});
|
||||
|
||||
|
||||
// Verifica permessi admin
|
||||
if (!User.isAdmin(userAdmin.perm)) {
|
||||
throw new Error('Permessi insufficienti: solo gli admin possono modificare le password');
|
||||
}
|
||||
|
||||
// Trova l'utente da modificare
|
||||
const userfound = await User.findOne({
|
||||
_id: mydata._id
|
||||
const userfound = await User.findOne({
|
||||
_id: mydata._id,
|
||||
});
|
||||
|
||||
if (!userfound) {
|
||||
@@ -1022,7 +1020,7 @@ UserSchema.statics.setPwdComeQuellaDellAdmin = async function (mydata) {
|
||||
userfound.old_password = userfound.password;
|
||||
// Imposta la password dell'admin (già hashata)
|
||||
userfound.password = userAdmin.password;
|
||||
|
||||
|
||||
// Salva l'utente
|
||||
await userfound.save();
|
||||
|
||||
@@ -1031,19 +1029,18 @@ UserSchema.statics.setPwdComeQuellaDellAdmin = async function (mydata) {
|
||||
UserSchema.statics.ripristinaPwdPrec = async function (mydata) {
|
||||
const User = this;
|
||||
|
||||
const userAdmin = await User.findOne({
|
||||
_id: mydata.myuserId
|
||||
const userAdmin = await User.findOne({
|
||||
_id: mydata.myuserId,
|
||||
});
|
||||
|
||||
|
||||
// Verifica permessi admin
|
||||
if (!User.isAdmin(userAdmin.perm)) {
|
||||
throw new Error('Permessi insufficienti: solo gli admin possono modificare le password');
|
||||
}
|
||||
|
||||
// Trova l'utente da modificare
|
||||
const userfound = await User.findOne({
|
||||
_id: mydata._id
|
||||
const userfound = await User.findOne({
|
||||
_id: mydata._id,
|
||||
});
|
||||
|
||||
if (!userfound) {
|
||||
@@ -1055,7 +1052,7 @@ UserSchema.statics.ripristinaPwdPrec = async function (mydata) {
|
||||
userfound.password = userfound.old_password;
|
||||
userfound.old_password = '';
|
||||
}
|
||||
|
||||
|
||||
// Salva l'utente
|
||||
await userfound.save();
|
||||
|
||||
@@ -2281,6 +2278,15 @@ UserSchema.statics.getUsernameCircuitsByUsername = async function (idapp, userna
|
||||
};
|
||||
|
||||
// Rimuovo l'Amicizia
|
||||
UserSchema.statics.removeUser = async function (id) {
|
||||
const User = this;
|
||||
|
||||
if (id) {
|
||||
return await User.deleteMany({ _id: id });
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
UserSchema.statics.removeFriend = async function (idapp, username, usernameDest) {
|
||||
return await User.updateOne(
|
||||
{ idapp, username },
|
||||
@@ -2828,6 +2834,10 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.DELETE_USER) {
|
||||
const id = await User.findOne({ idapp, username: usernameDest }, { username: 1 });
|
||||
// Cancella Utente
|
||||
ris = await User.removeUser(id);
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.UNBLOCK_USER) {
|
||||
username_worked = usernameDest;
|
||||
|
||||
@@ -3351,13 +3361,13 @@ UserSchema.statics.setCircuitCmd = async function (
|
||||
const mycircuitOrig = await Circuit.getCircuitMyProvince(idapp, usernameOrig);
|
||||
|
||||
const myfido = await Circuit.getFido(idapp, usernameOrig, mycircuitOrig, '');
|
||||
|
||||
|
||||
// se è il circuito Italia e !extrarec.abilitoveramente allora
|
||||
if (thiscircuit.isCircItalia && !extrarec.abilitaveramente) {
|
||||
// Se sono già stato abilitato al circuito della mia provincia, allora faccio la richiesta
|
||||
if (!mycircuitOrig || myfido === 0) {
|
||||
abilitareq = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// abilito il set
|
||||
|
||||
@@ -4285,6 +4295,31 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username, r
|
||||
console.error('getNameSurnameByUsername', e);
|
||||
});
|
||||
};
|
||||
UserSchema.statics.getNameSurnameEUsernameByUsername = async function (idapp, username, reale = false) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne(
|
||||
{
|
||||
idapp,
|
||||
username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
{ username: 1, name: 1, surname: 1 }
|
||||
)
|
||||
.then((rec) => {
|
||||
let ris = rec.username;
|
||||
if (!!rec) {
|
||||
if (reale) {
|
||||
if (!rec.name) return '';
|
||||
}
|
||||
ris = rec.name ? `${rec.name} ${rec.surname} - ${rec.username}` : `${rec.username}`;
|
||||
}
|
||||
return !!rec ? ris : '';
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('getNameSurnameByUsername', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getIdByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
Reference in New Issue
Block a user