some more changes

This commit is contained in:
2022-03-21 01:37:16 +01:00
parent cb992c955a
commit c6bef04c73
62 changed files with 2293 additions and 9965 deletions

View File

@@ -51,7 +51,21 @@ func Login(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"username": user.Username, "email": user.Email})
}
func Verify(c *gin.Context) {
tokenCookie, err := c.Cookie("token")
if err != nil || tokenCookie == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
claims, err := auth.VerifyJWT(tokenCookie)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
c.JSON(http.StatusOK, gin.H{"username": claims["username"], "email": claims["email"]})
}
func Logout(c *gin.Context) {
c.SetCookie("token", "", -1, "", "", false, true)
c.Redirect(http.StatusTemporaryRedirect, "/")
c.Status(http.StatusOK)
}

View File

@@ -6,4 +6,5 @@ func Setup(r *gin.RouterGroup) {
r.GET("/logout", Logout)
r.POST("/login", Login)
r.POST("/register", Register)
r.GET("/verify", Verify)
}