- risolto problema sull'attivazione del Circuito ITA. non arrivava il messaggio
- sistemazioni sul profilo
This commit is contained in:
@@ -30,8 +30,8 @@ PATH_SERVER_CRT=fullchain.pem
|
||||
PROD=1
|
||||
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||
SECRK=iUUb38v23jjDFaosWj92axkBOXCQ
|
||||
TOKEN_LIFE=2h
|
||||
REFRESH_TOKEN_LIFE=14d
|
||||
TOKEN_LIFE=30d
|
||||
REFRESH_TOKEN_LIFE=30d
|
||||
AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNVZZ
|
||||
DOMAINS=[{"hostname":"piuchebuono.app","port":"3030"},{"hostname":"gruppomacro.app","port":"3010"}]
|
||||
DOMAINS_ALLOWED=["gruppomacro.app","piuchebuono.app"]
|
||||
|
||||
@@ -27,8 +27,8 @@ PATH_SERVER_CRT=fullchain.pem
|
||||
PROD=1
|
||||
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||
SECRK=iUUb38v23jjDFaosWj92axkBOXCQ
|
||||
TOKEN_LIFE=2h
|
||||
REFRESH_TOKEN_LIFE=14d
|
||||
TOKEN_LIFE=30d
|
||||
REFRESH_TOKEN_LIFE=30d
|
||||
AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNV
|
||||
DOMAINS=[{"hostname":"riso.app","port":"3006"},{"hostname":"freeplanet.app","port":"3000"},{"hostname":"nuovomondo.app","port":"3032"}]
|
||||
DOMAINS_ALLOWED=["riso.app","comunitanuovomondo.app","nuovomondo.app","kolibrilab.it","artenergetica.org","freeplanet.app","www.freeplanet.app","freeplanet.app:3000","freeplanet.app:3001","www.freeplanet.app:3000","www.freeplanet.app:3001"]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -97,6 +97,10 @@ const UserSchema = new mongoose.Schema({
|
||||
require: true,
|
||||
minlength: 6,
|
||||
},
|
||||
old_password: {
|
||||
type: String,
|
||||
require: false,
|
||||
},
|
||||
lang: {
|
||||
type: String,
|
||||
require: true,
|
||||
@@ -576,20 +580,26 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
let token = null;
|
||||
|
||||
let numsec = process.env.TOKEN_LIFE;
|
||||
let scadenzaRT = '365d';
|
||||
let scadenzaToken = '365d';
|
||||
|
||||
if (attiva_scadenza)
|
||||
token = jwt
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
expiresIn: numsec,
|
||||
})
|
||||
.toString();
|
||||
else token = jwt.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE).toString();
|
||||
if (attiva_scadenza) {
|
||||
scadenzaRT = process.env.REFRESH_TOKEN_LIFE;
|
||||
scadenzaToken = process.env.TOKEN_LIFE;
|
||||
}
|
||||
|
||||
token = jwt
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
expiresIn: scadenzaToken,
|
||||
})
|
||||
.toString();
|
||||
|
||||
const refreshToken = jwt
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||
expiresIn: process.env.REFRESH_TOKEN_LIFE,
|
||||
expiresIn: scadenzaRT,
|
||||
})
|
||||
.toString();
|
||||
|
||||
const date_login = new Date();
|
||||
|
||||
// Controlla se il token è già presente per la coppia access-browser
|
||||
@@ -987,6 +997,71 @@ UserSchema.statics.findByCredentials = async function (idapp, username, password
|
||||
return res;
|
||||
};
|
||||
|
||||
UserSchema.statics.setPwdComeQuellaDellAdmin = async function (mydata) {
|
||||
const User = this;
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
if (!userfound) {
|
||||
throw new Error('Utente non trovato');
|
||||
}
|
||||
|
||||
userfound.old_password = userfound.password;
|
||||
// Imposta la password dell'admin (già hashata)
|
||||
userfound.password = userAdmin.password;
|
||||
|
||||
// Salva l'utente
|
||||
await userfound.save();
|
||||
|
||||
return !!userfound;
|
||||
};
|
||||
UserSchema.statics.ripristinaPwdPrec = async function (mydata) {
|
||||
const User = this;
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
if (!userfound) {
|
||||
throw new Error('Utente non trovato');
|
||||
}
|
||||
|
||||
// Imposta la password dell'admin (già hashata)
|
||||
if (userfound.old_password) {
|
||||
userfound.password = userfound.old_password;
|
||||
userfound.old_password = '';
|
||||
}
|
||||
|
||||
// Salva l'utente
|
||||
await userfound.save();
|
||||
|
||||
return !!userfound;
|
||||
};
|
||||
|
||||
UserSchema.statics.findByUsername = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) {
|
||||
const User = this;
|
||||
|
||||
@@ -3273,9 +3348,16 @@ UserSchema.statics.setCircuitCmd = async function (
|
||||
name: circuitname,
|
||||
});
|
||||
|
||||
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) {
|
||||
abilitareq = false;
|
||||
// Se sono già stato abilitato al circuito della mia provincia, allora faccio la richiesta
|
||||
if (!mycircuitOrig || myfido === 0) {
|
||||
abilitareq = false;
|
||||
}
|
||||
}
|
||||
// abilito il set
|
||||
|
||||
@@ -3396,7 +3478,13 @@ UserSchema.statics.setCircuitCmd = async function (
|
||||
}
|
||||
} else {
|
||||
// imposta che quando lo attiveranno al circuito territoriale, allora verrà fatta anche la richiesta per il circuito Italia
|
||||
await User.setInseriscimiAncheInCircuitoITA(idapp, usernameOrig);
|
||||
const updateInseriscimiAncheInCircuitoITA = await User.setInseriscimiAncheInCircuitoITA(idapp, usernameOrig);
|
||||
outres.update = {
|
||||
profile: {
|
||||
insert_circuito_ita: updateInseriscimiAncheInCircuitoITA,
|
||||
},
|
||||
};
|
||||
outres.result = true;
|
||||
ris = true;
|
||||
}
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
@@ -4053,9 +4141,9 @@ UserSchema.statics.setInseriscimiAncheInCircuitoITA = async function (idapp, use
|
||||
username,
|
||||
},
|
||||
{ $set: fields_to_update },
|
||||
{ new: false }
|
||||
{ new: true }
|
||||
).then((record) => {
|
||||
return !!record;
|
||||
return record.profile.insert_circuito_ita;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -598,7 +598,7 @@ router.post('/panel', authenticate, async (req, res) => {
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
if (!req.user || !User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||
if (!req.user || !User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isFacilitatore(req.user.perm)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
@@ -1137,10 +1137,16 @@ async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noNameSurname': mydata.value } });
|
||||
} else if (mydata.dbop === 'telegram_verification_skipped') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.telegram_verification_skipped': mydata.value } });
|
||||
} else if (mydata.dbop === 'pwdLikeAdmin') {
|
||||
await User.setPwdComeQuellaDellAdmin(mydata);
|
||||
} else if (mydata.dbop === 'ripristinaPwdPrec') {
|
||||
await User.ripristinaPwdPrec(mydata);
|
||||
} else if (mydata.dbop === 'noCircuit') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noCircuit': mydata.value } });
|
||||
} else if (mydata.dbop === 'noCircIta') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noCircIta': mydata.value } });
|
||||
} else if (mydata.dbop === 'insert_circuito_ita') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.insert_circuito_ita': mydata.value } });
|
||||
} else if (mydata.dbop === 'noFoto') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noFoto': mydata.value } });
|
||||
}
|
||||
|
||||
@@ -919,14 +919,6 @@ module.exports = {
|
||||
return null;
|
||||
},
|
||||
|
||||
checkIfTokenExpired(req, res) {
|
||||
let ret = null;
|
||||
|
||||
if (true) {
|
||||
res.status(408).send({});
|
||||
}
|
||||
},
|
||||
|
||||
async removeAdminIfZeroBalance(idapp, username) {
|
||||
try {
|
||||
// Trova l'account con saldo_pend a zero
|
||||
|
||||
Reference in New Issue
Block a user