En-/decryption fixed
This commit is contained in:
@@ -7,6 +7,7 @@ export const register = async (req, res) => {
|
||||
const result = await userService.registerUser({ email, username, password, language });
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,20 +8,23 @@ const menuStructure = {
|
||||
home: {
|
||||
visible: ["all"],
|
||||
children: {},
|
||||
path: "/"
|
||||
path: "/",
|
||||
icon: "logo_mono.png"
|
||||
},
|
||||
friends: {
|
||||
visible: ["all"],
|
||||
children: {
|
||||
manageFriends : {
|
||||
visible: ["all"],
|
||||
path: "/socialnetwork/friends"
|
||||
path: "/socialnetwork/friends",
|
||||
icon: "friends24.png"
|
||||
}
|
||||
},
|
||||
showLoggedinFriends: 1
|
||||
},
|
||||
socialnetwork: {
|
||||
visible: ["all"],
|
||||
icon: "socialnetwork.png",
|
||||
children: {
|
||||
guestbook: {
|
||||
visible: ["all"],
|
||||
@@ -56,6 +59,7 @@ const menuStructure = {
|
||||
},
|
||||
chats: {
|
||||
visible: ["over12"],
|
||||
icon: "chat.png",
|
||||
children: {
|
||||
multiChat: {
|
||||
visible: ["over12"],
|
||||
@@ -69,6 +73,7 @@ const menuStructure = {
|
||||
},
|
||||
falukant: {
|
||||
visible: ["all"],
|
||||
icon: "falukant24.png",
|
||||
children: {
|
||||
create: {
|
||||
visible: ["nofalukantaccount"],
|
||||
@@ -130,9 +135,11 @@ const menuStructure = {
|
||||
},
|
||||
minigames: {
|
||||
visible: ["all"],
|
||||
icon: "minigames24.png",
|
||||
},
|
||||
settings: {
|
||||
visible: ["all"],
|
||||
icon: "settings24.png",
|
||||
children: {
|
||||
homepage: {
|
||||
visible: ["all"],
|
||||
@@ -156,7 +163,7 @@ const menuStructure = {
|
||||
},
|
||||
sexuality: {
|
||||
visible: ["over14"],
|
||||
path: "/setting/sexuality"
|
||||
path: "/settings/sexuality"
|
||||
},
|
||||
notifications: {
|
||||
visible: ["all"],
|
||||
|
||||
@@ -3,10 +3,40 @@ import SettingsType from '../models/type/settings.js';
|
||||
import UserParam from '../models/community/user_param.js';
|
||||
import User from '../models/community/user.js';
|
||||
import UserParamValue from '../models/type/user_param_value.js';
|
||||
import { calculateAge } from '../utils/userdata.js';
|
||||
import { DataTypes, Op } from 'sequelize';
|
||||
import { decrypt } from '../utils/encryption.js';
|
||||
|
||||
export const filterSettings = async (req, res) => {
|
||||
const { userid, type } = req.body;
|
||||
try {
|
||||
const user = await User.findOne({ where: { hashedId: userid } });
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
const userParams = await UserParam.findAll({
|
||||
where: { userId: user.id },
|
||||
include: [
|
||||
{
|
||||
model: UserParamType,
|
||||
as: 'paramType'
|
||||
}
|
||||
]
|
||||
});
|
||||
let birthdate = null;
|
||||
let gender = null;
|
||||
|
||||
for (const param of userParams) {
|
||||
console.log(param.paramType.description);
|
||||
if (param.paramType.description === 'birthdate') {
|
||||
birthdate = param.value;
|
||||
}
|
||||
if (param.paramType.description === 'gender') {
|
||||
const genderResult = await UserParamValue.findOne({ where: { id: param.value } });
|
||||
gender = genderResult.dataValues.value;
|
||||
}
|
||||
}
|
||||
const age = birthdate ? calculateAge(birthdate) : null;
|
||||
const fields = await UserParamType.findAll({
|
||||
include: [
|
||||
{
|
||||
@@ -26,9 +56,14 @@ export const filterSettings = async (req, res) => {
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ minAge: { [Op.or]: [null, { [Op.lte]: age }] } },
|
||||
{ gender: { [Op.or]: [null, gender] } }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const responseFields = await Promise.all(fields.map(async (field) => {
|
||||
const options = ['singleselect', 'multiselect'].includes(field.datatype) ? await UserParamValue.findAll({
|
||||
where: { userParamTypeId: field.id }
|
||||
@@ -44,11 +79,10 @@ export const filterSettings = async (req, res) => {
|
||||
options: options.map(opt => ({ id: opt.id, value: opt.value }))
|
||||
};
|
||||
}));
|
||||
|
||||
res.status(200).json(responseFields);
|
||||
} catch (error) {
|
||||
console.error('Error fetching settings:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
console.error('Error filtering settings:', error);
|
||||
res.status(500).json({ error: 'An error occurred while filtering the settings' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,4 +142,33 @@ export const getTypeParamValue = async(req, res) => {
|
||||
return;
|
||||
}
|
||||
res.status(200).json({ paramValueId: userParamValueObject.value });
|
||||
};
|
||||
};
|
||||
|
||||
export const getAccountSettings = async (req, res) => {
|
||||
try {
|
||||
const user = await User.findOne({ where: { hashedId: req.body.userId } });
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
const email = user.email;
|
||||
res.status(200).json({ username: user.username, email, showinsearch: user.searchable });
|
||||
} catch (error) {
|
||||
console.error('Error retrieving account settings:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const setAccountSettings = async(req, res) => {
|
||||
const { userid: userId, username, email, searchable, oldpassword, newpassword, newpasswordrepeat } = req.body;
|
||||
const user = await User.findOne({ where: { hashedId: userId }});
|
||||
if (!user) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
user.searchable = searchable;
|
||||
if (user.password !== oldpassword) {
|
||||
res.status(401).json({error: 'Wrong password'});
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user