Added movability of dialogs
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"CodeGPT.query.language": "German"
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import chatRouter from './routers/chatRouter.js';
|
||||
import authRouter from './routers/authRouter.js';
|
||||
import navigationRouter from './routers/navigationRouter.js';
|
||||
import settingsRouter from './routers/settingsRouter.js';
|
||||
import adminRouter from './routers/adminRouter.js';
|
||||
import contactRouter from './routers/contactRouter.js';
|
||||
import cors from 'cors';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -26,7 +28,9 @@ app.use('/api/chat', chatRouter);
|
||||
app.use('/api/auth', authRouter);
|
||||
app.use('/api/navigation', navigationRouter);
|
||||
app.use('/api/settings', settingsRouter);
|
||||
app.use('/api/admin', adminRouter);
|
||||
app.use('/images', express.static(path.join(__dirname, '../frontend/public/images')));
|
||||
app.use('/api/contact', contactRouter);
|
||||
|
||||
app.use((req, res) => {
|
||||
res.status(404).send('404 Not Found');
|
||||
|
||||
44
backend/controllers/adminController.js
Normal file
44
backend/controllers/adminController.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import AdminService from '../services/adminService.js';
|
||||
|
||||
export const getOpenInterests = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId} = req.headers;
|
||||
const openInterests = await AdminService.getOpenInterests(userId);
|
||||
res.status(200).json(openInterests);
|
||||
} catch (error) {
|
||||
res.status(403).json({error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
export const changeInterest = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { id: interestId, active, adult: adultOnly} = req.body;
|
||||
AdminService.changeInterest(userId, interestId, active, adultOnly);
|
||||
res.status(200).json(AdminService.getOpenInterests(userId));
|
||||
} catch (error) {
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteInterest = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { id: interestId } = req.params;
|
||||
AdminService.deleteInterest(userId, interestId);
|
||||
res.status(200).json(AdminService.getOpenInterests(userId));
|
||||
} catch (error) {
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
export const changeTranslation = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { id: interestId, translations } = req.body;
|
||||
AdminService.changeTranslation(userId, interestId, translations);
|
||||
res.status(200).json(AdminService.getOpenInterests(userId))
|
||||
} catch(error) {
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
11
backend/controllers/contactController.js
Normal file
11
backend/controllers/contactController.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import ContactService from '../services/ContactService.js';
|
||||
|
||||
export const addContactMessage = async(req, res) => {
|
||||
try {
|
||||
const { email, name, message, acceptDataSave } = req.body;
|
||||
await ContactService.addContactMessage(email, name, message, acceptDataSave);
|
||||
res.status(200).json({ status: 'ok' });
|
||||
} catch (error) {
|
||||
res.status(409).json({ error: error });
|
||||
}
|
||||
}
|
||||
@@ -157,9 +157,9 @@ const menuStructure = {
|
||||
visible: ["all"],
|
||||
path: "/settings/view"
|
||||
},
|
||||
interrests: {
|
||||
interests: {
|
||||
visible: ["all"],
|
||||
path: "/settings/interrests"
|
||||
path: "/settings/interests"
|
||||
},
|
||||
sexuality: {
|
||||
visible: ["over14"],
|
||||
@@ -190,9 +190,9 @@ const menuStructure = {
|
||||
visible: ["mainadmin", "rights"],
|
||||
path: "/admin/rights"
|
||||
},
|
||||
interrests: {
|
||||
visible: ["mainadmin", "interrests"],
|
||||
path: "/admin/interrests"
|
||||
interests: {
|
||||
visible: ["mainadmin", "interests"],
|
||||
path: "/admin/interests"
|
||||
},
|
||||
falukant: {
|
||||
visible: ["mainadmin", "falukant"],
|
||||
@@ -255,7 +255,8 @@ export const menu = async (req, res) => {
|
||||
where: { userId: user.id },
|
||||
include: [{
|
||||
model: UserRightType,
|
||||
as: 'rightType'
|
||||
as: 'rightType',
|
||||
required: false
|
||||
}]
|
||||
});
|
||||
const userBirthdateParams = await UserParam.findAll({
|
||||
|
||||
@@ -1,84 +1,9 @@
|
||||
import UserParamType from '../models/type/user_param.js';
|
||||
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';
|
||||
import settingsService from '../services/settingsService.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: [
|
||||
{
|
||||
model: SettingsType,
|
||||
as: 'settings_type',
|
||||
where: { name: type }
|
||||
},
|
||||
{
|
||||
model: UserParam,
|
||||
as: 'user_params',
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: User,
|
||||
as: 'user',
|
||||
where: { hashedId: userid }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
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 }
|
||||
}) : [];
|
||||
|
||||
return {
|
||||
id: field.id,
|
||||
name: field.description,
|
||||
minAge: field.minAge,
|
||||
gender: field.gender,
|
||||
datatype: field.datatype,
|
||||
value: field.user_params.length > 0 ? field.user_params[0].value : null,
|
||||
options: options.map(opt => ({ id: opt.id, value: opt.value }))
|
||||
};
|
||||
}));
|
||||
const responseFields = await settingsService.filterSettings(userid, type);
|
||||
res.status(200).json(responseFields);
|
||||
} catch (error) {
|
||||
console.error('Error filtering settings:', error);
|
||||
@@ -89,16 +14,7 @@ export const filterSettings = async (req, res) => {
|
||||
export const updateSetting = async (req, res) => {
|
||||
const { userid, settingId, value } = req.body;
|
||||
try {
|
||||
const user = await User.findOne({ where: { hashedId: userid } });
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
|
||||
const paramType = await UserParamType.findOne({ where: { id: settingId } });
|
||||
if (!paramType) {
|
||||
return res.status(404).json({ error: 'Parameter type not found' });
|
||||
}
|
||||
await UserParam.upsertParam(user.id, paramType.id, value);
|
||||
await settingsService.updateSetting(userid, settingId, value);
|
||||
res.status(200).json({ message: 'Setting updated successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error updating user setting:', error);
|
||||
@@ -106,69 +22,114 @@ export const updateSetting = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getTypeParamValueId = async(req, res) => {
|
||||
export const getTypeParamValueId = async (req, res) => {
|
||||
const { paramValue } = req.body;
|
||||
const userParamValueObject = await UserParamValue.findOne({
|
||||
where: { value: paramValue }
|
||||
});
|
||||
if (!userParamValueObject) {
|
||||
try {
|
||||
const paramValueId = await settingsService.getTypeParamValueId(paramValue);
|
||||
res.status(200).json({ paramValueId });
|
||||
} catch (error) {
|
||||
console.error('Error retrieving parameter value ID:', error);
|
||||
res.status(404).json({ error: "notfound" });
|
||||
return;
|
||||
}
|
||||
res.status(200).json({ paramValueId: userParamValueObject.id });
|
||||
};
|
||||
|
||||
export const getTypeParamValues = async(req, res) => {
|
||||
export const getTypeParamValues = async (req, res) => {
|
||||
const { type } = req.body;
|
||||
const userParamValues = await UserParamValue.findAll({
|
||||
include: [
|
||||
{
|
||||
model: UserParamType,
|
||||
as: 'user_param_type',
|
||||
where: { description: type }
|
||||
try {
|
||||
const paramValues = await settingsService.getTypeParamValues(type);
|
||||
res.status(200).json(paramValues);
|
||||
} catch (error) {
|
||||
console.error('Error retrieving parameter values:', error);
|
||||
res.status(500).json({ error: 'An error occurred while retrieving the parameter values' });
|
||||
}
|
||||
]
|
||||
});
|
||||
res.status(200).json(userParamValues.map(type => { return { id: type.dataValues.id, name: type.dataValues.value}}));
|
||||
}
|
||||
|
||||
export const getTypeParamValue = async(req, res) => {
|
||||
const { id } = req.param;
|
||||
const userParamValueObject = await UserParamValue.findOne({
|
||||
where: { id: id }
|
||||
});
|
||||
if (!userParamValueObject) {
|
||||
export const getTypeParamValue = async (req, res) => {
|
||||
const { id } = req.params;
|
||||
try {
|
||||
const paramValue = await settingsService.getTypeParamValue(id);
|
||||
res.status(200).json({ paramValue });
|
||||
} catch (error) {
|
||||
console.error('Error retrieving parameter value:', error);
|
||||
res.status(404).json({ error: "notfound" });
|
||||
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 });
|
||||
const { userId } = req.body;
|
||||
const accountSettings = await settingsService.getAccountSettings(userId);
|
||||
res.status(200).json(accountSettings);
|
||||
} 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;
|
||||
export const setAccountSettings = async (req, res) => {
|
||||
try {
|
||||
await settingsService.setAccountSettings(req.body);
|
||||
res.status(200).json({ message: 'Account settings updated successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error updating account settings:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const getPossibleInterests = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const interests = await settingsService.getPossibleInterests(userId);
|
||||
res.status(200).json(interests);
|
||||
} catch (error) {
|
||||
console.error('Error retrieving possible interests:', error);
|
||||
res.status(500).json({ error: 'An error occurred while retrieving the possible interests' });
|
||||
}
|
||||
}
|
||||
|
||||
export const getInterests = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const interests = await settingsService.getInterests(userId);
|
||||
res.status(200).json(interests);
|
||||
} catch (error) {
|
||||
console.error('Error retrieving interests:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export const addInterest = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { name } = req.body;
|
||||
const interest = await settingsService.addInterest(userId, name);
|
||||
res.status(200).json({ interest });
|
||||
} catch (error) {
|
||||
console.error('Error adding interest:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export const addUserInterest = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { interestid: interestId } = req.body;
|
||||
await settingsService.addUserInterest(userId, interestId);
|
||||
res.status(200).json({ message: 'User interest added successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error adding user interest:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export const removeInterest = async (req, res) => {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { id: interestId } = req.params;
|
||||
await settingsService.removeInterest(userId, interestId);
|
||||
res.status(200).json({ message: 'Interest removed successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error removing interest:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import UserRightType from './type/user_right.js';
|
||||
import UserRight from './community/user_right.js';
|
||||
import SettingsType from './type/settings.js';
|
||||
import UserParamValue from './type/user_param_value.js';
|
||||
import InterestType from './type/interest.js';
|
||||
import InterestTranslationType from './type/interest_translation.js';
|
||||
import Interest from './community/interest.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
SettingsType.hasMany(UserParamType, { foreignKey: 'settingsId', as: 'user_param_types' });
|
||||
@@ -18,7 +21,23 @@ export default function setupAssociations() {
|
||||
|
||||
UserRight.belongsTo(User, { foreignKey: 'userId' });
|
||||
UserRight.belongsTo(UserRightType, { foreignKey: 'rightTypeId', as: 'rightType' });
|
||||
UserRightType.hasMany(UserRight, { foreignKey: 'rightTypeId', as: 'rightType' });
|
||||
|
||||
UserParamType.hasMany(UserParamValue, { foreignKey: 'userParamTypeId', as: 'user_param_values' });
|
||||
UserParamValue.belongsTo(UserParamType, { foreignKey: 'userParamTypeId', as: 'user_param_type' });
|
||||
|
||||
InterestType.hasMany(InterestTranslationType, { foreignKey: 'interestsId', as: 'interest_translations' });
|
||||
InterestTranslationType.belongsTo(InterestType, { foreignKey: 'interestsId', as: 'interest_translations' });
|
||||
|
||||
InterestType.hasMany(Interest, { foreignKey: 'userinterestId', as: 'user_interest_type'} );
|
||||
User.hasMany(Interest, { foreignKey: 'userId', as: 'user_interest' });
|
||||
Interest.belongsTo(InterestType, { foreignKey: 'userinterestId', as: 'user_interest_type' });
|
||||
Interest.belongsTo(User, { foreignKey: 'userId', as: 'user_interest' });
|
||||
|
||||
InterestTranslationType.belongsTo(UserParamValue, {
|
||||
foreignKey: 'language',
|
||||
targetKey: 'id',
|
||||
as: 'user_param_value'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
11
backend/models/community/interest.js
Normal file
11
backend/models/community/interest.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
const interest = sequelize.define('interest_type', {
|
||||
}, {
|
||||
tableName: 'interest',
|
||||
schema: 'community',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
export default interest;
|
||||
@@ -6,6 +6,10 @@ import User from './community/user.js';
|
||||
import UserParam from './community/user_param.js';
|
||||
import Login from './logs/login.js';
|
||||
import UserRight from './community/user_right.js';
|
||||
import InterestType from './type/interest.js';
|
||||
import InterestTranslationType from './type/interest_translation.js';
|
||||
import Interest from './community/interest.js';
|
||||
import ContactMessage from './service/contactmessage.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
@@ -16,6 +20,10 @@ const models = {
|
||||
UserParam,
|
||||
Login,
|
||||
UserRight,
|
||||
InterestType,
|
||||
InterestTranslationType,
|
||||
Interest,
|
||||
ContactMessage,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
65
backend/models/service/contactmessage.js
Normal file
65
backend/models/service/contactmessage.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { encrypt, decrypt } from '../../utils/encryption.js';
|
||||
|
||||
const ContactMessage = sequelize.define('contact_message', {
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
if (value) {
|
||||
const encryptedValue = encrypt(value);
|
||||
this.setDataValue('email', encryptedValue.toString('hex'));
|
||||
}
|
||||
},
|
||||
get() {
|
||||
const value = this.getDataValue('email');
|
||||
if (value) {
|
||||
return decrypt(Buffer.from(value, 'hex'));
|
||||
}
|
||||
}
|
||||
},
|
||||
message: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
if (value) {
|
||||
const encryptedValue = encrypt(value);
|
||||
this.setDataValue('message', encryptedValue.toString('hex'));
|
||||
}
|
||||
},
|
||||
get() {
|
||||
const value = this.getDataValue('message');
|
||||
if (value) {
|
||||
return decrypt(Buffer.from(value, 'hex'));
|
||||
}
|
||||
}
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
if (value) {
|
||||
const encryptedValue = encrypt(value);
|
||||
this.setDataValue('name', encryptedValue.toString('hex'));
|
||||
}
|
||||
},
|
||||
get() {
|
||||
const value = this.getDataValue('name');
|
||||
if (value) {
|
||||
return decrypt(Buffer.from(value, 'hex'));
|
||||
}
|
||||
}
|
||||
},
|
||||
allowDataSave: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false
|
||||
},
|
||||
}, {
|
||||
tableName: 'contact_message',
|
||||
timestamps: true,
|
||||
schema: 'service',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
export default ContactMessage;
|
||||
25
backend/models/type/interest.js
Normal file
25
backend/models/type/interest.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
const Interest = sequelize.define('interest_type', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
allowed: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
adultOnly: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
}
|
||||
}, {
|
||||
tableName: 'interest',
|
||||
schema: 'type',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
export default Interest;
|
||||
30
backend/models/type/interest_translation.js
Normal file
30
backend/models/type/interest_translation.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import Interest from '../type/interest.js';
|
||||
|
||||
const interestTranslation = sequelize.define('interest_translation_type', {
|
||||
translation: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
language: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
interestsId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Interest,
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
}, {
|
||||
tableName: 'interest_translation',
|
||||
schema: 'type',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
export default interestTranslation;
|
||||
12
backend/routers/adminRouter.js
Normal file
12
backend/routers/adminRouter.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Router } from 'express';
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
import { getOpenInterests, changeInterest, deleteInterest, changeTranslation } from '../controllers/adminController.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/interests/open', authenticate, getOpenInterests);
|
||||
router.post('/interest', authenticate, changeInterest);
|
||||
router.post('/interest/translation', authenticate, changeTranslation);
|
||||
router.delete('/interest/:id', authenticate, deleteInterest);
|
||||
|
||||
export default router;
|
||||
8
backend/routers/contactRouter.js
Normal file
8
backend/routers/contactRouter.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
import { addContactMessage } from '../controllers/contactController.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post('/', addContactMessage);
|
||||
|
||||
export default router;
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Router } from 'express';
|
||||
import { filterSettings, updateSetting, getTypeParamValueId, getTypeParamValues, getTypeParamValue, getAccountSettings } from '../controllers/settingsController.js';
|
||||
import { filterSettings, updateSetting, getTypeParamValueId, getTypeParamValues, getTypeParamValue, getAccountSettings,
|
||||
getPossibleInterests, getInterests, addInterest, addUserInterest, removeInterest } from '../controllers/settingsController.js';
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
|
||||
const router = Router();
|
||||
@@ -11,5 +12,10 @@ router.post('/account', authenticate, getAccountSettings);
|
||||
router.post('/getparamvalues', getTypeParamValues);
|
||||
router.post('/getparamvalueid', getTypeParamValueId);
|
||||
router.post('/getparamvalue/:id', getTypeParamValue);
|
||||
router.get('/getpossibleinterests', authenticate, getPossibleInterests);
|
||||
router.get('/getuserinterests', authenticate, getInterests);
|
||||
router.post('/addinterest', authenticate, addInterest);
|
||||
router.post('/setinterest', authenticate, addUserInterest);
|
||||
router.get('/removeinterest/:id', authenticate, removeInterest);
|
||||
|
||||
export default router;
|
||||
|
||||
22
backend/services/ContactService.js
Normal file
22
backend/services/ContactService.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import ContactMessage from "../models/service/contactmessage.js";
|
||||
|
||||
class ContactService {
|
||||
|
||||
async addContactMessage(email, name, message, acceptDataSave) {
|
||||
if (acceptDataSave && !email) {
|
||||
throw new Error('emailrequired');
|
||||
}
|
||||
if (!acceptDataSave) {
|
||||
name = '';
|
||||
email = '';
|
||||
}
|
||||
ContactMessage.create({
|
||||
email,
|
||||
name,
|
||||
message,
|
||||
allowDataSave: acceptDataSave
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new ContactService();
|
||||
124
backend/services/adminService.js
Normal file
124
backend/services/adminService.js
Normal file
@@ -0,0 +1,124 @@
|
||||
import UserRight from "../models/community/user_right.js";
|
||||
import UserRightType from "../models/type/user_right.js";
|
||||
import InterestType from "../models/type/interest.js"
|
||||
import InterestTranslationType from "../models/type/interest_translation.js"
|
||||
import User from "../models/community/user.js";
|
||||
import UserParamValue from "../models/type/user_param_value.js";
|
||||
|
||||
class AdminService {
|
||||
async hasUserAccess(userId, section) {
|
||||
const userRights = await UserRight.findAll({
|
||||
/* where: {
|
||||
userId: userId,
|
||||
},*/
|
||||
include: [{
|
||||
model: UserRightType,
|
||||
as: 'rightType',
|
||||
where: {
|
||||
title: [section, 'mainadmin'],
|
||||
}
|
||||
},
|
||||
{
|
||||
model: User,
|
||||
as: 'user',
|
||||
where: {
|
||||
hashedId: userId,
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
});
|
||||
return userRights.length > 0;
|
||||
}
|
||||
|
||||
async getOpenInterests(userId) {
|
||||
if (!this.hasUserAccess(userId, 'interests')) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const openInterests = await InterestType.findAll({
|
||||
where: {
|
||||
allowed: false
|
||||
},
|
||||
include: {
|
||||
model: InterestTranslationType,
|
||||
as: 'interest_translations',
|
||||
}
|
||||
})
|
||||
return openInterests;
|
||||
}
|
||||
|
||||
async changeInterest(userId, interestId, active, adultOnly) {
|
||||
if (!this.hasUserAccess(userId, 'interests')) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const interest = await InterestType.findOne({
|
||||
where: {
|
||||
id: interestId
|
||||
}
|
||||
});
|
||||
if (interest) {
|
||||
interest.allowed = active;
|
||||
interest.adultOnly = adultOnly;
|
||||
await interest.save();
|
||||
}
|
||||
}
|
||||
|
||||
async deleteInterest(userId, interestId) {
|
||||
if (!this.hasUserAccess(userId, 'interests')) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const interest = await InterestType.findOne({
|
||||
where: {
|
||||
id: interestId
|
||||
}
|
||||
});
|
||||
if (interest) {
|
||||
await interest.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
async changeTranslation(userId, interestId, translations) {
|
||||
if (!this.hasUserAccess(userId, 'interests')) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const interest = await InterestType.findOne({
|
||||
id: interestId
|
||||
});
|
||||
if (!interest) {
|
||||
throw new Error('notexisting');
|
||||
}
|
||||
for (const languageId of Object.keys(translations)) {
|
||||
const languageObject = await UserParamValue.findOne(
|
||||
{
|
||||
where: {
|
||||
id: languageId
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!languageObject) {
|
||||
throw new Error('wronglanguage');
|
||||
}
|
||||
const translation = await InterestTranslationType.findOne(
|
||||
{
|
||||
where: {
|
||||
interestsId: interestId,
|
||||
language: languageObject.id
|
||||
}
|
||||
}
|
||||
);
|
||||
if (translation) {
|
||||
translation.translation = translations[languageId];
|
||||
translation.save();
|
||||
} else {
|
||||
await InterestTranslationType.create({
|
||||
interestsId: interestId,
|
||||
language: languageObject.id,
|
||||
translation: translations[languageId]
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new AdminService();
|
||||
313
backend/services/settingsService.js
Normal file
313
backend/services/settingsService.js
Normal file
@@ -0,0 +1,313 @@
|
||||
import UserParamType from '../models/type/user_param.js';
|
||||
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 Interest from '../models/type/interest.js';
|
||||
import UserInterest from '../models/community/interest.js'
|
||||
import InterestTranslation from '../models/type/interest_translation.js';
|
||||
import { calculateAge } from '../utils/userdata.js';
|
||||
import { Op } from 'sequelize';
|
||||
|
||||
class SettingsService {
|
||||
async getUser(userId) {
|
||||
const user = await User.findOne({ where: { hashedId: userId } });
|
||||
if (!user) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
async getUserParams(userId, paramDescriptions) {
|
||||
return await UserParam.findAll({
|
||||
where: { userId },
|
||||
include: [
|
||||
{
|
||||
model: UserParamType,
|
||||
as: 'paramType',
|
||||
where: { description: { [Op.in]: paramDescriptions } }
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async getFieldOptions(field) {
|
||||
if (['singleselect', 'multiselect'].includes(field.datatype)) {
|
||||
return await UserParamValue.findAll({
|
||||
where: { userParamTypeId: field.id }
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
async filterSettings(userId, type) {
|
||||
const user = await this.getUser(userId);
|
||||
const userParams = await this.getUserParams(user.id, ['birthdate', 'gender']);
|
||||
|
||||
let birthdate = null;
|
||||
let gender = null;
|
||||
for (const param of userParams) {
|
||||
if (param.paramType.description === 'birthdate') {
|
||||
birthdate = param.value;
|
||||
}
|
||||
if (param.paramType.description === 'gender') {
|
||||
const genderResult = await UserParamValue.findOne({ where: { id: param.value } });
|
||||
gender = genderResult ? genderResult.dataValues?.value : null;
|
||||
}
|
||||
}
|
||||
|
||||
const age = birthdate ? calculateAge(birthdate) : null;
|
||||
const fields = await UserParamType.findAll({
|
||||
include: [
|
||||
{
|
||||
model: SettingsType,
|
||||
as: 'settings_type',
|
||||
where: { name: type }
|
||||
},
|
||||
{
|
||||
model: UserParam,
|
||||
as: 'user_params',
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: User,
|
||||
as: 'user',
|
||||
where: { hashedId: userId }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ minAge: { [Op.or]: [null, { [Op.lte]: age }] } },
|
||||
{ gender: { [Op.or]: [null, gender] } }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
return await Promise.all(fields.map(async (field) => {
|
||||
const options = await this.getFieldOptions(field);
|
||||
return {
|
||||
id: field.id,
|
||||
name: field.description,
|
||||
minAge: field.minAge,
|
||||
gender: field.gender,
|
||||
datatype: field.datatype,
|
||||
value: field.user_params.length > 0 ? field.user_params[0].value : null,
|
||||
options: options.map(opt => ({ id: opt.id, value: opt.value }))
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
async updateSetting(userId, settingId, value) {
|
||||
const user = await this.getUser(userId);
|
||||
const paramType = await UserParamType.findOne({ where: { id: settingId } });
|
||||
if (!paramType) {
|
||||
throw new Error('Parameter type not found');
|
||||
}
|
||||
await UserParam.upsertParam(user.id, paramType.id, value);
|
||||
}
|
||||
|
||||
async getTypeParamValueId(paramValue) {
|
||||
const userParamValueObject = await UserParamValue.findOne({
|
||||
where: { value: paramValue }
|
||||
});
|
||||
if (!userParamValueObject) {
|
||||
throw new Error('Parameter value not found');
|
||||
}
|
||||
return userParamValueObject.id;
|
||||
}
|
||||
|
||||
async getTypeParamValues(type) {
|
||||
const userParamValues = await UserParamValue.findAll({
|
||||
include: [
|
||||
{
|
||||
model: UserParamType,
|
||||
as: 'user_param_type',
|
||||
where: { description: type }
|
||||
}
|
||||
]
|
||||
});
|
||||
return userParamValues.map(type => ({ id: type.dataValues.id, name: type.dataValues.value }));
|
||||
}
|
||||
|
||||
async getTypeParamValue(id) {
|
||||
const userParamValueObject = await UserParamValue.findOne({
|
||||
where: { id }
|
||||
});
|
||||
if (!userParamValueObject) {
|
||||
throw new Error('Parameter value not found');
|
||||
}
|
||||
return userParamValueObject.value;
|
||||
}
|
||||
|
||||
async getAccountSettings(userId) {
|
||||
const user = await this.getUser(userId);
|
||||
const email = user.email;
|
||||
return { username: user.username, email, showinsearch: user.searchable };
|
||||
}
|
||||
|
||||
async setAccountSettings(data) {
|
||||
const { userId, username, email, searchable, oldpassword, newpassword, newpasswordrepeat } = data;
|
||||
const user = await this.getUser(userId);
|
||||
|
||||
user.searchable = searchable;
|
||||
|
||||
if (user.password !== oldpassword) {
|
||||
throw new Error('Wrong password');
|
||||
}
|
||||
|
||||
const updateUser = {};
|
||||
if (username.toLowerCase() !== user.username.toLowerCase()) {
|
||||
const isUsernameTaken = (await User.findAll({ where: { username: username } })).length > 0;
|
||||
if (isUsernameTaken) {
|
||||
throw new Error('Username already taken');
|
||||
}
|
||||
updateUser.username = username;
|
||||
}
|
||||
|
||||
if (newpassword.trim().length > 0) {
|
||||
if (newpassword.length < 6) {
|
||||
throw new Error('Password too short');
|
||||
}
|
||||
if (newpassword !== newpasswordrepeat) {
|
||||
throw new Error('Passwords do not match');
|
||||
}
|
||||
updateUser.password = newpassword;
|
||||
}
|
||||
await user.update(updateUser);
|
||||
}
|
||||
|
||||
async getPossibleInterests(userId) {
|
||||
const user = await this.getUser(userId);
|
||||
const userParams = await this.getUserParams(user.id, ['birthdate']);
|
||||
let birthdate = null;
|
||||
for (const param of userParams) {
|
||||
if (param.paramType.description === 'birthdate') {
|
||||
birthdate = param.value;
|
||||
}
|
||||
}
|
||||
const age = birthdate ? calculateAge(birthdate) : 0;
|
||||
const filter = {
|
||||
where: age >= 18 ? {
|
||||
allowed: true,
|
||||
} : {
|
||||
allowed: true,
|
||||
[Op.or]: [
|
||||
{ adultOnly: false },
|
||||
{ adultOnly: { [Op.eq]: null } }
|
||||
]
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: InterestTranslation,
|
||||
as: 'interest_translations',
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: UserParamValue,
|
||||
as: 'user_param_value',
|
||||
required: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
return await Interest.findAll(filter);
|
||||
}
|
||||
|
||||
async getInterests(userId) {
|
||||
const user = await this.getUser(userId);
|
||||
return await UserInterest.findAll({
|
||||
where: { userId: user.id },
|
||||
include: [
|
||||
{
|
||||
model: Interest,
|
||||
as: 'user_interest_type',
|
||||
include: [
|
||||
{
|
||||
model: InterestTranslation,
|
||||
as: 'interest_translations',
|
||||
include: [
|
||||
{
|
||||
model: UserParamValue,
|
||||
as: 'user_param_value',
|
||||
required: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async addInterest(userId, name) {
|
||||
const user = await this.getUser(userId);
|
||||
const existingInterests = await Interest.findAll({ where: { name: name.toLowerCase() } });
|
||||
if (existingInterests.length > 0) {
|
||||
throw new Error('Interest already exists');
|
||||
}
|
||||
const userParam = await this.getUserParams(user.id, ['language']);
|
||||
let language = 'en';
|
||||
if (userParam) {
|
||||
const userParamValue = await UserParamValue.findOne({
|
||||
where: {
|
||||
id: userParam[0].value
|
||||
}
|
||||
});
|
||||
language = userParamValue && userParamValue.value ? userParamValue.value : 'en';
|
||||
}
|
||||
const languageParam = await UserParamValue.findOne({ where: { value: language } });
|
||||
const languageId = languageParam.id;
|
||||
const interest = await Interest.create({ name: name.toLowerCase(), allowed: false, adultOnly: true });
|
||||
await InterestTranslation.create({ interestsId: interest.id, language: languageId, translation: name });
|
||||
return interest;
|
||||
}
|
||||
|
||||
async addUserInterest(userId, interestId) {
|
||||
const user = await this.getUser(userId);
|
||||
const interestsFilter = {
|
||||
id: interestId,
|
||||
allowed: true,
|
||||
};
|
||||
const userParams = await this.getUserParams(user.id, ['birthdate']);
|
||||
let birthdate = null;
|
||||
for (const param of userParams) {
|
||||
if (param.paramType.description === 'birthdate') {
|
||||
birthdate = param.value;
|
||||
}
|
||||
}
|
||||
const age = birthdate ? calculateAge(birthdate) : 0;
|
||||
if (age < 18) {
|
||||
interestsFilter[Op.or] = [
|
||||
{ adultOnly: false },
|
||||
{ adultOnly: { [Op.eq]: null } }
|
||||
];
|
||||
}
|
||||
const existingInterests = await Interest.findAll({ where: interestsFilter });
|
||||
if (existingInterests.length === 0) {
|
||||
throw new Error('Interest not found');
|
||||
};
|
||||
const interest = await UserInterest.findAll({
|
||||
where: { userId: user.id, userinterestId: interestId }
|
||||
});
|
||||
if (interest.length > 0) {
|
||||
throw new Error('Interest already exists');
|
||||
}
|
||||
await UserInterest.create({ userId: user.id, userinterestId: interestId });
|
||||
}
|
||||
|
||||
async removeInterest(userId, interestId) {
|
||||
const user = await this.getUser(userId);
|
||||
const interests = await UserInterest.findAll({
|
||||
where: { userId: user.id, userinterestId: interestId }
|
||||
});
|
||||
for (const interest of interests) {
|
||||
await interest.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new SettingsService();
|
||||
@@ -1,6 +1,10 @@
|
||||
import UserParamType from '../models/type/user_param.js';
|
||||
import SettingsType from '../models/type/settings.js';
|
||||
import UserParamValue from '../models/type/user_param_value.js';
|
||||
import Interest from '../models/type/interest.js';
|
||||
import { Op, } from 'sequelize';
|
||||
import InterestTranslation from '../models/type/interest_translation.js';
|
||||
import { sequelize } from '../utils/sequelize.js';
|
||||
|
||||
const initializeTypes = async () => {
|
||||
const settingsTypes = await SettingsType.findAll();
|
||||
@@ -10,7 +14,7 @@ const initializeTypes = async () => {
|
||||
}, {});
|
||||
|
||||
const getSettingsTypeId = (name) => settingsTypeMap[name];
|
||||
const getUserParamTypeId = async(name) => {
|
||||
const getUserParamTypeId = async (name) => {
|
||||
const userParamType = await UserParamType.findOne({
|
||||
where: {
|
||||
description: name
|
||||
@@ -19,7 +23,7 @@ const initializeTypes = async () => {
|
||||
return userParamType.id;
|
||||
};
|
||||
const userParams = {
|
||||
language: {type: 'singleselect', setting: 'personal'},
|
||||
language: { type: 'singleselect', setting: 'personal' },
|
||||
birthdate: { type: 'date', setting: 'personal' },
|
||||
zip: { type: 'string', setting: 'personal' },
|
||||
town: { type: 'string', setting: 'personal' },
|
||||
@@ -38,7 +42,7 @@ const initializeTypes = async () => {
|
||||
penislenght: { type: 'int', setting: 'sexuality', minAge: 14, gender: 'male' },
|
||||
brasize: { type: 'string', setting: 'sexuality', minAge: 14, gender: 'female' }
|
||||
};
|
||||
Object.keys(userParams).forEach(async(key) => {
|
||||
Object.keys(userParams).forEach(async (key) => {
|
||||
const item = userParams[key];
|
||||
const createItem = { description: key, datatype: item.type, settingsId: getSettingsTypeId(item.setting) };
|
||||
if (item.minAge) createItem.minAge = item.minAge;
|
||||
@@ -59,10 +63,10 @@ const initializeTypes = async () => {
|
||||
sexualpreference: ['straight', 'gay', 'bi', 'pan', 'asexual'],
|
||||
pubichair: ['none', 'short', 'medium', 'long', 'hairy', 'waxed', 'landingstrip', 'bikinizone', 'other'],
|
||||
};
|
||||
Object.keys(valuesList).forEach(async(key) => {
|
||||
Object.keys(valuesList).forEach(async (key) => {
|
||||
const values = valuesList[key];
|
||||
const userParamTypeId = await getUserParamTypeId(key);
|
||||
values.forEach(async(value) => {
|
||||
values.forEach(async (value) => {
|
||||
await UserParamValue.findOrCreate({
|
||||
where: {
|
||||
userParamTypeId: userParamTypeId,
|
||||
@@ -72,6 +76,91 @@ const initializeTypes = async () => {
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
const interestsList = {
|
||||
music: { adult: false, translation: { value: 'Musik', language: 'de' } },
|
||||
piano: { adult: false, translation: { value: 'Klavier', language: 'de' } },
|
||||
art: { adult: false, translation: { value: 'Kunst', language: 'de' } },
|
||||
photography: { adult: false, translation: { value: 'Fotografie', language: 'de' } },
|
||||
gaming: { adult: false, translation: { value: 'Spielen', language: 'de' } },
|
||||
sports: { adult: false, translation: { value: 'Sport', language: 'de' } },
|
||||
tabletennis: { adult: false, translation: { value: 'Tischtennis', language: 'de' } },
|
||||
soccer: { adult: false, translation: { value: 'Fußball', language: 'de' } },
|
||||
tennis: { adult: false, translation: { value: 'Tennis', language: 'de' } },
|
||||
swimming: { adult: false, translation: { value: 'Schwimmen', language: 'de' } },
|
||||
hiking: { adult: false, translation: { value: 'Wandern', language: 'de' } },
|
||||
cooking: { adult: false, translation: { value: 'Kochen', language: 'de' } },
|
||||
travel: { adult: false, translation: { value: 'Reisen', language: 'de' } },
|
||||
movies: { adult: false, translation: { value: 'Filme', language: 'de' } },
|
||||
books: { adult: false, translation: { value: 'Bücher', language: 'de' } },
|
||||
reading: { adult: false, translation: { value: 'Lesen', language: 'de' } },
|
||||
pets: { adult: false, translation: { value: 'Haustiere', language: 'de' } },
|
||||
dogs: { adult: false, translation: { value: 'Hunde', language: 'de' } },
|
||||
cats: { adult: false, translation: { value: 'Katzen', language: 'de' } },
|
||||
plants: { adult: false, translation: { value: 'Pflanzen', language: 'de' } },
|
||||
gardening: { adult: false, translation: { value: 'Gartenarbeit', language: 'de' } },
|
||||
yoga: { adult: false, translation: { value: 'Yoga', language: 'de' } },
|
||||
meditation: { adult: false, translation: { value: 'Meditation', language: 'de' } },
|
||||
spirituality: { adult: false, translation: { value: 'Spiritualität', language: 'de' } },
|
||||
religion: { adult: false, translation: { value: 'Religion', language: 'de' } },
|
||||
politics: { adult: false, translation: { value: 'Politik', language: 'de' } },
|
||||
history: { adult: false, translation: { value: 'Geschichte', language: 'de' } },
|
||||
science: { adult: false, translation: { value: 'Wissenschaft', language: 'de' } },
|
||||
technology: { adult: false, translation: { value: 'Technologie', language: 'de' } },
|
||||
fashion: { adult: false, translation: { value: 'Mode', language: 'de' } },
|
||||
beauty: { adult: false, translation: { value: 'Schönheit', language: 'de' } },
|
||||
fitness: { adult: false, translation: { value: 'Fitness', language: 'de' } },
|
||||
health: { adult: false, translation: { value: 'Gesundheit', language: 'de' } },
|
||||
nutrition: { adult: false, translation: { value: 'Ernährung', language: 'de' } },
|
||||
wellness: { adult: false, translation: { value: 'Wellness', language: 'de' } },
|
||||
finance: { adult: false, translation: { value: 'Finanzen', language: 'de' } },
|
||||
business: { adult: false, translation: { value: 'Geschäft', language: 'de' } },
|
||||
entrepreneurship: { adult: false, translation: { value: 'Unternehmertum', language: 'de' } },
|
||||
education: { adult: false, translation: { value: 'Bildung', language: 'de' } },
|
||||
learning: { adult: false, translation: { value: 'Lernen', language: 'de' } },
|
||||
language: { adult: false, translation: { value: 'Sprache', language: 'de' } },
|
||||
culture: { adult: false, translation: { value: 'Kultur', language: 'de' } },
|
||||
family: { adult: false, translation: { value: 'Familie', language: 'de' } },
|
||||
friends: { adult: false, translation: { value: 'Freunde', language: 'de' } },
|
||||
social: { adult: false, translation: { value: 'Soziales', language: 'de' } },
|
||||
nightlife: { adult: false, translation: { value: 'Nachtleben', language: 'de' } },
|
||||
partying: { adult: false, translation: { value: 'Feiern', language: 'de' } },
|
||||
comedy: { adult: false, translation: { value: 'Komödie', language: 'de' } },
|
||||
humor: { adult: false, translation: { value: 'Humor', language: 'de' } },
|
||||
sex: { adult: true, translation: { value: 'Sex', language: 'de' } },
|
||||
romance: { adult: false, translation: { value: 'Romantik', language: 'de' } },
|
||||
dating: { adult: true, translation: { value: 'Dating', language: 'de' } },
|
||||
relationships: { adult: false, translation: { value: 'Beziehungen', language: 'de' } },
|
||||
adventure: { adult: true, translation: { value: 'Abenteuer', language: 'de' } },
|
||||
escapade: { adult: true, translation: { value: 'Eskapade', language: 'de' } },
|
||||
sexuality: { adult: true, translation: { value: 'Sexualität', language: 'de' } }
|
||||
};
|
||||
const languages = await UserParamValue.findAll({where: { value: {[Op.in]: ['de', 'en']} } });
|
||||
const languageId = (language) => {
|
||||
const lang = languages.find((lang) => lang.value === language);
|
||||
return lang ? lang.id : null;
|
||||
};
|
||||
|
||||
for (const key of Object.keys(interestsList)) {
|
||||
try {
|
||||
const value = interestsList[key];
|
||||
const [item, created] = await Interest.findOrCreate({
|
||||
where: { name: key },
|
||||
defaults: { name: key, allowed: true, adultOnly: value.adult },
|
||||
});
|
||||
|
||||
if (created) {
|
||||
const langId = languageId('de');
|
||||
console.log(item.id, langId, value.translation.value);
|
||||
await InterestTranslation.create({
|
||||
interestsId: item.id,
|
||||
language: langId,
|
||||
translation: value.translation.value
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default initializeTypes;
|
||||
|
||||
@@ -23,8 +23,8 @@ const initializeUserRights = async() => {
|
||||
defaults: { title: "rights"}
|
||||
});
|
||||
await UserRightType.findOrCreate({
|
||||
where: { title: "interrests"},
|
||||
defaults: { title: "interrests"}
|
||||
where: { title: "interests"},
|
||||
defaults: { title: "interests"}
|
||||
});
|
||||
await UserRightType.findOrCreate({
|
||||
where: { title: "falukant"},
|
||||
|
||||
@@ -8,13 +8,14 @@ const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, proces
|
||||
dialect: 'postgres',
|
||||
define: {
|
||||
timestamps: false
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const createSchemas = async () => {
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS community');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS logs');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS type');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS service');
|
||||
};
|
||||
|
||||
const initializeDatabase = async () => {
|
||||
@@ -24,21 +25,10 @@ const initializeDatabase = async () => {
|
||||
};
|
||||
|
||||
const syncModels = async (models) => {
|
||||
// Stellen Sie sicher, dass alle Modelle vorhanden sind
|
||||
if (!models.SettingsType || !models.UserParamValue || !models.UserParamType || !models.UserRightType ||
|
||||
!models.User || !models.UserParam || !models.Login || !models.UserRight) {
|
||||
throw new Error('Models are not properly loaded.');
|
||||
// Nur einmaliges sync ohne alter/force
|
||||
for (const model of Object.values(models)) {
|
||||
await model.sync();
|
||||
}
|
||||
|
||||
// Synchronisieren Sie die Modelle in der gewünschten Reihenfolge
|
||||
await models.SettingsType.sync({ alter: true });
|
||||
await models.UserParamValue.sync({ alter: true });
|
||||
await models.UserParamType.sync({ alter: true });
|
||||
await models.UserRightType.sync({ alter: true });
|
||||
await models.User.sync({ alter: true });
|
||||
await models.UserParam.sync({ alter: true });
|
||||
await models.Login.sync({ alter: true });
|
||||
await models.UserRight.sync({ alter: true });
|
||||
};
|
||||
|
||||
export { sequelize, initializeDatabase };
|
||||
|
||||
@@ -8,13 +8,11 @@ import models from '../models/index.js';
|
||||
const syncDatabase = async () => {
|
||||
try {
|
||||
await initializeDatabase();
|
||||
for (const model of Object.values(models)) {
|
||||
await model.sync({ alter: true });
|
||||
}
|
||||
setupAssociations();
|
||||
for (const model of Object.values(models)) {
|
||||
await model.sync({ alter: true });
|
||||
await model.sync();
|
||||
}
|
||||
|
||||
await initializeSettings();
|
||||
await initializeTypes();
|
||||
await initializeUserRights();
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="static-block">
|
||||
<a href="#" @click.prevent="openImprintDialog">Impressum</a>
|
||||
<a href="#" @click.prevent="openDataPrivacyDialog">Datenschutzerklärung</a>
|
||||
<a href="#" @click.prevent="openImprintDialog">{{ $t('imprint.button') }}</a>
|
||||
<a href="#" @click.prevent="openDataPrivacyDialog">{{ $t('dataPrivacy.button') }}</a>
|
||||
<a href="#" @click.prevent="openContactDialog">{{ $t('contact.button') }}</a>
|
||||
</div>
|
||||
<ImprintDialog ref="imprintDialog" name="imprintDialog" />
|
||||
<DataPrivacyDialog ref="dataPrivacyDialog" name="dataPrivacyDialog" />
|
||||
<ContactDialog ref="contactDialog" name="contactDialog" />
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
@@ -22,12 +24,14 @@
|
||||
import { mapGetters } from 'vuex';
|
||||
import ImprintDialog from '../dialogues/standard/ImprintDialog.vue';
|
||||
import DataPrivacyDialog from '../dialogues/standard/DataPrivacyDialog.vue';
|
||||
import ContactDialog from '../dialogues/standard/ContactDialog.vue';
|
||||
|
||||
export default {
|
||||
name: 'AppFooter',
|
||||
components: {
|
||||
ImprintDialog,
|
||||
DataPrivacyDialog,
|
||||
ContactDialog,
|
||||
},
|
||||
computed: {
|
||||
...mapGetters('dialogs', ['openDialogs'])
|
||||
@@ -39,6 +43,9 @@ export default {
|
||||
openDataPrivacyDialog() {
|
||||
this.$refs.dataPrivacyDialog.open();
|
||||
},
|
||||
openContactDialog() {
|
||||
this.$refs.contactDialog.open();
|
||||
},
|
||||
toggleDialogMinimize(dialogName) {
|
||||
this.$store.dispatch('dialogs/toggleDialogMinimize', dialogName);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 10px;
|
||||
background-color: #f8f9fa;
|
||||
background-color: #f8a22b;
|
||||
}
|
||||
.logo, .title, .advertisement {
|
||||
text-align: center;
|
||||
|
||||
@@ -59,6 +59,7 @@ nav>ul {
|
||||
padding: 0;
|
||||
flex-direction: row;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
ul {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<template>
|
||||
<div v-if="visible" :class="['dialog-overlay', { 'non-modal': !modal }]" @click.self="handleOverlayClick">
|
||||
<div class="dialog" :class="{ minimized: minimized }" :style="{ width: dialogWidth, height: dialogHeight }"
|
||||
v-if="!minimized">
|
||||
<div class="dialog-header">
|
||||
<div class="dialog" :class="{ minimized: minimized }"
|
||||
:style="{ width: dialogWidth, height: dialogHeight, top: dialogTop, left: dialogLeft, position: 'absolute' }"
|
||||
v-if="!minimized" ref="dialog">
|
||||
<div class="dialog-header" @mousedown="startDragging">
|
||||
<span v-if="icon" class="dialog-icon">
|
||||
<img :src="icon" alt="Icon" />
|
||||
</span>
|
||||
@@ -66,12 +67,19 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
minimized: false
|
||||
minimized: false,
|
||||
dialogTop: '50%',
|
||||
dialogLeft: '50%',
|
||||
isDragging: false,
|
||||
dragOffsetX: 0,
|
||||
dragOffsetY: 0,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
dialogWidth() {
|
||||
return this.width || '70%';
|
||||
const val = this.width || '70%';
|
||||
console.log(val);
|
||||
return val;
|
||||
},
|
||||
dialogHeight() {
|
||||
return this.height || '60%';
|
||||
@@ -80,7 +88,7 @@ export default {
|
||||
watch: {
|
||||
visible(newValue) {
|
||||
if (!newValue) {
|
||||
this.minimized = false; // Reset minimized state when dialog is closed
|
||||
this.minimized = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -101,7 +109,7 @@ export default {
|
||||
buttonClick(action) {
|
||||
this.$emit(action);
|
||||
if (action === 'close') {
|
||||
this.close(); // Close dialog after button click if action is close
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
handleOverlayClick() {
|
||||
@@ -115,7 +123,26 @@ export default {
|
||||
toggleMinimize() {
|
||||
this.minimized = !this.minimized;
|
||||
this.$store.dispatch('dialogs/toggleDialogMinimize', this.name);
|
||||
}
|
||||
},
|
||||
startDragging(event) {
|
||||
this.isDragging = true;
|
||||
const dialog = this.$refs.dialog;
|
||||
this.dragOffsetX = event.clientX - dialog.offsetLeft;
|
||||
this.dragOffsetY = event.clientY - dialog.offsetTop;
|
||||
document.addEventListener('mousemove', this.onDrag);
|
||||
document.addEventListener('mouseup', this.stopDragging);
|
||||
console.log('dragging started');
|
||||
},
|
||||
onDrag(event) {
|
||||
if (!this.isDragging) return;
|
||||
this.dialogLeft = `${event.clientX - this.dragOffsetX}px`;
|
||||
this.dialogTop = `${event.clientY - this.dragOffsetY}px`;
|
||||
},
|
||||
stopDragging() {
|
||||
this.isDragging = false;
|
||||
document.removeEventListener('mousemove', this.onDrag);
|
||||
document.removeEventListener('mouseup', this.stopDragging);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.$store.subscribe((mutation) => {
|
||||
@@ -153,6 +180,8 @@ export default {
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
pointer-events: all;
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.dialog.minimized {
|
||||
@@ -167,6 +196,7 @@ export default {
|
||||
padding: 10px 20px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
background-color: #F9A22C;
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.dialog-icon {
|
||||
|
||||
183
frontend/src/components/MessageboxWidget.vue
Normal file
183
frontend/src/components/MessageboxWidget.vue
Normal file
@@ -0,0 +1,183 @@
|
||||
<template>
|
||||
<div v-if="visible" :class="['dialog-overlay', { 'non-modal': false }]">
|
||||
<div class="dialog" :class="{ minimized: minimized }" :style="{ width: dialogWidth, height: dialogHeight }">
|
||||
<div class="dialog-header">
|
||||
<span class="dialog-title">{{ getHeadLine() }}</span>
|
||||
<span class="dialog-close" @click="close">✖</span>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
{{ message }}
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="close()" class="dialog-button">Ok</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'MessageboxWidget',
|
||||
props: {
|
||||
type: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px'
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '200px'
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
minimized: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
dialogWidth() {
|
||||
return this.width || '70%';
|
||||
},
|
||||
dialogHeight() {
|
||||
return this.height || '60%';
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
visible(newValue) {
|
||||
if (!newValue) {
|
||||
this.minimized = false; // Reset minimized state when dialog is closed
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
open() {
|
||||
this.visible = true;
|
||||
if (this.modal === false) {
|
||||
this.$store.dispatch('dialogs/addOpenDialog', {
|
||||
status: 'open',
|
||||
dialog: this
|
||||
});
|
||||
}
|
||||
},
|
||||
close() {
|
||||
this.visible = false;
|
||||
this.$store.dispatch('dialogs/removeOpenDialog', this.name);
|
||||
},
|
||||
getHeadLine() {
|
||||
switch (this.type) {
|
||||
case 'error':
|
||||
return this.$t('error-title');
|
||||
case 'warning':
|
||||
return this.$t('warning-title');
|
||||
case 'info':
|
||||
return this.$t('info-title');
|
||||
default:
|
||||
return this.$t('info-title');
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$store.subscribe((mutation) => {
|
||||
if (mutation.type === 'dialogs/toggleDialogMinimize' && mutation.payload === this.name) {
|
||||
this.minimized = !this.minimized;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.dialog-overlay.non-modal {
|
||||
background: transparent;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
background: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
.dialog.minimized {
|
||||
height: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 20px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
background-color: #F9A22C;
|
||||
}
|
||||
|
||||
.dialog-icon {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.dialog-title {
|
||||
flex-grow: 1;
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.dialog-close,
|
||||
.dialog-minimize {
|
||||
cursor: pointer;
|
||||
font-size: 1.5em;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
flex-grow: 1;
|
||||
padding: 20px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 10px 20px;
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.dialog-button {
|
||||
margin-left: 10px;
|
||||
padding: 10px 20px;
|
||||
cursor: pointer;
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.dialog-button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
</style>
|
||||
92
frontend/src/dialogues/standard/ContactDialog.vue
Normal file
92
frontend/src/dialogues/standard/ContactDialog.vue
Normal file
@@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<DialogWidget ref="dialog" title="contact.title" :isTitleTranslated="true" icon="contact24.png" :show-close="true"
|
||||
:buttons="[{ text: 'Ok', action: 'save' }, { text: 'Cancel', action: 'close' }]" :modal="false" @save="save"
|
||||
:width="'50em'">
|
||||
<table>
|
||||
<tr>
|
||||
<td>{{ $t("dialog.contact.email") }}</td>
|
||||
<td><input type="email" v-model="email" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ $t("dialog.contact.name") }}</td>
|
||||
<td><input type="text" v-model="name" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>{{ $t("dialog.contact.message") }}</p>
|
||||
<textarea v-model="message" rows="15" cols="80"></textarea>
|
||||
<p>{{ $t("dialog.contact.accept") }}</p>
|
||||
<label><input type="checkbox" v-model="acceptDataSave" />{{ $t("dialog.contact.acceptdatasave") }}</label>
|
||||
<p>{{ $t("dialog.contact.accept2") }}</p>
|
||||
<p v-if="error" class="error">{{ $t("dialog.contact.error." + error) }}</p>
|
||||
</DialogWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DialogWidget from '../../components/DialogWidget.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
|
||||
export default {
|
||||
name: 'ContactDialog',
|
||||
components: {
|
||||
DialogWidget
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
email: "",
|
||||
name: "",
|
||||
message: "",
|
||||
acceptDataSave: false,
|
||||
error: ""
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
open() {
|
||||
this.email = "";
|
||||
this.name = "";
|
||||
this.message = "";
|
||||
this.acceptDataSave = false;
|
||||
this.error = "";
|
||||
this.$refs.dialog.open();
|
||||
},
|
||||
async save() {
|
||||
try {
|
||||
const response = await apiClient.post('/api/contact', {
|
||||
email: this.email,
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
acceptDataSave: this.acceptDataSave
|
||||
});
|
||||
this.$refs.dialog.close();
|
||||
} catch (error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
p {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
table,
|
||||
tr,
|
||||
td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,7 @@
|
||||
:isTitleTranslated=true
|
||||
icon="privacy24.png"
|
||||
:show-close=true
|
||||
:buttons="[{ text: 'Ok' }]"
|
||||
:buttons="[{ text: 'Ok', action: 'close' }]"
|
||||
:modal=false
|
||||
@close="closeDialog"
|
||||
@ok="handleOk"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:isTitleTranslated=true
|
||||
icon="imprint24.png"
|
||||
:show-close="true"
|
||||
:buttons="[{ text: 'Ok' }]"
|
||||
:buttons="[{ text: 'Ok', action: 'close' }]"
|
||||
:modal=false
|
||||
@close="closeDialog"
|
||||
@ok="handleOk"
|
||||
|
||||
@@ -10,6 +10,7 @@ import enRegister from './locales/en/register.json';
|
||||
import enError from './locales/en/error.json';
|
||||
import enActivate from './locales/en/activate.json';
|
||||
import enSettings from './locales/en/settings.json';
|
||||
import enAdmin from './locales/en/admin.json';
|
||||
|
||||
import deGeneral from './locales/de/general.json';
|
||||
import deHeader from './locales/de/header.json';
|
||||
@@ -20,6 +21,7 @@ import deRegister from './locales/de/register.json';
|
||||
import deError from './locales/de/error.json';
|
||||
import deActivate from './locales/de/activate.json';
|
||||
import deSettings from './locales/de/settings.json';
|
||||
import deAdmin from './locales/de/admin.json';
|
||||
|
||||
const messages = {
|
||||
en: {
|
||||
@@ -32,6 +34,7 @@ const messages = {
|
||||
...enError,
|
||||
...enActivate,
|
||||
...enSettings,
|
||||
...enAdmin,
|
||||
},
|
||||
de: {
|
||||
...deGeneral,
|
||||
@@ -43,6 +46,7 @@ const messages = {
|
||||
...deError,
|
||||
...deActivate,
|
||||
...deSettings,
|
||||
...deAdmin,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
16
frontend/src/i18n/locales/de/admin.json
Normal file
16
frontend/src/i18n/locales/de/admin.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"admin": {
|
||||
"interests": {
|
||||
"title": "[Admin] - Interessen verwalten",
|
||||
"newinterests": {
|
||||
"name": "Name des Interesses",
|
||||
"status": "Freigegeben",
|
||||
"adultonly": "Nur für Erwachsene",
|
||||
"translations": "Übersetzungen",
|
||||
"isactive": "Aktiviert",
|
||||
"isadult": "Nur für Erwachsene",
|
||||
"delete": "Löschen"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,28 @@
|
||||
{
|
||||
"welcome": "Willkommen bei YourPart",
|
||||
"imprint": {
|
||||
"title": "Impressum"
|
||||
"title": "Impressum",
|
||||
"button": "Impressum"
|
||||
},
|
||||
"dataPrivacy": {
|
||||
"title": "Datenschutzerklärung"
|
||||
"title": "Datenschutzerklärung",
|
||||
"button": "Datenschutzerklärung"
|
||||
},
|
||||
"contact": {
|
||||
"title": "Kontakt",
|
||||
"button": "Kontakt"
|
||||
},
|
||||
"error-title": "Fehler",
|
||||
"warning-title": "Warnung",
|
||||
"info-title": "Information",
|
||||
"dialog": {
|
||||
"contact": {
|
||||
"email": "Email-Adresse",
|
||||
"name": "Name",
|
||||
"message": "Deine Nachricht an uns",
|
||||
"accept": "Deine Email-Adresse wird vorübergehend in unserem System gespeichert. Nachdem Deine Anfrage bearbeitet wurde, wird die Email-Adresse wieder aus dem System gelöscht.",
|
||||
"acceptdatasave": "Ich stimme der vorübergehenden Speicherung meiner Email-Adresse zu.",
|
||||
"accept2": "Ohne diese Zustimmung können wir Dir leider nicht antworten."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
"account": "Account",
|
||||
"personal": "Persönliches",
|
||||
"view": "Aussehen",
|
||||
"interrests": "Interessen",
|
||||
"interests": "Interessen",
|
||||
"notifications": "Benachrichtigungen",
|
||||
"sexuality": "Sexualität"
|
||||
},
|
||||
@@ -36,7 +36,7 @@
|
||||
"useradministration": "Benutzerverwaltung",
|
||||
"forum": "Forum",
|
||||
"userrights": "Benutzerrechte",
|
||||
"interrests": "Interessen",
|
||||
"interests": "Interessen",
|
||||
"falukant": "Falukant"
|
||||
},
|
||||
"m-friends": {
|
||||
|
||||
@@ -126,7 +126,16 @@
|
||||
"deleteAccount": "Account löschen",
|
||||
"language": "Sprache",
|
||||
"showinsearch": "In Usersuchen anzeigen",
|
||||
"changeaction": "Benutzerdaten ändern"
|
||||
"changeaction": "Benutzerdaten ändern",
|
||||
"oldpassword": "Altes Paßwort (benötigt)"
|
||||
},
|
||||
"interests": {
|
||||
"title": "Interessen",
|
||||
"new": "Neues Interesse",
|
||||
"add": "Hinzufügen",
|
||||
"added": "Das neue Interesse wurde hinzugefügt und wird bearbeitet. Bis zum Abschluss ist es nicht in der Liste der Interessen sichtbar.",
|
||||
"adderror": "Beim hinzufügen des Interesses ist ein Fehler aufgetreten.",
|
||||
"errorsetinterest": "Das Interest konnte für Dich nicht gebucht werden."
|
||||
}
|
||||
}
|
||||
}
|
||||
3
frontend/src/i18n/locales/en/admin.json
Normal file
3
frontend/src/i18n/locales/en/admin.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import PeronalSettingsView from '../views/settings/PersonalView.vue';
|
||||
import ViewSettingsView from '../views/settings/ViewView.vue';
|
||||
import SexualitySettingsView from '../views/settings/SexualityView.vue';
|
||||
import AccountSettingsView from '../views/settings/AccountView.vue';
|
||||
import InterestsView from '../views/settings/InterestsView.vue';
|
||||
import AdminInterestsView from '../views/admin/InterestsView.vue';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
@@ -41,6 +43,18 @@ const routes = [
|
||||
name: 'Account settings',
|
||||
component: AccountSettingsView,
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/settings/interests',
|
||||
name: 'Interests',
|
||||
component: InterestsView,
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/admin/interests',
|
||||
name: 'AdminInterests',
|
||||
component: AdminInterestsView,
|
||||
meta: { requiresAuth: true }
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -9,11 +9,8 @@ const apiClient = axios.create({
|
||||
});
|
||||
|
||||
apiClient.interceptors.request.use(config => {
|
||||
console.log('loading user');
|
||||
const user = store.getters.user;
|
||||
console.log(user);
|
||||
if (user && user.authCode) {
|
||||
console.log('set auth');
|
||||
config.headers['userId'] = user.id;
|
||||
config.headers['authCode'] = user.authCode;
|
||||
}
|
||||
|
||||
133
frontend/src/views/admin/InterestsView.vue
Normal file
133
frontend/src/views/admin/InterestsView.vue
Normal file
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>{{ $t("admin.interests.title") }}</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t("admin.interests.newinterests.name") }}</th>
|
||||
<th>{{ $t("admin.interests.newinterests.status") }}</th>
|
||||
<th>{{ $t("admin.interests.newinterests.adultonly") }}</th>
|
||||
<th>{{ $t("admin.interests.newinterests.translations") }}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="openInterest in openInterests" :key="openInterest.id">
|
||||
<td>{{ openInterest.name }}</td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" v-model="openInterest.allowed" @change="changeItem(openInterest)" />
|
||||
{{ $t("admin.interests.newinterests.isactive") }}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" v-model="openInterest.adultOnly"
|
||||
@change="changeItem(openInterest)" />
|
||||
{{ $t("admin.interests.newinterests.isadult") }}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<div v-for="language in languages" :key="language.id">
|
||||
<label>{{ $t(language.captionTr) }}
|
||||
<input type="text" :value="getTranslationValue(openInterest, language)"
|
||||
@change="changeTranslation(openInterest, language, $event.target.value)" />
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button @click="deleteInterest(openInterest.id)">{{ $t("admin.interests.newinterests.delete")
|
||||
}}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import { mapGetters } from 'vuex';
|
||||
import MessageboxWidget from '../../components/MessageboxWidget.vue';
|
||||
|
||||
export default {
|
||||
name: "AdminInterestsView",
|
||||
data() {
|
||||
return {
|
||||
openInterests: [],
|
||||
languages: [],
|
||||
}
|
||||
},
|
||||
components: {
|
||||
MessageboxWidget,
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['user', 'language']),
|
||||
},
|
||||
async mounted() {
|
||||
await this.loadOpenInterests();
|
||||
await this.getLanguages();
|
||||
},
|
||||
methods: {
|
||||
async loadOpenInterests() {
|
||||
try {
|
||||
const response = await apiClient.get('/api/admin/interests/open');
|
||||
this.openInterests = response.data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async changeItem(interest) {
|
||||
try {
|
||||
const payload = {
|
||||
id: interest.id,
|
||||
active: interest.allowed || false,
|
||||
adult: interest.adultOnly || false,
|
||||
};
|
||||
await apiClient.post('/api/admin/interest', payload);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async changeTranslation(interest, language, value) {
|
||||
try {
|
||||
if (!interest.translations) {
|
||||
interest.translations = {}; // Direkte Zuweisung, um Reaktivität sicherzustellen
|
||||
}
|
||||
interest.translations[language.value] = value; // Direkte Zuweisung
|
||||
|
||||
const payload = {
|
||||
id: interest.id,
|
||||
translations: {
|
||||
[language.value]: value,
|
||||
}
|
||||
};
|
||||
await apiClient.post('/api/admin/interest/translation', payload);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async deleteInterest(id) {
|
||||
try {
|
||||
await apiClient.delete(`/api/admin/interest/${id}`);
|
||||
this.openInterests = this.openInterests.filter(interest => interest.id !== id);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async getLanguages() {
|
||||
try {
|
||||
const response = await apiClient.post('/api/settings/getparamvalues', {
|
||||
type: 'language'
|
||||
});
|
||||
this.languages = response.data.map(item => { return { value: item.id, captionTr: `settings.personal.language.${item.name}` } });
|
||||
} catch (err) {
|
||||
console.error('Error loading languages:', err);
|
||||
}
|
||||
},
|
||||
getTranslationValue(interest, language) {
|
||||
return interest.translations ? interest.translations[language.value] || '' : '';
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
169
frontend/src/views/settings/InterestsView.vue
Normal file
169
frontend/src/views/settings/InterestsView.vue
Normal file
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>{{ $t('settings.interests.title') }}</h2>
|
||||
<div><span v-for="interest, key in this.userInterests" class="interest">{{ key > 0 ? ', ' : '' }}{{
|
||||
getInterestTranslation(interest.user_interest_type) }}<span class="link remove" @click="removeInterest(interest)">-</span></span></div>
|
||||
</div>
|
||||
<div class="new-interest">
|
||||
{{ $t('settings.interests.new') }} <input type="text" v-model="newInterest" @keyup="newInterestKeyupHandler" />
|
||||
<button @click="addInterestByText">{{ $t('settings.interests.add') }}</button>
|
||||
<div class="new-interest-proposals" v-if="filteredInterests.length > 0">
|
||||
<ul>
|
||||
<li v-for="interest in filteredInterests" @click="addInterest(interest)" class="link">{{
|
||||
getInterestTranslation(interest) }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<MessageboxWidget :type="messageboxType" :message="messageboxMessage" ref="messageboxWidget"></MessageboxWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import { mapGetters } from 'vuex';
|
||||
import MessageboxWidget from '../../components/MessageboxWidget.vue';
|
||||
|
||||
export default {
|
||||
name: "InterestsView",
|
||||
components: {
|
||||
MessageboxWidget,
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['user', 'language']),
|
||||
},
|
||||
async mounted() {
|
||||
await this.loadUserInterests();
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
possibleInterests: [],
|
||||
userInterests: [],
|
||||
filteredInterests: [],
|
||||
newInterest: '',
|
||||
messageboxType: 'info',
|
||||
messageboxMessage: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadUserInterests() {
|
||||
const resultPossibleInterests = await apiClient.get('/api/settings/getpossibleinterests');
|
||||
this.possibleInterests = resultPossibleInterests.data;
|
||||
const resultUserInterests = await apiClient.get('/api/settings/getuserinterests');
|
||||
this.userInterests = resultUserInterests.data;
|
||||
},
|
||||
newInterestKeyupHandler() {
|
||||
const searchTerm = this.newInterest.toLowerCase();
|
||||
this.filteredInterests = [];
|
||||
if (searchTerm.length < 2) {
|
||||
return;
|
||||
}
|
||||
this.filteredInterests = this.possibleInterests.filter(interest => {
|
||||
if (interest.name.toLowerCase().includes(searchTerm)) {
|
||||
return true;
|
||||
}
|
||||
if (interest.interest_translations && interest.interest_translations.length > 0) {
|
||||
return interest.interest_translations.some(translation => {
|
||||
return translation.translation.toLowerCase().includes(searchTerm);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
getInterestTranslation(interest) {
|
||||
if (interest.interest_translations && interest.interest_translations.length > 0) {
|
||||
let translation = interest.interest_translations.filter(translation => {
|
||||
return translation.user_param_value.value === this.language;
|
||||
});
|
||||
if (translation.length === 0) {
|
||||
translation = interest.interest_translations.filter(translation => {
|
||||
return translation.user_param_value.value === 'en';
|
||||
});
|
||||
if (translation.length === 0) {
|
||||
translation = interest.interest_translations.filter(translation => {
|
||||
return translation.user_param_value.value === 'de';
|
||||
});
|
||||
}
|
||||
}
|
||||
return translation.length > 0 ? translation[0].translation : interest.name;
|
||||
}
|
||||
return interest.name;
|
||||
},
|
||||
async addInterest(interest) {
|
||||
if (!this.userInterests.includes(interest)) {
|
||||
try {
|
||||
await apiClient.post('/api/settings/setinterest', { interestid: interest.id });
|
||||
await this.loadUserInterests();
|
||||
this.newInterest = '';
|
||||
this.filteredInterests = [];
|
||||
} catch (error) {
|
||||
this.messageboxType = 'error';
|
||||
this.messageboxMessage = $t('settings.interests.errorsetinterest')
|
||||
this.$refs.messageboxWidget.open();
|
||||
}
|
||||
}
|
||||
},
|
||||
async addInterestByText() {
|
||||
if (this.newInterest.length > 0) {
|
||||
const newInterest = this.possibleInterests.filter(interest => this.getInterestTranslation(interest) === this.newInterest);
|
||||
if (newInterest.length === 1) {
|
||||
this.addInterest(newInterest[0]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiClient.post('/api/settings/addinterest', {
|
||||
name: this.newInterest
|
||||
});
|
||||
this.messageboxType = 'info';
|
||||
this.messageboxMessage = this.$t('settings.interests.added');
|
||||
} catch (error) {
|
||||
this.messageboxType = 'error';
|
||||
this.messageboxMessage = this.$t('settings.interests.adderror');
|
||||
}
|
||||
this.$refs.messageboxWidget.open();
|
||||
}
|
||||
},
|
||||
async removeInterest(interest) {
|
||||
await apiClient.get('/api/settings/removeinterest/' + interest.id);
|
||||
await this.loadUserInterests();
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.new-interest {
|
||||
position: relative;
|
||||
}
|
||||
.new-interest-proposals {
|
||||
position: absolute;
|
||||
top: 1.5em;
|
||||
left: 0;
|
||||
border: 1px solid #000000;
|
||||
padding: 3px;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.new-interest-proposals > ul {
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
|
||||
}
|
||||
.interest {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.remove {
|
||||
background-color: #ff0000;
|
||||
border: 1px solid #000000;
|
||||
font-size: 8pt;
|
||||
border-radius: 3px;
|
||||
color: #ffffff;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
display: inline-block;
|
||||
padding: 0;
|
||||
line-height: 8px;
|
||||
text-align: center;
|
||||
margin-left: 3px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user