Compare commits
No commits in common. "2e3d0a755cc51619c90a5ed407420fbaa6ab692b" and "b4a7986c8a2e631cc2c747206b5814a69b941637" have entirely different histories.
2e3d0a755c
...
b4a7986c8a
10 changed files with 24 additions and 166 deletions
|
@ -9,7 +9,7 @@ import { SettingString } from "../../../type/settingTypes";
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getSettings(req: Request, res: Response): Promise<any> {
|
||||
res.json({ ...SettingHelper.getAllSettings(), ["mail.password"]: undefined });
|
||||
res.json(SettingHelper.getAllSettings());
|
||||
}
|
||||
|
||||
/**
|
|
@ -35,7 +35,7 @@ export async function getInvites(req: Request, res: Response): Promise<any> {
|
|||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function inviteUser(req: Request, res: Response, isSetup: boolean = false): Promise<any> {
|
||||
export async function inviteUser(req: Request, res: Response, isInvite: boolean = true): Promise<any> {
|
||||
let origin = req.headers.origin;
|
||||
let username = req.body.username;
|
||||
let mail = req.body.mail;
|
||||
|
@ -71,7 +71,7 @@ export async function inviteUser(req: Request, res: Response, isSetup: boolean =
|
|||
await MailHelper.sendMail(
|
||||
mail,
|
||||
`Email Bestätigung für Mitglieder Admin-Portal von ${SettingHelper.getSetting("club.name")}`,
|
||||
`Öffne folgenden Link: ${origin}/${isSetup ? "setup" : "invite"}/verify?mail=${mail}&token=${token}`
|
||||
`Öffne folgenden Link: ${origin}/${isInvite ? "invite" : "setup"}/verify?mail=${mail}&token=${token}`
|
||||
);
|
||||
|
||||
res.sendStatus(204);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Request, Response } from "express";
|
||||
import SettingHelper from "../helpers/settingsHelper";
|
||||
|
||||
/**
|
||||
* @description Service is currently not configured
|
||||
|
@ -10,89 +9,3 @@ import SettingHelper from "../helpers/settingsHelper";
|
|||
export async function isSetup(req: Request, res: Response): Promise<any> {
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description set club identity
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function setClubIdentity(req: Request, res: Response): Promise<any> {
|
||||
const name = req.body.name;
|
||||
const imprint = req.body.imprint;
|
||||
const privacy = req.body.privacy;
|
||||
const website = req.body.website;
|
||||
|
||||
if (name) {
|
||||
await SettingHelper.setSetting("club.name", name);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.name");
|
||||
}
|
||||
|
||||
if (imprint) {
|
||||
await SettingHelper.setSetting("club.imprint", imprint);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.imprint");
|
||||
}
|
||||
|
||||
if (privacy) {
|
||||
await SettingHelper.setSetting("club.privacy", privacy);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.privacy");
|
||||
}
|
||||
|
||||
if (website) {
|
||||
await SettingHelper.setSetting("club.website", website);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.website");
|
||||
}
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description set applucation icon and logo
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function uploadClubImages(req: Request, res: Response): Promise<any> {
|
||||
if (req.files && !Array.isArray(req.files) && req.files.icon) {
|
||||
await SettingHelper.setSetting("club.icon", "configured");
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.icon");
|
||||
}
|
||||
|
||||
if (req.files && !Array.isArray(req.files) && req.files.logo) {
|
||||
await SettingHelper.setSetting("club.logo", "configured");
|
||||
} else {
|
||||
await SettingHelper.resetSetting("club.logo");
|
||||
}
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description set app identity
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function setAppIdentity(req: Request, res: Response): Promise<any> {
|
||||
const custom_login_message = req.body.custom_login_message;
|
||||
const show_link_to_calendar = req.body.show_link_to_calendar;
|
||||
|
||||
if (custom_login_message) {
|
||||
await SettingHelper.setSetting("app.custom_login_message", custom_login_message);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("app.custom_login_message");
|
||||
}
|
||||
|
||||
if (show_link_to_calendar) {
|
||||
await SettingHelper.setSetting("app.show_link_to_calendar", show_link_to_calendar);
|
||||
} else {
|
||||
await SettingHelper.resetSetting("app.show_link_to_calendar");
|
||||
}
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
|
|
@ -64,19 +64,17 @@ export default abstract class SettingHelper {
|
|||
* @param key The key of the setting
|
||||
* @param value The value to set
|
||||
*/
|
||||
public static async setSetting<K extends SettingString>(key: K, value: SettingValueMapping[K]): Promise<void> {
|
||||
public static async setSetting(key: SettingString, value: string): Promise<void> {
|
||||
if (value === undefined || value === null) return;
|
||||
|
||||
const stringValue = String(value);
|
||||
|
||||
const settingType = settingsType[key];
|
||||
this.validateSetting(key, stringValue);
|
||||
this.validateSetting(key, value);
|
||||
|
||||
const oldValue = this.getSetting(key);
|
||||
let finalValue = stringValue;
|
||||
let finalValue = value;
|
||||
|
||||
if (typeof settingType.type === "string" && settingType.type.includes("/crypt")) {
|
||||
finalValue = CodingHelper.encrypt(APPLICATION_SECRET, stringValue);
|
||||
finalValue = CodingHelper.encrypt(APPLICATION_SECRET, value);
|
||||
}
|
||||
|
||||
this.settings[key] = finalValue;
|
||||
|
@ -97,8 +95,6 @@ export default abstract class SettingHelper {
|
|||
* @param key The key of the setting
|
||||
*/
|
||||
public static async resetSetting(key: SettingString): Promise<void> {
|
||||
if (this.getSetting(key) == String(settingsType[key].default ?? "")) return;
|
||||
|
||||
const oldValue = this.getSetting(key);
|
||||
|
||||
const settingType = settingsType[key];
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import multer from "multer";
|
||||
import { FileSystemHelper } from "../helpers/fileSystemHelper";
|
||||
import path from "path";
|
||||
|
||||
export const clubImageStorage = multer.diskStorage({
|
||||
destination: FileSystemHelper.formatPath("/app"),
|
||||
filename: function (req, file, cb) {
|
||||
const fileExtension = path.extname(file.originalname).toLowerCase();
|
||||
|
||||
if (file.fieldname === "icon") {
|
||||
cb(null, "company-icon" + fileExtension);
|
||||
} else if (file.fieldname === "logo") {
|
||||
cb(null, "company-logo" + fileExtension);
|
||||
} else {
|
||||
cb(null, file.originalname);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const clubImageMulter = multer({
|
||||
storage: clubImageStorage,
|
||||
});
|
||||
|
||||
export const clubImageUpload = clubImageMulter.fields([
|
||||
{ name: "icon", maxCount: 1 },
|
||||
{ name: "logo", maxCount: 1 },
|
||||
]);
|
|
@ -1,7 +1,6 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import { setting_table } from "./baseSchemaTables/admin";
|
||||
import SettingHelper from "../helpers/settingsHelper";
|
||||
import ms from "ms";
|
||||
|
||||
export class SettingsFromEnv1745059495808 implements MigrationInterface {
|
||||
name = "SettingsFromEnv1745059495808";
|
||||
|
@ -12,19 +11,16 @@ export class SettingsFromEnv1745059495808 implements MigrationInterface {
|
|||
//transfer settings of env to database
|
||||
await SettingHelper.setSetting("club.name", process.env.CLUB_NAME);
|
||||
await SettingHelper.setSetting("club.website", process.env.CLUB_WEBSITE);
|
||||
await SettingHelper.setSetting("session.jwt_expiration", process.env.JWT_EXPIRATION as ms.StringValue);
|
||||
await SettingHelper.setSetting("session.refresh_expiration", process.env.REFRESH_EXPIRATION as ms.StringValue);
|
||||
await SettingHelper.setSetting(
|
||||
"session.pwa_refresh_expiration",
|
||||
process.env.PWA_REFRESH_EXPIRATION as ms.StringValue
|
||||
);
|
||||
await SettingHelper.setSetting("session.jwt_expiration", process.env.JWT_EXPIRATION);
|
||||
await SettingHelper.setSetting("session.refresh_expiration", process.env.REFRESH_EXPIRATION);
|
||||
await SettingHelper.setSetting("session.pwa_refresh_expiration", process.env.PWA_REFRESH_EXPIRATION);
|
||||
await SettingHelper.setSetting("mail.username", process.env.MAIL_USERNAME);
|
||||
await SettingHelper.setSetting("mail.password", process.env.MAIL_PASSWORD);
|
||||
await SettingHelper.setSetting("mail.host", process.env.MAIL_HOST);
|
||||
await SettingHelper.setSetting("mail.port", Number(process.env.MAIL_PORT));
|
||||
await SettingHelper.setSetting("mail.secure", Boolean(process.env.MAIL_SECURE));
|
||||
await SettingHelper.setSetting("backup.interval", Number(process.env.BACKUP_INTERVAL));
|
||||
await SettingHelper.setSetting("backup.copies", Number(process.env.BACKUP_COPIES));
|
||||
await SettingHelper.setSetting("mail.port", process.env.MAIL_PORT);
|
||||
await SettingHelper.setSetting("mail.secure", process.env.MAIL_SECURE);
|
||||
await SettingHelper.setSetting("backup.interval", process.env.BACKUP_INTERVAL);
|
||||
await SettingHelper.setSetting("backup.copies", process.env.BACKUP_COPIES);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
import express, { Request, Response } from "express";
|
||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||
import {
|
||||
getSetting,
|
||||
getSettings,
|
||||
resetSetting,
|
||||
setSetting,
|
||||
} from "../../../controller/admin/management/settingController";
|
||||
import { getSetting, getSettings, resetSetting, setSetting } from "../../../controller/admin/management/setting";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
updateUserPermissions,
|
||||
updateUserRoles,
|
||||
} from "../../../controller/admin/management/userController";
|
||||
import { inviteUser } from "../../../controller/inviteController";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import express from "express";
|
||||
import { finishInvite, verifyInvite } from "../controller/inviteController";
|
||||
import { isSetup } from "../controller/setupController";
|
||||
import { finishInvite, inviteUser, verifyInvite } from "../controller/inviteController";
|
||||
import ParamaterPassCheckHelper from "../helpers/parameterPassCheckHelper";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import express from "express";
|
||||
import { isSetup, setAppIdentity, setClubIdentity, uploadClubImages } from "../controller/setupController";
|
||||
import { isSetup } from "../controller/setupController";
|
||||
import { finishInvite, inviteUser, verifyInvite } from "../controller/inviteController";
|
||||
import ParamaterPassCheckHelper from "../helpers/parameterPassCheckHelper";
|
||||
import { clubImageUpload } from "../middleware/multer";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
|
@ -10,37 +9,21 @@ router.get("/", async (req, res) => {
|
|||
await isSetup(req, res);
|
||||
});
|
||||
|
||||
router.post("/club", async (req, res) => {
|
||||
await setClubIdentity(req, res);
|
||||
});
|
||||
|
||||
router.post("/club/images", clubImageUpload, async (req, res) => {
|
||||
await uploadClubImages(req, res);
|
||||
});
|
||||
|
||||
router.post("/app", async (req, res) => {
|
||||
await setAppIdentity(req, res);
|
||||
});
|
||||
|
||||
router.post("/verify", ParamaterPassCheckHelper.requiredIncludedMiddleware(["mail", "token"]), async (req, res) => {
|
||||
await verifyInvite(req, res);
|
||||
});
|
||||
|
||||
router.post(
|
||||
"/me",
|
||||
"/",
|
||||
ParamaterPassCheckHelper.requiredIncludedMiddleware(["username", "mail", "firstname", "lastname"]),
|
||||
async (req, res) => {
|
||||
await inviteUser(req, res, true);
|
||||
await inviteUser(req, res, false);
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/finish",
|
||||
ParamaterPassCheckHelper.requiredIncludedMiddleware(["mail", "token", "totp"]),
|
||||
async (req, res) => {
|
||||
await finishInvite(req, res, true);
|
||||
}
|
||||
);
|
||||
router.put("/", ParamaterPassCheckHelper.requiredIncludedMiddleware(["mail", "token", "totp"]), async (req, res) => {
|
||||
await finishInvite(req, res, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
|
|
Loading…
Add table
Reference in a new issue