changed way to get encrypted data to make cross server requests possible
This commit is contained in:
1 parent
d1c01b6bf9
commit
18938a77d0
4 files changed
+23
-8
No files matched your search
+1
-1
@@ -9,7 +9,7 @@ pages:
|
||||
script:
|
||||
- export SALT="salt_and_pepper"
|
||||
- export KEY="qwerty"
|
||||
- export PLAYER_LIST_LOCATION="//ballephenix.gitlab.io/private/players.json.spritz"
|
||||
- export PLAYER_LIST_LOCATION="//ballephenix.gitlab.io/private/players.spritz.js"
|
||||
- npm install
|
||||
- node_modules/.bin/gulp prod
|
||||
- node_modules/.bin/r.js -o build.js
|
||||
|
||||
+8
-5
@@ -42,7 +42,7 @@ gulp.task('compile-results', function(){
|
||||
|
||||
var encryptFile = function(message){
|
||||
var keyLengthInBytes = 128;
|
||||
var salt = process.env.SALT || '';
|
||||
var salt = process.env.SALT || 'salt';
|
||||
var stringKey = salt + (process.env.KEY || 'qwerty');
|
||||
var key = spritz.hash(stringKey, keyLengthInBytes);
|
||||
var byteArrMessage = spritz.stringToUtf8ByteArray(message);
|
||||
@@ -50,16 +50,20 @@ var encryptFile = function(message){
|
||||
return JSON.stringify(cypher);
|
||||
};
|
||||
|
||||
var wrapEncryptedData = function(encryptedData){
|
||||
return 'window.encryptedPlayerList = ' + encryptedData + ';';
|
||||
};
|
||||
|
||||
gulp.task('encrypt-results', ['compile-results'], function(){
|
||||
return gulp.src('api/*.clear.json')
|
||||
.pipe(modify({
|
||||
fileModifier: function(file, content) {
|
||||
return encryptFile(content);
|
||||
return wrapEncryptedData(encryptFile(content));
|
||||
}
|
||||
}))
|
||||
.pipe(rename(function(path){
|
||||
path.basename = path.basename.replace(/\.clear$/i, '');
|
||||
path.extname = '.json.spritz';
|
||||
path.extname = '.spritz.js';
|
||||
return path;
|
||||
}))
|
||||
.pipe(gulp.dest('./api'));
|
||||
@@ -75,7 +79,7 @@ gulp.task('template-prod', function () {
|
||||
gulp.task('template-dev', function () {
|
||||
return gulp.src('index.tmpl.html')
|
||||
.pipe(rename("index.html"))
|
||||
.pipe(template({production: false, salt: '', playerListLocation: 'api/players.json.spritz'}))
|
||||
.pipe(template({production: false, salt: 'salt', playerListLocation: 'api/players.spritz.js'}))
|
||||
.pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
@@ -122,7 +126,6 @@ gulp.task('webserver', function(){
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){
|
||||
gulp.watch('./scss/*.scss', ['sass']);
|
||||
gulp.watch('*.tmpl.html', ['template-dev']);
|
||||
|
||||
+1
-1
@@ -12,8 +12,8 @@
|
||||
<body>
|
||||
<script>
|
||||
window.salt = "<%= salt %>";
|
||||
window.playerListLocation = "<%= playerListLocation %>"
|
||||
</script>
|
||||
<script src="<%= playerListLocation %>"></script>
|
||||
<%if(production){ %>
|
||||
<script src="main-built.js"></script>
|
||||
<% }else{ %>
|
||||
|
||||
@@ -90,12 +90,24 @@ define(['m', '_', 'spritz', 'teams'], function (m, _ , spritz, teams) {
|
||||
return JSON.parse(spritz.utf8ByteArrayToString(decryptedMessage));
|
||||
};
|
||||
|
||||
playersTable.getEncryptedPlayerList = function(){
|
||||
var deferred = m.deferred();
|
||||
var interval = setInterval(function() {
|
||||
if(!_.isEmpty(window.encryptedPlayerList)){
|
||||
clearInterval(interval);
|
||||
deferred.resolve(window.encryptedPlayerList);
|
||||
m.redraw();
|
||||
}
|
||||
}, 333);
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
playersTable.controller = function(model){
|
||||
var players = m.prop([]);
|
||||
var ctrl = {};
|
||||
ctrl.model = model;
|
||||
|
||||
ctrl.players = m.request({method: "GET", url: window.playerListLocation})
|
||||
ctrl.players = playersTable.getEncryptedPlayerList()
|
||||
.then(playersTable.decryptPlayerList)
|
||||
.then(players);
|
||||
ctrl.sortPlayers = function(){
|
||||
|
||||
Reference in new issue
Block a user