added encryption to player list
This commit is contained in:
1 parent
9f113a8588
commit
2a689dd20b
9 files changed
+53
-30
No files matched your search
+2
-1
@@ -22,6 +22,7 @@
|
||||
"mithril": "~0.2.1",
|
||||
"lodash": "~4.2.1",
|
||||
"almond": "~0.3.1",
|
||||
"requirejs": "~2.1.22"
|
||||
"requirejs": "~2.1.22",
|
||||
"spritzjs": "https://gitlab.com/didiercrunch/spritzjs.git"
|
||||
}
|
||||
}
|
||||
+30
-5
@@ -8,9 +8,10 @@ var rename = require("gulp-rename");
|
||||
var yaml = require('gulp-yaml');
|
||||
var template = require('gulp-template');
|
||||
var wrapper = require('gulp-wrapper');
|
||||
var rename = require("gulp-rename");
|
||||
var webserver = require('gulp-webserver');
|
||||
var marked = require('marked');
|
||||
var spritz = require('spritzjs');
|
||||
var modify = require('gulp-modify');
|
||||
var _ = require('lodash');
|
||||
|
||||
gulp.task('help', help);
|
||||
@@ -39,17 +40,41 @@ gulp.task('compile-results', function(){
|
||||
.pipe(gulp.dest('./api'));
|
||||
});
|
||||
|
||||
var encryptFile = function(message){
|
||||
var keyLengthInBytes = 128;
|
||||
var stringKey = process.env.KEY || 'qwerty';
|
||||
var key = spritz.hash(stringKey, keyLengthInBytes);
|
||||
var byteArrMessage = spritz.stringToUtf8ByteArray(message);
|
||||
var cypher = spritz.encrypt(key, byteArrMessage);
|
||||
return JSON.stringify(cypher);
|
||||
};
|
||||
|
||||
gulp.task('encrypt-results', ['compile-results'], function(){
|
||||
return gulp.src('api/*.clear.json')
|
||||
.pipe(modify({
|
||||
fileModifier: function(file, content) {
|
||||
return encryptFile(content);
|
||||
}
|
||||
}))
|
||||
.pipe(rename(function(path){
|
||||
path.basename = path.basename.replace(/\.clear$/i, '');
|
||||
path.extname = '.json.spritz';
|
||||
return path;
|
||||
}))
|
||||
.pipe(gulp.dest('./api'));
|
||||
});
|
||||
|
||||
gulp.task('template-prod', function () {
|
||||
return gulp.src('index.tmpl.html')
|
||||
.pipe(rename("index.html"))
|
||||
.pipe(template({production: true}))
|
||||
.pipe(template({production: true, salt: process.env.SALT, playerListLocation: process.env.PLAYER_LIST_LOCATION}))
|
||||
.pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
gulp.task('template-dev', function () {
|
||||
return gulp.src('index.tmpl.html')
|
||||
.pipe(rename("index.html"))
|
||||
.pipe(template({production: false}))
|
||||
.pipe(template({production: false, salt: '', playerListLocation: 'api/players.json.spritz'}))
|
||||
.pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
@@ -82,7 +107,7 @@ gulp.task('compile-articles', function(){
|
||||
|
||||
});
|
||||
|
||||
gulp.task('default', ['bower', 'sass', 'compile-results', 'compile-articles']);
|
||||
gulp.task('default', ['bower', 'sass', 'encrypt-results', 'compile-results', 'compile-articles']);
|
||||
|
||||
gulp.task('prod', ['default', 'template-prod']);
|
||||
|
||||
@@ -101,5 +126,5 @@ gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){
|
||||
gulp.watch('./scss/*.scss', ['sass']);
|
||||
gulp.watch('*.tmpl.html', ['template-dev']);
|
||||
gulp.watch('./data/articles/**/*', ['compile-articles']);
|
||||
return gulp.watch('./data/*.yaml', ['compile-results']);
|
||||
return gulp.watch('./data/*.yaml', ['encrypt-results', 'compile-results']);
|
||||
});
|
||||
@@ -10,6 +10,10 @@
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.salt = "<%= salt %>";
|
||||
window.playerListLocation = "<%= playerListLocation %>"
|
||||
</script>
|
||||
<%if(production){ %>
|
||||
<script src="main-built.js"></script>
|
||||
<% }else{ %>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ]
|
||||
2 info using npm@1.4.28
|
||||
3 info using node@v0.10.37
|
||||
4 verbose node symlink /usr/bin/node
|
||||
5 error install Couldn't read dependencies
|
||||
6 error package.json ENOENT, open '/home/didier/dev/go/src/gitlab.com/didiercrunch/phenix-website/static/package.json'
|
||||
6 error package.json This is most likely not a problem with npm itself.
|
||||
6 error package.json npm can't find a package.json file in your current directory.
|
||||
7 error System Linux 4.2.0-23-generic
|
||||
8 error command "/usr/bin/node" "/usr/bin/npm" "install"
|
||||
9 error cwd /home/didier/dev/go/src/gitlab.com/didiercrunch/phenix-website/static
|
||||
10 error node -v v0.10.37
|
||||
11 error npm -v 1.4.28
|
||||
12 error path /home/didier/dev/go/src/gitlab.com/didiercrunch/phenix-website/static/package.json
|
||||
13 error code ENOPACKAGEJSON
|
||||
14 error errno 34
|
||||
15 verbose exit [ 34, true ]
|
||||
+3
-1
@@ -7,6 +7,7 @@
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-bower": "0.0.13",
|
||||
"gulp-clean": "^0.3.1",
|
||||
"gulp-modify": "^0.1.1",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-sass": "^2.1.1",
|
||||
"gulp-task-listing": "^1.0.1",
|
||||
@@ -16,7 +17,8 @@
|
||||
"gulp-wrapper": "^1.0.0",
|
||||
"lodash": "^4.6.1",
|
||||
"marked": "^0.3.5",
|
||||
"requirejs": "^2.1.22"
|
||||
"requirejs": "^2.1.22",
|
||||
"spritzjs": "git+ssh://git@gitlab.com:didiercrunch/spritzjs.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-webserver": "^0.9.1",
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
requirejs.config({
|
||||
paths: {
|
||||
'_': '../lib/lodash/dist/lodash.min',
|
||||
'm': '../lib/mithril/mithril.min'
|
||||
'm': '../lib/mithril/mithril.min',
|
||||
'spritz': '../lib/spritzjs/dist/spritz'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ define(['m', '_', 'teams', 'views/loginPage', 'views/playersPage', 'views/topNav
|
||||
|
||||
confidentialPage.view = function(){
|
||||
var body;
|
||||
if(!window.secret){
|
||||
if(_.isEmpty(window.secret)){
|
||||
body = loginPage;
|
||||
}else{
|
||||
body = playersPage;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
define(['m', '_'], function (m, _) {
|
||||
|
||||
var loginPage = {};
|
||||
loginPage.salt = "9'D)E@E{DSq[|l2bq!v";
|
||||
loginPage.salt = window.salt;
|
||||
|
||||
loginPage.controller = function(){
|
||||
return {email: m.prop(''), password: m.prop('')};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['m', '_', 'teams'], function (m, _ , teams) {
|
||||
define(['m', '_', 'spritz', 'teams'], function (m, _ , spritz, teams) {
|
||||
|
||||
var playersSelectionBar = {};
|
||||
|
||||
@@ -83,12 +83,20 @@ define(['m', '_', 'teams'], function (m, _ , teams) {
|
||||
return _.orderBy(playerList, sortingKeys, sortingDirections);
|
||||
};
|
||||
|
||||
playersTable.decryptPlayerList = function(encryptedPlayerList){
|
||||
var keyLengthInBytes = 128;
|
||||
var key = spritz.hash(window.secret, keyLengthInBytes);
|
||||
var decryptedMessage = spritz.decrypt(key, encryptedPlayerList);
|
||||
return JSON.parse(spritz.utf8ByteArrayToString(decryptedMessage));
|
||||
};
|
||||
|
||||
playersTable.controller = function(model){
|
||||
var players = m.prop([]);
|
||||
var ctrl = {};
|
||||
ctrl.model = model;
|
||||
|
||||
ctrl.players = m.request({method: "GET", url: "api/players.json"})
|
||||
ctrl.players = m.request({method: "GET", url: window.playerListLocation})
|
||||
.then(playersTable.decryptPlayerList)
|
||||
.then(players);
|
||||
ctrl.sortPlayers = function(){
|
||||
ctrl.players(playersTable._sortPlayers(ctrl.model.sorting, ctrl.players()));
|
||||
|
||||
Reference in new issue
Block a user