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:
|
script:
|
||||||
- export SALT="salt_and_pepper"
|
- export SALT="salt_and_pepper"
|
||||||
- export KEY="qwerty"
|
- 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
|
- npm install
|
||||||
- node_modules/.bin/gulp prod
|
- node_modules/.bin/gulp prod
|
||||||
- node_modules/.bin/r.js -o build.js
|
- node_modules/.bin/r.js -o build.js
|
||||||
|
|||||||
+8
-5
@@ -42,7 +42,7 @@ gulp.task('compile-results', function(){
|
|||||||
|
|
||||||
var encryptFile = function(message){
|
var encryptFile = function(message){
|
||||||
var keyLengthInBytes = 128;
|
var keyLengthInBytes = 128;
|
||||||
var salt = process.env.SALT || '';
|
var salt = process.env.SALT || 'salt';
|
||||||
var stringKey = salt + (process.env.KEY || 'qwerty');
|
var stringKey = salt + (process.env.KEY || 'qwerty');
|
||||||
var key = spritz.hash(stringKey, keyLengthInBytes);
|
var key = spritz.hash(stringKey, keyLengthInBytes);
|
||||||
var byteArrMessage = spritz.stringToUtf8ByteArray(message);
|
var byteArrMessage = spritz.stringToUtf8ByteArray(message);
|
||||||
@@ -50,16 +50,20 @@ var encryptFile = function(message){
|
|||||||
return JSON.stringify(cypher);
|
return JSON.stringify(cypher);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var wrapEncryptedData = function(encryptedData){
|
||||||
|
return 'window.encryptedPlayerList = ' + encryptedData + ';';
|
||||||
|
};
|
||||||
|
|
||||||
gulp.task('encrypt-results', ['compile-results'], function(){
|
gulp.task('encrypt-results', ['compile-results'], function(){
|
||||||
return gulp.src('api/*.clear.json')
|
return gulp.src('api/*.clear.json')
|
||||||
.pipe(modify({
|
.pipe(modify({
|
||||||
fileModifier: function(file, content) {
|
fileModifier: function(file, content) {
|
||||||
return encryptFile(content);
|
return wrapEncryptedData(encryptFile(content));
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.pipe(rename(function(path){
|
.pipe(rename(function(path){
|
||||||
path.basename = path.basename.replace(/\.clear$/i, '');
|
path.basename = path.basename.replace(/\.clear$/i, '');
|
||||||
path.extname = '.json.spritz';
|
path.extname = '.spritz.js';
|
||||||
return path;
|
return path;
|
||||||
}))
|
}))
|
||||||
.pipe(gulp.dest('./api'));
|
.pipe(gulp.dest('./api'));
|
||||||
@@ -75,7 +79,7 @@ gulp.task('template-prod', function () {
|
|||||||
gulp.task('template-dev', function () {
|
gulp.task('template-dev', function () {
|
||||||
return gulp.src('index.tmpl.html')
|
return gulp.src('index.tmpl.html')
|
||||||
.pipe(rename("index.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('.'));
|
.pipe(gulp.dest('.'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,7 +126,6 @@ gulp.task('webserver', function(){
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){
|
gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){
|
||||||
gulp.watch('./scss/*.scss', ['sass']);
|
gulp.watch('./scss/*.scss', ['sass']);
|
||||||
gulp.watch('*.tmpl.html', ['template-dev']);
|
gulp.watch('*.tmpl.html', ['template-dev']);
|
||||||
|
|||||||
+1
-1
@@ -12,8 +12,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
window.salt = "<%= salt %>";
|
window.salt = "<%= salt %>";
|
||||||
window.playerListLocation = "<%= playerListLocation %>"
|
|
||||||
</script>
|
</script>
|
||||||
|
<script src="<%= playerListLocation %>"></script>
|
||||||
<%if(production){ %>
|
<%if(production){ %>
|
||||||
<script src="main-built.js"></script>
|
<script src="main-built.js"></script>
|
||||||
<% }else{ %>
|
<% }else{ %>
|
||||||
|
|||||||
@@ -90,12 +90,24 @@ define(['m', '_', 'spritz', 'teams'], function (m, _ , spritz, teams) {
|
|||||||
return JSON.parse(spritz.utf8ByteArrayToString(decryptedMessage));
|
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){
|
playersTable.controller = function(model){
|
||||||
var players = m.prop([]);
|
var players = m.prop([]);
|
||||||
var ctrl = {};
|
var ctrl = {};
|
||||||
ctrl.model = model;
|
ctrl.model = model;
|
||||||
|
|
||||||
ctrl.players = m.request({method: "GET", url: window.playerListLocation})
|
ctrl.players = playersTable.getEncryptedPlayerList()
|
||||||
.then(playersTable.decryptPlayerList)
|
.then(playersTable.decryptPlayerList)
|
||||||
.then(players);
|
.then(players);
|
||||||
ctrl.sortPlayers = function(){
|
ctrl.sortPlayers = function(){
|
||||||
|
|||||||
Reference in new issue
Block a user