Commit 6f665f79 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update

parent 85079a64
......@@ -4,10 +4,6 @@ type CheckUserRequest struct {
InitData string `json:"initData"`
Platform string `json:"platform"`
VisitorID string `json:"visitorId"`
Keystore string `json:"keystore"`
Signature string `json:"signature"`
UserId string `json:"userId"`
InviterId string `json:"inviter_id"`
}
type CheckUserResponse struct {
......
......@@ -20,7 +20,6 @@ func checkUser(c *gin.Context) {
c.JSON(200, withError(constant.InvalidParam))
return
}
var platformId string
switch req.Platform {
case constant.PlatformTelegram:
var ok bool
......@@ -36,62 +35,46 @@ func checkUser(c *gin.Context) {
c.JSON(200, withError("invalid initData"))
return
}
platformId = fmt.Sprintf("%s:%s", botId, userId)
case constant.PlatformFingerprint:
if len(req.VisitorID) <= 10 {
c.JSON(200, withError(constant.InvalidParam))
return
}
platformId = req.VisitorID
default:
c.JSON(200, withError(constant.UnsupportedPlatform))
return
}
// 检查签名是否为keystore中的地址
address := gjson.Get(req.Keystore, "address").String()
binSignature, err := hexutil.Decode(req.Signature)
if err != nil || len(binSignature) < 65 {
c.JSON(200, withError("invalid signature"))
return
}
binSignature[64] -= 27
ecdsaPub, err := crypto.SigToPub(accounts.TextHash([]byte(req.Keystore)), binSignature)
if err != nil {
c.JSON(200, withError("invalid signature"))
return
}
addr := crypto.PubkeyToAddress(*ecdsaPub)
if strings.ToLower(addr.Hex()[2:]) != address {
c.JSON(200, withError("invalid signature"))
return
}
isExistKeystore, uid, keystore, err := srv.CheckUser(req.Platform, platformId)
dbId := fmt.Sprintf("%s:%s", botId, userId)
ok, uid, keystore, err := srv.CheckUser(constant.PlatformTelegram, dbId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
token := util.GenerateJWT(uid, req.Platform, platformId)
token := util.GenerateJWT(uid, constant.PlatformTelegram, dbId)
resp := &apiModel.CheckUserResponse{
IsNewUser: !isExistKeystore,
IsNewUser: !ok,
Keystore: keystore,
Token: token,
}
c.JSON(200, withSuccess(resp))
return
if !isExistKeystore {
_, err = srv.SetKeystore(uid, address, req.Keystore)
case constant.PlatformFingerprint:
userId := req.VisitorID
ok, uid, keystore, err := srv.CheckUser(constant.PlatformFingerprint, userId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
resp.Keystore = req.Keystore
token := util.GenerateJWT(uid, constant.PlatformFingerprint, userId)
resp := &apiModel.CheckUserResponse{
IsNewUser: !ok,
Keystore: keystore,
Token: token,
}
srv.AONServerLogin(address, req.UserId, req.InviterId)
c.JSON(200, withSuccess(resp))
default:
c.JSON(200, withError(constant.UnsupportedPlatform))
return
}
}
func createUser(c *gin.Context) {
......@@ -103,7 +86,6 @@ func createUser(c *gin.Context) {
uid := c.GetString("jwt-uid")
// 检查签名是否为keystore中的地址
address := gjson.Get(req.Keystore, "address").String()
binSignature, err := hexutil.Decode(req.Signature)
if err != nil || len(binSignature) < 65 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment