Login count : GWM
This commit is contained in:
parent
8339ef1ca2
commit
65850e763d
43
main.go
43
main.go
@ -282,9 +282,6 @@ func fetchfilterJSON(kpi string) ([]FilterGroup, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug Log Exclusion Filters
|
|
||||||
log.Printf("Raw Exclusion Filters JSON: %s", dataSetFilter.ExclusionFiltersJSON)
|
|
||||||
|
|
||||||
// Parse exclusion filters JSON if it's not empty
|
// Parse exclusion filters JSON if it's not empty
|
||||||
var exclusionFilters []utils.FilterGroup
|
var exclusionFilters []utils.FilterGroup
|
||||||
if dataSetFilter.ExclusionFiltersJSON != "" {
|
if dataSetFilter.ExclusionFiltersJSON != "" {
|
||||||
@ -448,6 +445,46 @@ func main() {
|
|||||||
|
|
||||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
|
|
||||||
|
e.Router.GET("/api/login_success", func(c echo.Context) error {
|
||||||
|
|
||||||
|
userID := c.QueryParam("id")
|
||||||
|
if userID == "" {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "User ID is required"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find user by ID
|
||||||
|
record, err := app.Dao().FindRecordById("users", userID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("User not found: %v", err)
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": "User not found"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current login count and convert it properly
|
||||||
|
var loginCount int
|
||||||
|
if count, ok := record.Get("login_count").(float64); ok {
|
||||||
|
loginCount = int(count) // Convert float64 to int
|
||||||
|
} else {
|
||||||
|
loginCount = 0 // Default if not set
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment login count
|
||||||
|
loginCount++
|
||||||
|
record.Set("login_count", loginCount)
|
||||||
|
|
||||||
|
// Save the updated record
|
||||||
|
if err := app.Dao().SaveRecord(record); err != nil {
|
||||||
|
log.Printf("Failed to update login count: %v", err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to update login count"})
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("User %s login count updated to %d", userID, loginCount)
|
||||||
|
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
|
"message": "Success",
|
||||||
|
"login_count": loginCount,
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
e.Router.GET("/api/custom/apicalltest", func(c echo.Context) error {
|
e.Router.GET("/api/custom/apicalltest", func(c echo.Context) error {
|
||||||
// Get the database instance
|
// Get the database instance
|
||||||
db := app.Dao().DB()
|
db := app.Dao().DB()
|
||||||
|
|||||||
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user