Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sdk-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
sdk-api
Commits
6f665f79
Commit
6f665f79
authored
Jun 30, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
85079a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
50 deletions
+28
-50
api.go
model/api/api.go
+0
-4
user.go
server/user.go
+28
-46
No files found.
model/api/api.go
View file @
6f665f79
...
@@ -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
{
...
...
server/user.go
View file @
6f665f79
...
@@ -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
{
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
In
validParam
))
c
.
JSON
(
200
,
withError
(
constant
.
In
ternalError
))
return
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
)
token
:=
util
.
GenerateJWT
(
uid
,
constant
.
PlatformTelegram
,
dbId
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
token
:=
util
.
GenerateJWT
(
uid
,
req
.
Platform
,
platformId
)
resp
:=
&
apiModel
.
CheckUserResponse
{
IsNewUser
:
!
ok
,
Keystore
:
keystore
,
Token
:
token
,
}
c
.
JSON
(
200
,
withSuccess
(
resp
))
return
resp
:=
&
apiModel
.
CheckUserResponse
{
case
constant
.
PlatformFingerprint
:
IsNewUser
:
!
isExistKeystore
,
userId
:=
req
.
VisitorID
Keystore
:
keystore
,
Token
:
token
,
}
if
!
isExistKeystore
{
ok
,
uid
,
keystore
,
err
:=
srv
.
CheckUser
(
constant
.
PlatformFingerprint
,
userId
)
_
,
err
=
srv
.
SetKeystore
(
uid
,
address
,
req
.
Keystore
)
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
,
}
c
.
JSON
(
200
,
withSuccess
(
resp
))
default
:
c
.
JSON
(
200
,
withError
(
constant
.
UnsupportedPlatform
))
return
}
}
srv
.
AONServerLogin
(
address
,
req
.
UserId
,
req
.
InviterId
)
c
.
JSON
(
200
,
withSuccess
(
resp
))
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment