From 1ea00f2b0e3d94a7cc4dbf49d59c84808019b73e Mon Sep 17 00:00:00 2001
From: Immanuel Onyeka <immanuel@debian-BULLSEYE-live-builder-AMD64>
Date: Mon, 12 Feb 2024 21:19:08 -0500
Subject: [PATCH] Add procedures for email verification

---
 skouter.go | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/skouter.go b/skouter.go
index 1160d9b..1291905 100644
--- a/skouter.go
+++ b/skouter.go
@@ -110,6 +110,11 @@ type UserClaims struct {
 	Exp  string `json:"exp"`
 }
 
+type VerificationClaims struct {
+	Id   int    `json:"id"`
+	Exp  string `json:"exp"`
+}
+
 type Page struct {
 	tpl   *template.Template
 	Title string
@@ -3347,6 +3352,24 @@ func subDeleted(w http.ResponseWriter, db *sql.DB, r *http.Request) {
 	log.Println("User subscription created:", user.Id, sub.ID)
 }
 
+func verificationToken(id int) string {
+	token := jwt.NewWithClaims(jwt.SigningMethodHS256,
+		VerificationClaims{Id: id,
+			Exp: time.Now().Add(time.Day * 2).Format(time.UnixDate)})
+
+	tokenStr, err := token.SignedString([]byte(os.Getenv("JWT_SECRET")))
+	if err != nil {
+		log.Println("Verification could not be signed: ", err, tokenStr)
+		return err
+	}
+
+	return tokenStr
+}
+
+func verifyUser(w http.ResponseWriter, db *sql.DB, r *http.Request) {
+
+}
+
 func api(w http.ResponseWriter, r *http.Request) {
 	var args []string
 
@@ -3397,6 +3420,9 @@ func api(w http.ResponseWriter, r *http.Request) {
 		r.Method == http.MethodDelete &&
 		guard(r, 3):
 		deleteUser(w, db, r)
+	case match(p, "/api/user/verify", &args) &&
+		r.Method == http.MethodGet:
+		verifyUser(w, db, r)
 	case match(p, "/api/user/avatar", &args) &&
 		r.Method == http.MethodGet &&
 		guard(r, 1):