chore: trackit route and tracking with no auth with ip address
This commit is contained in:
parent
54d3c18436
commit
08c07fb009
@ -95,20 +95,21 @@ func post_tracking_handle(c *gin.Context, rtenv *RouteEnv) {
|
||||
}
|
||||
userid := trackpost.Data
|
||||
_, okmdl := rtenv.MdlsUsrs[userid]
|
||||
auth := ""
|
||||
if !okmdl {
|
||||
_, okusr := rtenv.Users.Accounts[userid]
|
||||
if !okusr {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Authentication failed"})
|
||||
return
|
||||
// if !okusr {
|
||||
// c.JSON(http.StatusUnauthorized, gin.H{"error": "Authentication failed"})
|
||||
// return
|
||||
// }
|
||||
if okusr && rtenv.Cfg.UseJWT {
|
||||
tk, errtk := rtenv.AuthMiddleware.ParseToken(c)
|
||||
if errtk == nil {
|
||||
auth = fmt.Sprintf("%v",tk.Raw)
|
||||
}
|
||||
}
|
||||
}
|
||||
auth := ""
|
||||
if rtenv.Cfg.UseJWT {
|
||||
tk, errtk := rtenv.AuthMiddleware.ParseToken(c)
|
||||
if errtk == nil {
|
||||
auth = fmt.Sprintf("%v",tk.Raw)
|
||||
}
|
||||
}
|
||||
ip, _ := getIP(c.Request)
|
||||
trackaction := &TrackAction{
|
||||
When: trackpost.When,
|
||||
Where: trackpost.Where,
|
||||
@ -116,10 +117,12 @@ func post_tracking_handle(c *gin.Context, rtenv *RouteEnv) {
|
||||
Context: trackpost.Context,
|
||||
Data: trackpost.Data,
|
||||
Auth: auth,
|
||||
Ip: ip,
|
||||
// Info: requestInfo(c,rtenv,"post_tracking",fmt.Sprintf("post %s",trackpost.Data), fmt.Sprintf("post %s",userid)),
|
||||
}
|
||||
data,err := json.Marshal(trackaction)
|
||||
if err != nil {
|
||||
logRoute(c,rtenv,"post_trackng",fmt.Sprintf("post %s: error %v ",trackpost.Data,err), fmt.Sprintf("post %s",userid))
|
||||
logRoute(c,rtenv,"post_tracking",fmt.Sprintf("post %s: error %v ",trackpost.Data,err), fmt.Sprintf("post %s",userid))
|
||||
fmt.Printf("Error Parse tracking %s: %v\n", trackpost.Data, err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save tracking"})
|
||||
return
|
||||
|
39
routes.go
39
routes.go
@ -56,23 +56,23 @@ func getRoutes(router *gin.Engine, cfg *cfg.Config, users *UsersAccounts, mdlsUs
|
||||
// router.POST(cfg.Routes["post_login"].Path, routenv.AuthMiddleware.LoginHandler)
|
||||
authorized = router.Group(cfg.Routes["root"].Path, gin.BasicAuth(webusrs.Accounts))
|
||||
}
|
||||
authorized.GET("/hello", func(c *gin.Context) {
|
||||
if cfg.UseJWT {
|
||||
claims := jwt.ExtractClaims(c)
|
||||
user, _ := c.Get(cfg.IdentityKey)
|
||||
c.JSON(200, gin.H{
|
||||
"userID": claims[cfg.IdentityKey],
|
||||
"userName": user.(*User).UserName,
|
||||
"text": "Hello World.",
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, gin.H{
|
||||
"userID": "",
|
||||
"userName": "",
|
||||
"text": "Hello World.",
|
||||
})
|
||||
}
|
||||
})
|
||||
// authorized.GET("/hello", func(c *gin.Context) {
|
||||
// if cfg.UseJWT {
|
||||
// claims := jwt.ExtractClaims(c)
|
||||
// user, _ := c.Get(cfg.IdentityKey)
|
||||
// c.JSON(200, gin.H{
|
||||
// "userID": claims[cfg.IdentityKey],
|
||||
// "userName": user.(*User).UserName,
|
||||
// "text": "Hello World.",
|
||||
// })
|
||||
// } else {
|
||||
// c.JSON(200, gin.H{
|
||||
// "userID": "",
|
||||
// "userName": "",
|
||||
// "text": "Hello World.",
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// authorized.GET("/page/:id", func(c *gin.Context) {
|
||||
// logRoute := func(info string, infoReq string) {
|
||||
// logRequest(c, cfg, "route", "/", info, infoReq)
|
||||
@ -157,7 +157,10 @@ func getRoutes(router *gin.Engine, cfg *cfg.Config, users *UsersAccounts, mdlsUs
|
||||
authorized.GET(cfg.Routes["tracking"].Path, func(c *gin.Context) {
|
||||
get_tracking_handle(c, routenv )
|
||||
})
|
||||
authorized.POST(cfg.Routes["post_tracking"].Path, func(c *gin.Context) {
|
||||
router.POST(cfg.Routes["post_tracking"].Path, func(c *gin.Context) {
|
||||
post_tracking_handle(c, routenv )
|
||||
})
|
||||
authorized.POST(cfg.Routes["post_tracking_auth"].Path, func(c *gin.Context) {
|
||||
post_tracking_handle(c, routenv )
|
||||
})
|
||||
authorized.GET(cfg.Routes["config"].Path, func(c *gin.Context) {
|
||||
|
Loading…
Reference in New Issue
Block a user