MCPcopy Create free account
hub / github.com/chanify/chanify / handleUpdatePushToken

Method handleUpdatePushToken

core/pushdev.go:10–52  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

8)
9
10func (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, &params); 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}

Callers

nothing calls this directly

Calls 9

bindBodyJSONMethod · 0.95
verifyUserFunction · 0.85
verifyDeviceFunction · 0.85
IsServerlessMethod · 0.80
GetPublicKeyStringMethod · 0.80
JSONMethod · 0.65
GetUserMethod · 0.65
GetDeviceKeyMethod · 0.65
UpdatePushTokenMethod · 0.65

Tested by

no test coverage detected