Skip to content

Commit

Permalink
Delayed consent screen
Browse files Browse the repository at this point in the history
  • Loading branch information
spolischook committed Oct 13, 2024
1 parent 416698b commit 68b65b3
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
89 changes: 89 additions & 0 deletions cmd/testGoogleJWT/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/gin-gonic/gin"
)

func main() {
router := gin.Default()

// Route to handle POST request to receive JWT token
router.POST("/token", func(c *gin.Context) {
var json struct {
Token string `json:"token" binding:"required"`
}

// Bind incoming JSON data
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
return
}

// Log the received token
fmt.Println("Received JWT token:", json.Token)

// Use the token to access the Google Sheet and convert to CSV
csvData, err := getSheetDataAsCSV(json.Token)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

err = ioutil.WriteFile("/tmp/inventory.csv", []byte(csvData), 0644)
if err != nil {
panic(err)
}

fmt.Println("CSV data saved to /tmp/inventory.csv")

// Return the CSV data as a response
c.Header("Content-Type", "text/csv")
c.String(http.StatusOK, "")
})

// Start the server
router.Run(":8080")
}

// getSheetDataAsCSV retrieves Google Sheet data using an access token and converts it to CSV format
func getSheetDataAsCSV(token string) (string, error) {
// Replace with your specific Google Sheets API endpoint for exporting the spreadsheet as CSV
sheetID := "1MPkRsuhJhJdYlTCOxHFiJoFX3DZalZPbTOUObacJPg0"
gid := "1746605435"
url := fmt.Sprintf("https://docs.google.com/spreadsheets/d/%s/export?format=csv&gid=%s", sheetID, gid)

// Make an authenticated GET request to Google Sheets API using the provided access token
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}

// Set the Authorization header with the access token
req.Header.Set("Authorization", "Bearer "+token)

// Execute the request
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()

// Check if the response was successful
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
return "", fmt.Errorf("failed to fetch Google Sheet: %s", string(bodyBytes))
}

// Read the response body (CSV data)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

return string(body), nil
}
9 changes: 5 additions & 4 deletions layouts/partials/privacy-notice.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ <h2 class="text-lg font-semibold mb-4">We value your privacy</h2>
// Perform actions if the cookie exists
} else {
// remove hidden class from consentForm and add flex class
document.getElementById('consentForm').classList.remove('hidden');
document.getElementById('consentForm').classList.add('flex');
console.log('cookieConsentEssential does not exist');
// Perform actions if the cookie does not exist
setTimeout(function() {
document.getElementById('consentForm').classList.remove('hidden');
document.getElementById('consentForm').classList.add('flex');
console.log('cookieConsentEssential does not exist');
}, 5000); // Delay of 5000 milliseconds (5 seconds)
}
const acceptButton = document.getElementById('cookieAccept');
const declineButton = document.getElementById('cookieDecline');
Expand Down

0 comments on commit 68b65b3

Please sign in to comment.