(ctx *gin.Context)
| 8 | ) |
| 9 | |
| 10 | func (c *Core) handleUpdatePushToken(ctx *gin.Context) { |
| 11 | var params struct { |
| 12 | Nonce uint64 `json:"nonce"` |
| 13 | DeviceID string `json:"device"` |
| 14 | UserID string `json:"user"` |
| 15 | Token string `json:"token"` |
| 16 | Sandbox bool `json:"sandbox,omitempty"` |
| 17 | } |
| 18 | if err := c.bindBodyJSON(ctx, ¶ms); err != nil { |
| 19 | ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid params"}) |
| 20 | return |
| 21 | } |
| 22 | u, err := c.logic.GetUser(params.UserID) |
| 23 | if err != nil { |
| 24 | ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid user id"}) |
| 25 | return |
| 26 | } |
| 27 | if u.IsServerless() { |
| 28 | ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid user mode"}) |
| 29 | return |
| 30 | } |
| 31 | if !verifyUser(ctx, u.GetPublicKeyString()) { |
| 32 | ctx.JSON(http.StatusUnauthorized, gin.H{"res": http.StatusUnauthorized, "msg": "invalid user sign"}) |
| 33 | return |
| 34 | } |
| 35 | dev, err := c.logic.GetDeviceKey(params.DeviceID) |
| 36 | if err != nil { |
| 37 | ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid device id"}) |
| 38 | return |
| 39 | } |
| 40 | if !verifyDevice(ctx, crypto.Base64Encode.EncodeToString(dev)) { |
| 41 | ctx.JSON(http.StatusUnauthorized, gin.H{"res": http.StatusUnauthorized, "msg": "invalid device sign"}) |
| 42 | return |
| 43 | } |
| 44 | if err := c.logic.UpdatePushToken(params.UserID, params.DeviceID, params.Token, params.Sandbox); err != nil { |
| 45 | ctx.JSON(http.StatusConflict, gin.H{"res": http.StatusConflict, "msg": "update push token failed"}) |
| 46 | return |
| 47 | } |
| 48 | ctx.JSON(http.StatusOK, gin.H{ |
| 49 | "uuid": params.DeviceID, |
| 50 | "uid": params.UserID, |
| 51 | }) |
| 52 | } |
nothing calls this directly
no test coverage detected