Skip to content

Fix broken resend email validation link #4002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions spec/EmailVerificationToken.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe("Email Verification Token Expiration: ", () => {
request.get(sendEmailOptions.link, {
followRedirect: false,
}, (error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test');
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are those changed? That seems to be a breaking change

done();
});
}, 1000);
Expand Down Expand Up @@ -408,8 +407,7 @@ describe("Email Verification Token Expiration: ", () => {
request.get(sendEmailOptions.link, {
followRedirect: false,
}, (error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test');
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link');
done();
});
})
Expand Down
49 changes: 45 additions & 4 deletions src/Routers/PublicAPIRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,55 @@ export class PublicAPIRouter extends PromiseRouter {
});
}

/**
* loading the template for invalid verification link page
* this method returns the template for the page stored in memory
* on first access it will load the template file from disk
*/
loadInvalidVerificationLinkPageTemplate(config) {
if (this.invalid_verification_link_page_template_file) {
return this.invalid_verification_link_page_template_file;
} else {
this.invalid_verification_link_page_template_file = this.loadPageTemplateFile("invalid_verification_link");
if (this.invalid_verification_link_page_template_file) {
this.invalid_verification_link_page_template_file = this.invalid_verification_link_page_template_file.replace("PARSE_SERVER_URL", `'${config.publicServerURL}'`);
}
return this.invalid_verification_link_page_template_file;
}
}

loadPageTemplateFile(filename) {
fs.readFile(path.resolve(views, filename), 'utf-8', (err, data) => {
if (err) {
return null;
}
return data;
});
}

invalidVerificationLink(req) {
const config = req.config;
if (req.query.username && req.params.appId) {
const params = qs.stringify({username: req.query.username, appId: req.params.appId});
if (!config.publicServerURL) {
return Promise.resolve({
status: 302,
location: `${config.invalidVerificationLinkURL}?${params}`
status: 404,
text: 'Not found.'
});
}

if (req.query.username && req.params.appId) {
// load page template from file or from memory
var invalid_verification_link_page = this.loadInvalidVerificationLinkPageTemplate(config);
if (invalid_verification_link_page) {
// replace dynamic template attributes
invalid_verification_link_page = invalid_verification_link_page.replace("USERNAME", `'${req.query.username}'`);
invalid_verification_link_page = invalid_verification_link_page.replace("APPID", `'${req.params.appId}'`);
// send page to the client
return Promise.resolve({
text: invalid_verification_link_page
});
} else {
Promise.reject("Could not load invalid_verification_link template.");
}
} else {
return this.invalidLink(req);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,16 @@
</style>
</head>
<script type="text/javascript">
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

window.onload = addDataToForm;

function addDataToForm() {
var username = getUrlParameter("username");
// these values will be set in PublicAPIRouter
var base = PARSE_SERVER_URL;
var username = USERNAME;
var appId = APPID;

document.getElementById("usernameField").value = username;

var appId = getUrlParameter("appId");
document.getElementById("resendForm").action = '/apps/' + appId + '/resend_verification_email'
document.getElementById("resendForm").action = base + '/apps/' + appId + '/resend_verification_email'
}

</script>
Expand Down