poter visualizzare i propri beni e servizi anche se non sei registrato alla app !

This commit is contained in:
Surya Paolo
2023-01-04 02:09:42 +01:00
parent 18b827f5f4
commit dd1c9d573f
5 changed files with 30 additions and 6 deletions

View File

@@ -16,6 +16,17 @@ const authenticate = (req, res, next) => {
// console.log('authenticate... '); // console.log('authenticate... ');
let noaut = false;
if (req.body.hasOwnProperty('noaut')) {
noaut = req.body.noaut;
}
if (noaut) {
next();
return;
}
const access = 'auth'; const access = 'auth';
User.findByToken(token, access).then((user) => { User.findByToken(token, access).then((user) => {

View File

@@ -101,6 +101,9 @@ const sendNotifSchema = new Schema({
sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) { sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) {
const SendNotif = this; const SendNotif = this;
if (!username)
return null;
try { try {
if (idnotif) { if (idnotif) {

View File

@@ -2695,6 +2695,15 @@ UserSchema.statics.getAskedFriendsByUsername = async function (idapp, username)
UserSchema.statics.getFriendsByUsername = async function (idapp, username) { UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
if (!username) {
return {
listFriends: [],
listRequestFriends: [],
listTrusted: [],
listSentRequestFriends: [],
}
}
try { try {
const whatToShow = getWhatToShow(idapp, username); const whatToShow = getWhatToShow(idapp, username);
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username); const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);

View File

@@ -558,7 +558,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
router.post('/gettable', authenticate, (req, res) => { router.post('/gettable', authenticate, (req, res) => {
const params = req.body; const params = req.body;
let idapp = req.user.idapp; let idapp = req.user ? req.user.idapp : params.idapp;
const mytable = globalTables.getTableByTableName(params.table); const mytable = globalTables.getTableByTableName(params.table);
// console.log('mytable', mytable); // console.log('mytable', mytable);
if (!mytable) { if (!mytable) {

View File

@@ -395,8 +395,9 @@ router.patch('/:id', authenticate, (req, res) => {
}); });
}); });
router.post('/profile', authenticate, (req, res) => { router.post('/profile', (req, res) => {
const usernameOrig = req.user.username; const usernameOrig = req.user ? req.user.username : '';
const perm = req.user ? req.user.perm : tools.Perm.PERM_NONE;
const username = req.body['username']; const username = req.body['username'];
const idapp = req.body.idapp; const idapp = req.body.idapp;
const locale = req.body.locale; const locale = req.body.locale;
@@ -409,11 +410,11 @@ router.post('/profile', authenticate, (req, res) => {
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : ''; const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif); SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
return User.getUserProfileByUsername(idapp, username, req.user.username, return User.getUserProfileByUsername(idapp, username, usernameOrig,
false, req.user.perm). false, perm).
then((ris) => { then((ris) => {
return User.getFriendsByUsername(idapp, req.user.username). return User.getFriendsByUsername(idapp, usernameOrig).
then((friends) => { then((friends) => {
res.send({ user: ris, friends }); res.send({ user: ris, friends });
}); });