Skip to content

Commit

Permalink
add page template
Browse files Browse the repository at this point in the history
  • Loading branch information
r0zbot committed Mar 5, 2021
1 parent e2e2acf commit 1fbab05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/user-data-download/server/DataExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ export const DataExport = {
res.end();
},

getErrorPage(errorType, errorDescription) {
let errorHtml = Assets.getText('errors/error_template.html');
errorHtml = errorHtml.replace('$ERROR_TYPE$', errorType);
errorHtml = errorHtml.replace('$ERROR_DESCRIPTION$', errorDescription);
errorHtml = errorHtml.replace('$SERVER_URL$', __meteor_runtime_config__.ROOT_URL);
return errorHtml;
},

};
8 changes: 5 additions & 3 deletions app/user-data-download/server/exportDownload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WebApp } from 'meteor/webapp';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { UserDataFiles } from '../../models';
import { DataExport } from './DataExport';
Expand All @@ -10,16 +11,17 @@ WebApp.connectHandlers.use(DataExport.getPath(), function(req, res, next) {

if (!settings.get('UserData_EnableDownload')) {
res.writeHead(403);
return res.end('Sorry, user data exports are not enabled on this server!');
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
return res.end(DataExport.getErrorPage('Feature disabled', 'Sorry, user data exports are not enabled on this server!'));
}

if (match && match[1]) {
const file = UserDataFiles.findOneById(match[1]);
if (file) {
if (!DataExport.requestCanAccessFiles(req, file.userId)) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.writeHead(403);
// TODO: prettify error
return res.end('You need to log into your Rocket.Chat account to download this data export.');
return res.end(DataExport.getErrorPage('Forbidden', 'You need to log into your Rocket.Chat account to download this data export. Click the link below to do that.'));
}

res.setHeader('Content-Security-Policy', 'default-src \'none\'');
Expand Down
30 changes: 30 additions & 0 deletions private/errors/error_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html>
<style type="text/css">
body {
margin: 40px auto;
max-width: 650px;
line-height: 1.4;
font-size: 18px;
color: #444;
padding: 0 10px
}

h1, h2, h3 {
line-height: 1.2
}

div {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
</style>
<body>
<div>
<h1>$ERROR_TYPE$</h1>
<p>$ERROR_DESCRIPTION$</p>
<p><a href='$SERVER_URL$'>Go home</a></p>
</div>
</body>
</html>

0 comments on commit 1fbab05

Please sign in to comment.