Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ginkgo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vjrj
ginkgo
Commits
9671c573
Commit
9671c573
authored
1 year ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Correct cplus calls
parent
58e013ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/g1/api.dart
+30
-20
30 additions, 20 deletions
lib/g1/api.dart
with
30 additions
and
20 deletions
lib/g1/api.dart
+
30
−
20
View file @
9671c573
...
@@ -736,30 +736,26 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
...
@@ -736,30 +736,26 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
'version'
:
2
,
'version'
:
2
,
'issuer'
:
pubKey
,
'issuer'
:
pubKey
,
'title'
:
name
+
userNameSuffix
,
'title'
:
name
+
userNameSuffix
,
'geoPoint'
:
null
,
'time'
:
DateTime
.
now
()
.
millisecondsSinceEpoch
~/
'time'
:
DateTime
.
now
()
.
millisecondsSinceEpoch
~/
1000
,
// current time in seconds
1000
,
// current time in seconds
'tags'
:
<
String
>[],
'tags'
:
<
String
>[],
};
};
final
String
userProfileJson
=
jsonEncode
(
userProfile
);
signAndHash
(
userProfile
,
wallet
);
final
String
signature
=
wallet
.
sign
(
userProfileJson
);
userProfile
[
'hash'
]
=
calculateHash
(
userProfileJson
);
userProfile
[
'signature'
]
=
signature
;
// Convert the user profile data into a JSON string again, now including hash and signature
// Convert the user profile data into a JSON string again, now including hash and signature
final
String
userProfileJsonWithHashAndSignature
=
jsonEncode
(
userProfile
);
final
String
userProfileJsonWithHashAndSignature
=
jsonEncode
(
userProfile
);
// Prepare the request headers
final
Map
<
String
,
String
>
headers
=
<
String
,
String
>{
'Content-Type'
:
'application/json'
,
};
if
(
userName
!=
null
)
{
if
(
userName
!=
null
)
{
//
User exists, update the user profile
logger
(
'
User exists, update the user profile
'
);
final
http
.
Response
updateResponse
=
await
_requestWithRetry
(
final
http
.
Response
updateResponse
=
await
_requestWithRetry
(
NodeType
.
cesiumPlus
,
'/user/profile/_update'
,
false
,
true
,
NodeType
.
cesiumPlus
,
'/user/profile/
$pubKey
/_update?pubkey=
$pubKey
'
,
false
,
true
,
httpType:
HttpType
.
post
,
httpType:
HttpType
.
post
,
headers:
h
eaders
,
headers:
_defCPlusH
eaders
()
,
body:
userProfileJsonWithHashAndSignature
);
body:
userProfileJsonWithHashAndSignature
);
if
(
updateResponse
.
statusCode
==
200
)
{
if
(
updateResponse
.
statusCode
==
200
)
{
logger
(
'User profile updated successfully.'
);
logger
(
'User profile updated successfully.'
);
...
@@ -769,11 +765,11 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
...
@@ -769,11 +765,11 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
logger
(
'Response body:
${updateResponse.body}
'
);
logger
(
'Response body:
${updateResponse.body}
'
);
}
}
}
else
if
(
userName
==
null
)
{
}
else
if
(
userName
==
null
)
{
//
User does not exist, create a new user profile
logger
(
'
User does not exist, create a new user profile
'
);
final
http
.
Response
createResponse
=
await
_requestWithRetry
(
final
http
.
Response
createResponse
=
await
_requestWithRetry
(
NodeType
.
cesiumPlus
,
'/user/profile'
,
false
,
false
,
NodeType
.
cesiumPlus
,
'/user/profile'
,
false
,
false
,
httpType:
HttpType
.
post
,
httpType:
HttpType
.
post
,
headers:
h
eaders
,
headers:
_defCPlusH
eaders
()
,
body:
userProfileJsonWithHashAndSignature
);
body:
userProfileJsonWithHashAndSignature
);
if
(
createResponse
.
statusCode
==
200
)
{
if
(
createResponse
.
statusCode
==
200
)
{
...
@@ -785,6 +781,21 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
...
@@ -785,6 +781,21 @@ Future<void> createOrUpdateCesiumPlusUser(String name) async {
}
}
}
}
Map
<
String
,
String
>
_defCPlusHeaders
()
{
return
<
String
,
String
>{
'Accept'
:
'application/json, text/plain, */*'
,
'Content-Type'
:
'application/json;charset=UTF-8'
,
};
}
void
signAndHash
(
Map
<
String
,
dynamic
>
userProfile
,
CesiumWallet
wallet
)
{
final
String
userProfileJson
=
jsonEncode
(
userProfile
);
final
String
hash
=
calculateHash
(
userProfileJson
);
final
String
signature
=
wallet
.
sign
(
hash
);
userProfile
[
'hash'
]
=
hash
;
userProfile
[
'signature'
]
=
signature
;
}
Future
<
String
?
>
getCesiumPlusUser
(
String
pubKey
)
async
{
Future
<
String
?
>
getCesiumPlusUser
(
String
pubKey
)
async
{
final
Contact
c
=
await
getProfile
(
pubKey
,
true
);
final
Contact
c
=
await
getProfile
(
pubKey
,
true
);
return
c
.
name
;
return
c
.
name
;
...
@@ -803,14 +814,13 @@ Future<bool> deleteCesiumPlusUser() async {
...
@@ -803,14 +814,13 @@ Future<bool> deleteCesiumPlusUser() async {
1000
,
// current time in seconds
1000
,
// current time in seconds
};
};
final
String
userProfileJson
=
jsonEncode
(
userProfile
);
signAndHash
(
userProfile
,
wallet
);
final
String
signature
=
wallet
.
sign
(
userProfileJson
);
userProfile
[
'hash'
]
=
calculateHash
(
userProfileJson
);
userProfile
[
'signature'
]
=
signature
;
final
http
.
Response
delResponse
=
await
_requestWithRetry
(
final
http
.
Response
delResponse
=
await
_requestWithRetry
(
NodeType
.
cesiumPlus
,
'/user/profile/_delete'
,
false
,
false
,
NodeType
.
cesiumPlus
,
'/history/delete'
,
false
,
false
,
httpType:
HttpType
.
post
);
httpType:
HttpType
.
post
,
headers:
_defCPlusHeaders
(),
body:
jsonEncode
(
userProfile
));
return
delResponse
.
statusCode
==
200
;
return
delResponse
.
statusCode
==
200
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment