Skip to content

Commit b23871e

Browse files
committed
tmp work on certificates
1 parent 05e4d8e commit b23871e

7 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: certificate
3+
id: 1d4cf6d7-2a63-4e1c-9f43-7a6b4f5a9e1d
4+
event-name: Meetup Testing
5+
certificate-type: Attendance
6+
certificate: ldm-01.svg
7+
---

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ collections:
3737
galleries:
3838
output: true
3939
permalink: /galleries/:path
40+
certificates:
41+
output: true
4042
register:
4143
output: true
4244
permalink: /register/:name/

_layouts/certificate.html

Whitespace-only changes.

_layouts/certificates.html

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
layout: default
3+
---
4+
5+
<script src="https://accounts.google.com/gsi/client" async defer></script>
6+
7+
<style>
8+
.cert-container {
9+
display: grid;
10+
grid-template-columns: 300px 1fr;
11+
gap: 2rem;
12+
padding-top: 90px;
13+
padding-left: 2rem;
14+
padding-right: 2rem;
15+
padding-bottom: 1rem;
16+
}
17+
.user-info {
18+
margin-bottom: 1rem;
19+
}
20+
#certificate-frame {
21+
border: 1px solid #ccc;
22+
width: 100%;
23+
height: 80vh;
24+
}
25+
</style>
26+
27+
<div class="cert-container">
28+
<div>
29+
<div class="user-info" id="user-info">
30+
<div id="g_id_onload"
31+
data-client_id="820930631538-pcpv8qid6rpvgeirjjksbjp06u1f2oi6.apps.googleusercontent.com"
32+
data-callback="handleCredentialResponse">
33+
</div>
34+
<div class="g_id_signin"
35+
data-type="standard"
36+
data-size="large"
37+
data-theme="outline"
38+
data-text="sign_in_with"
39+
data-shape="rect"
40+
data-logo_alignment="left">
41+
</div>
42+
</div>
43+
44+
<select id="events-dropdown" style="display:none; width:100%; padding:0.5rem;">
45+
<option value="">Select your event certificate</option>
46+
</select>
47+
</div>
48+
49+
<div>
50+
<iframe id="certificate-frame"></iframe>
51+
</div>
52+
</div>
53+
54+
<script>
55+
let googleUser = null;
56+
57+
async function handleCredentialResponse(response) {
58+
const data = parseJwt(response.credential);
59+
googleUser = data;
60+
document.getElementById('user-info').innerHTML =
61+
`<p><strong>${data.name}</strong><br>${data.email}</p>`;
62+
await loadEvents(data.sub);
63+
}
64+
65+
function parseJwt(token) {
66+
const base64Url = token.split('.')[1];
67+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
68+
const jsonPayload = decodeURIComponent(atob(base64).split('').map(c =>
69+
'%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
70+
).join(''));
71+
return JSON.parse(jsonPayload);
72+
}
73+
74+
async function loadEvents(userId) {
75+
try {
76+
const res = await fetch('https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/my-certificates', {
77+
method: 'POST',
78+
headers: {'Content-Type': 'application/json'},
79+
body: JSON.stringify({ user_id: userId })
80+
});
81+
if (!res.ok) throw new Error('Failed fetching events');
82+
const events = await res.json();
83+
84+
const dropdown = document.getElementById('events-dropdown');
85+
dropdown.innerHTML = '<option value="">Select your event certificate</option>';
86+
events.forEach(id => {
87+
dropdown.innerHTML += `<option value="${id}">${id}</option>`;
88+
});
89+
dropdown.style.display = 'block';
90+
91+
dropdown.addEventListener('change', e => {
92+
if (e.target.value) loadCertificate(e.target.value);
93+
});
94+
95+
} catch (e) {
96+
console.error(e);
97+
}
98+
}
99+
100+
async function loadCertificate(eventId) {
101+
// Since Jekyll builds everything statically, we must load the collection index at build time.
102+
// We'll expose them via `site.certificates` below:
103+
// const allCertificates = {{ site.certificates | jsonify }};
104+
// const cert = allCertificates.find(c => c.id === eventId);
105+
// if (!cert) {
106+
// alert('Certificate not found');
107+
// return;
108+
// }
109+
110+
// const svgPath = `{{ '/assets/certificates/' | relative_url }}${cert.certificate}`;
111+
// document.getElementById('certificate-frame').src = svgPath;
112+
}
113+
</script>

assets/certificates/ldm-01.svg

Loading

certificates.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: certificates
3+
title: "Certificates"
4+
permalink: /certificates/
5+
---

tmp.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
#### test untuk certificate generator
3+
4+
5+
curl -X POST "https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/attend-event" \
6+
-H "Content-Type: application/json" \
7+
-H "apikey: YOUR_ANON_OR_SERVICE_ROLE_KEY" \
8+
-d '{
9+
"event_id": "1d4cf6d7-2a63-4e1c-9f43-7a6b4f5a9e1d",
10+
"google_account_id": "google-12345"
11+
}'
12+
13+
14+
curl -X POST \
15+
'https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/get-certificate' \
16+
-H 'Content-Type: application/json' \
17+
-d '{
18+
"user_id": "google-12345",
19+
"event_id": "1d4cf6d7-2a63-4e1c-9f43-7a6b4f5a9e1d"
20+
}'
21+
22+
curl -X POST \
23+
'https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/get-certificate' \
24+
-H 'Content-Type: application/json' \
25+
-d '{
26+
"user_id": "117136972624263020014",
27+
"event_id": "26b5ada4-8808-45ed-90ca-c66301221b33"
28+
}'
29+
30+
31+
32+
curl -X POST \
33+
'https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/check-certificate' \
34+
-H 'Content-Type: application/json' \
35+
-d '{
36+
"certificate_id": "aHP4Nq7qq35UbmCUOsa5"
37+
}'
38+
39+
40+
curl "https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/check-certificate?certificate-id=aHP4Nq7qq35UbmCUOsa5"
41+
42+
43+
44+
curl -X POST \
45+
'https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/my-certificates' \
46+
-H 'Content-Type: application/json' \
47+
-d '{
48+
"user_id": "google-12345",
49+
"event_id": "1d4cf6d7-2a63-4e1c-9f43-7a6b4f5a9e1d"
50+
}'
51+
52+
curl -X POST \
53+
'https://xrxfvavgbcphhywznrfq.supabase.co/functions/v1/my-certificates' \
54+
-H 'Content-Type: application/json' \
55+
-d '{
56+
"user_id": "117136972624263020014"
57+
}'

0 commit comments

Comments
 (0)