Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #71 from karthikv/export-redirect

Make exported project respect authentication redirects.
  • Loading branch information...
commit ce332a2e087bb527c84de7de94e12faff9f1ac41 2 parents 514e580 + 1c8cabd
@karthikv karthikv authored
Showing with 19 additions and 9 deletions.
  1. +14 −8 export/index.js
  2. +5 −1 views/helpers/share-login-form.jade
View
22 export/index.js
@@ -377,20 +377,26 @@ function renderEjsTemplate(template, attributes, screensById) {
template = template.replace(
/\/share\/#\{session.sharedId\}\/project\/#\{projectId\}\/screen\/#\{screenId\}/g, '');
- /* Replaces a screen id from a regular expression with a corresponding link.
- * Requires: regular expression match, screen id
- * Returns: corresponding screen link
+ /* Replaces a screen id with its corresponding title slug. Returns a function
+ * that should be used as a regular expression replace callback.
+ * Requires: format for the replacement string, where %s will be replaced
+ * with the slug
+ * Returns: regular expression replace callback assuming that the first
+ * capture group is the screen id
*/
- function replaceLink(match, screenId) {
- screenId = parseInt(screenId, 10);
- return '/' + screensById[screenId].titleSlug;
+ function replaceLink(format) {
+ return function(match, screenId) {
+ screenId = parseInt(screenId, 10);
+ return format.replace(/%s/g, screensById[screenId].titleSlug);
+ };
}
// screen link targets need to be translated to screen routes
template = template.replace(/\/share\/#\{userId\}\/project\/#\{projectId\}\/screen\/(\d+)/g,
- replaceLink);
+ replaceLink('/%s'));
template = template.replace(/\/share\/#\{session.sharedId\}\/project\/#\{projectId\}\/screen\/(\d+)/g,
- replaceLink);
+ replaceLink('/%s'));
+ template = template.replace(/\?redirect=(\d+)/, replaceLink('?redirect=%s'));
// no need for unescaped attributes
template = template.replace(/!=/g, '=');
View
6 views/helpers/share-login-form.jade
@@ -1,5 +1,9 @@
+<% if (typeof redirect === 'undefined') { %>
+<% redirect = ''; %>
+<% } %>
+
form.login-form(method='post',
- action!="/share/#{userId}/project/#{projectId}/screen/#{screenId}/log-in?redirect=<%= this.redirect || '' %>")
+ action!="/share/#{userId}/project/#{projectId}/screen/#{screenId}/log-in?redirect=<%= redirect %>")
a.persona-button.share-element.auth(href='#log-in')
span Sign in
input(type='hidden', name='bid_assertion', value='1')
Please sign in to comment.
Something went wrong with that request. Please try again.