- fix: se inserisco un username telegram di chi mi ha invitato, non facevo il controllo.
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
DATABASE=test_PiuCheBuono
|
DATABASE=test_FreePlanet
|
||||||
UDB=paofreeplanet
|
UDB=paofreeplanet
|
||||||
PDB=mypassword@1A
|
PDB=mypassword@1A
|
||||||
SEND_EMAIL=0
|
SEND_EMAIL=0
|
||||||
SEND_EMAIL_ORDERS=1
|
SEND_EMAIL_ORDERS=1
|
||||||
PORT=3000
|
PORT=3000
|
||||||
appTelegram_TEST=["1","17"]
|
appTelegram_TEST=["1","13"]
|
||||||
appTelegram=["1","17"]
|
appTelegram=["1","13"]
|
||||||
DOMAIN=mongodb://localhost:27017/
|
DOMAIN=mongodb://localhost:27017/
|
||||||
AUTH_MONGODB=true
|
AUTH_MONGODB=true
|
||||||
MONGODB_USER=admin
|
MONGODB_USER=admin
|
||||||
|
|||||||
@@ -876,6 +876,57 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail,
|
|||||||
return rec;
|
return rec;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Find a user by their Telegram username.
|
||||||
|
*
|
||||||
|
* @param {string} idapp - The application ID
|
||||||
|
* @param {string} username - The Telegram username
|
||||||
|
* @param {boolean} alsoemail - Flag to indicate if email should also be considered
|
||||||
|
* @param {boolean} onlyifVerifiedByAportador - Flag to indicate if only verified users should be returned
|
||||||
|
* @return {Promise} A Promise that resolves to the found user or null
|
||||||
|
**/
|
||||||
|
|
||||||
|
UserSchema.statics.findByUsernameTelegram = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
if (username && username[0] === '@') {
|
||||||
|
username = username.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const myreg = ['^', username, '$'].join('');
|
||||||
|
let regexusername = new RegExp(myreg, 'i');
|
||||||
|
|
||||||
|
//++TODO: Set only the necessary fields to get in memory
|
||||||
|
|
||||||
|
return await User.findOne({
|
||||||
|
idapp: idapp,
|
||||||
|
'profile.username_telegram': { $regex: regexusername },
|
||||||
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||||
|
}).then(async (ris) => {
|
||||||
|
if ((!ris) && (alsoemail)) {
|
||||||
|
regexemail = new RegExp(['^', username.toLowerCase(), '$'].join(''), 'i');
|
||||||
|
|
||||||
|
return await User.findOne({
|
||||||
|
'idapp': idapp,
|
||||||
|
'email': { $regex: regexemail },
|
||||||
|
$or: [
|
||||||
|
{ deleted: { $exists: false } },
|
||||||
|
{ deleted: { $exists: true, $eq: false } }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ris;
|
||||||
|
}).then((rec) => {
|
||||||
|
if (rec && onlyifVerifiedByAportador) {
|
||||||
|
if (tools.getAskToVerifyReg(idapp)) {
|
||||||
|
if (!rec.verified_by_aportador)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rec;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.getProjectUser = function () {
|
UserSchema.statics.getProjectUser = function () {
|
||||||
return {
|
return {
|
||||||
@@ -1728,6 +1779,20 @@ UserSchema.statics.getUserByUsername = function (idapp, username) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getUserByUsernameTelegram = function (idapp, username_telegram) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
if (username_telegram[0] === '@'){
|
||||||
|
username_telegram = username_telegram.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return User.findOne({
|
||||||
|
idapp,
|
||||||
|
'profile.username_telegram': username_telegram,
|
||||||
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.isMyFriend = async function (idapp, username, myusername) {
|
UserSchema.statics.isMyFriend = async function (idapp, username, myusername) {
|
||||||
|
|
||||||
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
|
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
|
||||||
|
|||||||
@@ -266,8 +266,16 @@ router.post('/', async (req, res) => {
|
|||||||
|
|
||||||
user.aportador_solidario = user.aportador_solidario.trim();
|
user.aportador_solidario = user.aportador_solidario.trim();
|
||||||
|
|
||||||
const id_aportador = await User.getIdByUsername(user.idapp, user.aportador_solidario);
|
let id_aportador = await User.getIdByUsername(user.idapp, user.aportador_solidario);
|
||||||
|
if (!id_aportador) {
|
||||||
|
// Cerca se esiste l'aportador solidario con l'username Telegram
|
||||||
|
const useraportador = await User.getUserByUsernameTelegram(user.idapp, user.aportador_solidario);
|
||||||
|
id_aportador = useraportador._id;
|
||||||
|
user.aportador_solidario = useraportador.username;
|
||||||
|
}
|
||||||
|
|
||||||
if (id_aportador) {
|
if (id_aportador) {
|
||||||
|
// Ottiene l'username "corretto" (senza maiuscole o minuscole)
|
||||||
user.aportador_solidario = await User.getRealUsernameByUsername(user.idapp, user.aportador_solidario);
|
user.aportador_solidario = await User.getRealUsernameByUsername(user.idapp, user.aportador_solidario);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,8 +389,10 @@ router.get('/:idapp/:username', async (req, res) => {
|
|||||||
// return res.status(200).send();
|
// return res.status(200).send();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
await User.findByUsername(idapp, username, false, true).then((user) => {
|
await User.findByUsername(idapp, username, false, true).then(async (user) => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
user = await User.findByUsernameTelegram(idapp, username, false, true);
|
||||||
|
if (!user)
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
// console.log('TROVATO!')
|
// console.log('TROVATO!')
|
||||||
@@ -390,6 +400,7 @@ router.get('/:idapp/:username', async (req, res) => {
|
|||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
return res.status(400).send();
|
return res.status(400).send();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch('/:id', authenticate, (req, res) => {
|
router.patch('/:id', authenticate, (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user