Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/controller/http/v1/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ func (r *syncRoutes) updateProgress(c *gin.Context) {
var doc entity.Progress
if err := c.ShouldBindJSON(&doc); err != nil {
r.l.Error(err)
c.JSON(http.StatusBadRequest, gin.H{"message": "Bad request", "code": 4000})
c.AsciiJSON(http.StatusBadRequest, gin.H{"message": "Bad request", "code": 4000})
return
}

doc.AuthDeviceName = c.GetString("device_name")
savedDoc, err := r.progress.Sync(c, doc)
if err != nil {
r.l.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal server error", "code": 5000})
c.AsciiJSON(http.StatusInternalServerError, gin.H{"message": "Internal server error", "code": 5000})
return
}

c.JSON(http.StatusOK, gin.H{"timestamp": savedDoc.Timestamp, "document": savedDoc})
c.AsciiJSON(http.StatusOK, gin.H{"timestamp": savedDoc.Timestamp, "document": savedDoc})
}

func (r *syncRoutes) fetchProgress(c *gin.Context) {
doc, err := r.progress.Fetch(c, c.Param("document"))
if err != nil {
r.l.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal server error", "code": 5000})
c.AsciiJSON(http.StatusInternalServerError, gin.H{"message": "Internal server error", "code": 5000})
return
}

c.JSON(http.StatusOK, doc)
c.AsciiJSON(http.StatusOK, doc)
}
6 changes: 3 additions & 3 deletions internal/controller/http/v1/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ func newUserRoutes(handler *gin.RouterGroup, a auth.AuthInterface, l logger.Inte

func (r *userRoutes) authenicate(c *gin.Context) {
// authenication done by authDeviceMiddleware
c.JSON(http.StatusOK, gin.H{"message": "OK", "code": 200})
c.AsciiJSON(http.StatusOK, gin.H{"message": "OK", "code": 200})
}

func authDeviceMiddleware(auth auth.AuthInterface, l logger.Interface) gin.HandlerFunc {
return func(c *gin.Context) {
username := c.GetHeader("x-auth-user")
hashed_password := c.GetHeader("x-auth-key")
if username == "" || hashed_password == "" {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Unauthorized", "code": 2001})
c.AsciiJSON(http.StatusUnauthorized, gin.H{"message": "Unauthorized", "code": 2001})
c.Abort()
return
}
if !auth.CheckDevicePassword(c.Request.Context(), username, hashed_password, false) {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Unauthorized", "code": 2001})
c.AsciiJSON(http.StatusUnauthorized, gin.H{"message": "Unauthorized", "code": 2001})
c.Abort()
return
}
Expand Down
Loading