some more changes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user