Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Cesium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
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
clients
Cesium-grp
Cesium
Commits
02ebcde2
Commit
02ebcde2
authored
7 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
clean code
parent
178e4e3b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
www/plugins/es/js/services/http-services.js
+48
-103
48 additions, 103 deletions
www/plugins/es/js/services/http-services.js
with
48 additions
and
103 deletions
www/plugins/es/js/services/http-services.js
+
48
−
103
View file @
02ebcde2
...
...
@@ -214,21 +214,16 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
function
postRecord
(
path
)
{
var
postRequest
=
that
.
post
(
path
);
return
function
(
record
,
params
)
{
if
(
!
csWallet
.
isLogin
())
{
var
deferred
=
$q
.
defer
();
deferred
.
reject
(
'
Wallet must be login before sending record to ES node
'
);
return
deferred
.
promise
;
}
return
csWallet
.
auth
()
.
then
(
function
(
walletData
)
{
if
(
!
record
.
time
)
{
record
.
time
=
that
.
date
.
now
();
}
var
keypair
=
$rootScope
.
walletData
.
keypair
;
var
obj
=
{};
angular
.
copy
(
record
,
obj
);
delete
obj
.
signature
;
delete
obj
.
hash
;
obj
.
issuer
=
$rootScope
.
walletData
.
pubkey
;
obj
.
issuer
=
walletData
.
pubkey
;
// Fill tags
fillRecordTags
(
obj
);
...
...
@@ -237,7 +232,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
return
CryptoUtils
.
util
.
hash
(
str
)
.
then
(
function
(
hash
)
{
return
CryptoUtils
.
sign
(
str
,
keypair
)
return
CryptoUtils
.
sign
(
str
,
walletData
.
keypair
)
.
then
(
function
(
signature
)
{
obj
.
hash
=
hash
;
obj
.
signature
=
signature
;
...
...
@@ -247,29 +242,26 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
});
});
});
});
};
}
function
removeRecord
(
index
,
type
)
{
return
function
(
id
)
{
if
(
!
csWallet
.
isLogin
())
{
var
deferred
=
$q
.
defer
();
deferred
.
reject
(
'
Wallet must be login before sending record to ES node
'
);
return
deferred
.
promise
;
}
return
csWallet
.
auth
()
.
then
(
function
(
walletData
)
{
var
keypair
=
$rootScope
.
walletData
.
keypair
;
var
obj
=
{
index
:
index
,
type
:
type
,
id
:
id
,
issuer
:
$rootScope
.
walletData
.
pubkey
,
issuer
:
walletData
.
pubkey
,
time
:
that
.
date
.
now
()
};
var
str
=
JSON
.
stringify
(
obj
);
return
CryptoUtils
.
util
.
hash
(
str
)
.
then
(
function
(
hash
)
{
return
CryptoUtils
.
sign
(
str
,
keypair
)
return
CryptoUtils
.
sign
(
str
,
walletData
.
keypair
)
.
then
(
function
(
signature
)
{
obj
.
hash
=
hash
;
obj
.
signature
=
signature
;
...
...
@@ -279,6 +271,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
});
});
});
});
};
}
...
...
@@ -350,50 +343,6 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
return
image
;
};
function
login
(
host
,
node
,
keypair
)
{
return
$q
(
function
(
resolve
,
reject
)
{
var
errorFct
=
function
(
err
)
{
reject
(
err
);
};
var
getChallenge
=
getResource
(
host
,
node
,
'
/auth
'
);
var
postAuth
=
postResource
(
host
,
node
,
'
/auth
'
);
getChallenge
()
// get the challenge phrase to sign
.
then
(
function
(
challenge
)
{
CryptoUtils
.
sign
(
challenge
,
keypair
)
// sign the challenge
.
then
(
function
(
signature
)
{
var
pubkey
=
CryptoUtils
.
util
.
encode_base58
(
keypair
.
signPk
);
postAuth
({
pubkey
:
pubkey
,
challenge
:
challenge
,
signature
:
signature
})
// get token
.
then
(
function
(
token
)
{
/*var authdata = CryptoUtils.util.encode_base64(pubkey + ':' + token);
$rootScope.globals = {
currentUser: {
username: pubkey,
authdata: token
}
};
$http.defaults.headers.common['Authorization'] = 'Basic ' + token; // jshint ignore:line
$cookies.put('globals', $rootScope.globals);
resolve(token);*/
})
.
catch
(
errorFct
);
})
.
catch
(
errorFct
);
})
.
catch
(
errorFct
);
});
}
function
logout
(
host
,
node
)
{
/*$rootScope.globals = {};
$cookie.remove('globals');
$http.defaults.headers.common.Authorization = 'Basic ';*/
}
function
parseEndPoint
(
endpoint
)
{
var
matches
=
regexp
.
ES_USER_API_ENDPOINT
.
exec
(
endpoint
);
if
(
!
matches
)
return
;
...
...
@@ -432,10 +381,6 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
fromAttachment
:
imageFromAttachment
,
toAttachment
:
imageToAttachment
},
auth
:
{
login
:
login
,
logout
:
logout
},
hit
:
{
empty
:
emptyHit
},
...
...
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