dh_ackergaul
2026-06-03 a25433795ec239654db2ef31af6d3f4e84b3b8dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { decode } = FurncloudSecurity;
const WebviewerError = require("furncloud-library").Errors.WebviewerError;
const FurnplanInstanceHistoryService = require("../services/FurnplanInstaceHistoryService.js");
 
module.exports = {
 
    /**
     * Article viewer page by manufacturer, program and article number.
     */
    view: function (req, res) {
        const language = req.query.lang || "de";
        req.setLocale(language);
 
        const token = req.query.token;
 
        Promise.all([
            req.user || Opus.login(token, "webshopViewer", "webshopViewer"),
            FurncloudCredential.findOne({ token: token })
        ])
            .then(async function ([user, credential]) {
 
                user.customerNo = credential.customerNo;
                user.userAgent = req.get("user-agent");
 
                if (req.query.land && req.query.schiene) {
                    user.data.tenant = (`${req.query.land}-${req.query.schiene}`) || "";
                }
                else if (req.query.tenant) {
                    user.data.tenant = req.query.tenant;
                }
                else {
                    user.data.tenant = "";
                }
 
                return Promise.all([
                    user,
                    true, // Für Messe
                    Helper.isLocalRequest(req.connection.remoteAddress),
                    Session.update({ _id: req.session._id }, { $addToSet: { users: user } }).exec()
                ]);
            })
            .then(async function ([user]) {
                const newConfiguration = await ConfigurationManager.getHRConfiguration();
 
                //Switch between furnview and furnview in wizard mode
                const path = "webviewer/view";
 
                return res.view(path, {
                    g_auth_id: req.auth_cookie.id,
                    g_configuration: newConfiguration,
                    g_article: {},
                    g_manufacturer: "",
                    g_sessionId: user.opusSessionId,
                    g_language: req.query.lang || req.getLocale(),
                    g_reCaptcha: ""
                });
            })
            .catch(function (error) {
                if (error instanceof WebviewerError.InvalidConfigurationId || error instanceof WebviewerError.NoPermission) {
                    Winston.warn("HRConfigurator: " + error.getMessage(), error);
                    return res.send(422, error.getMessage());
                }
                Winston.warn("Unable to open HRConfigurator. ", error);
                return res.send(500, "internal server error");
            });
    }
};