Skip to content

Commit d1f280c

Browse files
committed
Fix donation and Recaptcha settings
1 parent 8b122c8 commit d1f280c

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

routes/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const util = require('util');
33
const express = require('express');
4-
const request = require('request');
4+
const request = require('request-promise-native');
55
const store = require('../store');
66
const router = express.Router();
77

@@ -41,6 +41,7 @@ const titles = {
4141
socket: ':' + settings.socket,
4242
title: titles[page],
4343
stripePublishKey: settings.stripePublishKey,
44+
googleCaptchaKey: settings.googleCaptchaKey,
4445
stats: store.get('stats')['30'].total,
4546
latestVersion: settings.latestVersion
4647
});
@@ -50,22 +51,22 @@ const titles = {
5051
});
5152

5253
router.post('/donate', async (req, res, next) => {
53-
let data;
54+
let data, captchaBody;
5455
try {
5556
data = JSON.parse(req.body.data);
56-
let body = await request.post({
57+
captchaBody = await request.post({
5758
url:'https://www.google.com/recaptcha/api/siteverify',
5859
form: {
59-
secret: settings.googleCaptchaKey,
60+
secret: settings.googleCaptchaSecretKey,
6061
response: data.recaptcha
6162
}
6263
});
63-
body = JSON.parse(body);
64+
captchaBody = JSON.parse(captchaBody);
65+
if (process.env.spec === "true") captchaBody = {success: true};
6466
} catch (e) {
65-
if (process.env.spec === "true") body = {success: true};
66-
else return res.sendStatus(400);
67+
if (process.env.spec === "true") throw e;
6768
}
68-
if (body.success === true) {
69+
if (captchaBody.success === true) {
6970
data = JSON.parse(req.body.data);
7071
stripe.charges.create({
7172
amount: data.token.price,

settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"latestVersion": "1.3",
88
"stripePublishKey": "",
99
"stripePrivateKey": "",
10-
"googleCaptchaKey": ""
10+
"googleCaptchaKey": "",
11+
"googleCaptchaSecretKey": ""
1112
}

views/pages/donate.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<script>
101101
var onloadCallback = function() {
102102
grecaptcha.render('recaptcha', {
103-
'sitekey' : '6LeN-qUUAAAAALFyEP8fNstJZ9CT9hUWZ3RbcfZ6',
103+
'sitekey' : '<%=googleCaptchaKey%>',
104104
'callback': 'recaptchaCallback'
105105
});
106106
let btn = document.getElementById('donate_button');

0 commit comments

Comments
 (0)