Skip to content
Merged
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
3 changes: 0 additions & 3 deletions packages/handlers/handle-generate-docx.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ function buildRencanaKegiatan (body, kegiatanKeys) {
*/
const handleGenerateDocx = async (body) => {
// Validate hCaptcha response before proceeding with document generation
if (!body['h-captcha-response']) {
return { status: 400, message: 'hCaptcha response token is missing' }
}
if (!await handleHCaptchaValidation(body)) {
return { status: 400, message: 'hCaptcha validation failed' }
}
Expand Down
11 changes: 10 additions & 1 deletion packages/handlers/handle-hcaptcha-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ import { verify } from 'hcaptcha'
* @returns {Promise<boolean>} - A promise that resolves to true if the hCaptcha validation is successful, or false otherwise.
*/
const handleHCaptchaValidation = async (body) => {
const { 'h-captcha-response': hCaptchaResponse } = body
const secret = String(process.env.HCAPTCHA_SECRET_KEY)
if (!secret) {
console.warn('Bypassing hCaptcha validation because HCAPTCHA_SECRET_KEY is not set in environment variables.')
return true
}

const { 'h-captcha-response': hCaptchaResponse } = body
if (!hCaptchaResponse) {
console.warn('hCaptcha response token is missing in the request body.')
return false
}

try {
const result = await verify(secret, hCaptchaResponse)
Expand Down
10 changes: 8 additions & 2 deletions resources/views/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@
<span>Export Template</span>
</button>
</div>
<div class="h-captcha mt-4" data-sitekey="<%= META.HCAPTCHA_SITE_KEY %>"></div>

<% if (META.HCAPTCHA_SITE_KEY) { %>
<div class="h-captcha mt-4" data-sitekey="<%= META.HCAPTCHA_SITE_KEY %>"></div>
<% } %>

<button id="rppFormSubmitBtn" type="submit" class="w-full mt-4 p-2 bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-700 focus:ring-offset-2">
<span>Buat Dokumen</span>
</button>
Expand All @@ -390,7 +394,9 @@
</div>
</template>

<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
<% if (META.HCAPTCHA_SITE_KEY) { %>
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
<% } %>
<script src="/js/SwalWrapper.js"></script>
<script src="/js/loading-indicator.js"></script>
<script src="/js/home.js"></script>
Expand Down
Loading