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");
|
});
|
}
|
};
|