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

update

parent 85079a64
...@@ -4,10 +4,6 @@ type CheckUserRequest struct { ...@@ -4,10 +4,6 @@ type CheckUserRequest struct {
InitData string `json:"initData"` InitData string `json:"initData"`
Platform string `json:"platform"` Platform string `json:"platform"`
VisitorID string `json:"visitorId"` VisitorID string `json:"visitorId"`
Keystore string `json:"keystore"`
Signature string `json:"signature"`
UserId string `json:"userId"`
InviterId string `json:"inviter_id"`
} }
type CheckUserResponse struct { type CheckUserResponse struct {
......
...@@ -20,7 +20,6 @@ func checkUser(c *gin.Context) { ...@@ -20,7 +20,6 @@ func checkUser(c *gin.Context) {
c.JSON(200, withError(constant.InvalidParam)) c.JSON(200, withError(constant.InvalidParam))
return return
} }
var platformId string
switch req.Platform { switch req.Platform {
case constant.PlatformTelegram: case constant.PlatformTelegram:
var ok bool var ok bool
...@@ -36,62 +35,46 @@ func checkUser(c *gin.Context) { ...@@ -36,62 +35,46 @@ func checkUser(c *gin.Context) {
c.JSON(200, withError("invalid initData")) c.JSON(200, withError("invalid initData"))
return return
} }
platformId = fmt.Sprintf("%s:%s", botId, userId) dbId := fmt.Sprintf("%s:%s", botId, userId)
case constant.PlatformFingerprint: ok, uid, keystore, err := srv.CheckUser(constant.PlatformTelegram, dbId)
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)
if err != nil { if err != nil {
c.JSON(200, withError(constant.InternalError)) c.JSON(200, withError(constant.InternalError))
return return
} }
token := util.GenerateJWT(uid, req.Platform, platformId) token := util.GenerateJWT(uid, constant.PlatformTelegram, dbId)
resp := &apiModel.CheckUserResponse{ resp := &apiModel.CheckUserResponse{
IsNewUser: !isExistKeystore, IsNewUser: !ok,
Keystore: keystore, Keystore: keystore,
Token: token, Token: token,
} }
c.JSON(200, withSuccess(resp))
return
if !isExistKeystore { case constant.PlatformFingerprint:
_, err = srv.SetKeystore(uid, address, req.Keystore) userId := req.VisitorID
ok, uid, keystore, err := srv.CheckUser(constant.PlatformFingerprint, userId)
if err != nil { if err != nil {
c.JSON(200, withError(constant.InternalError)) c.JSON(200, withError(constant.InternalError))
return 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)) c.JSON(200, withSuccess(resp))
default:
c.JSON(200, withError(constant.UnsupportedPlatform))
return return
}
} }
func createUser(c *gin.Context) { func createUser(c *gin.Context) {
...@@ -103,7 +86,6 @@ func createUser(c *gin.Context) { ...@@ -103,7 +86,6 @@ func createUser(c *gin.Context) {
uid := c.GetString("jwt-uid") uid := c.GetString("jwt-uid")
// 检查签名是否为keystore中的地址
address := gjson.Get(req.Keystore, "address").String() address := gjson.Get(req.Keystore, "address").String()
binSignature, err := hexutil.Decode(req.Signature) binSignature, err := hexutil.Decode(req.Signature)
if err != nil || len(binSignature) < 65 { 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