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