Przeglądaj źródła

Add procedures for email verification

master
Immanuel Onyeka 7 miesięcy temu
rodzic
commit
1ea00f2b0e
1 zmienionych plików z 26 dodań i 0 usunięć
  1. +26
    -0
      skouter.go

+ 26
- 0
skouter.go Wyświetl plik

@@ -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):


Ładowanie…
Anuluj
Zapisz