-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
6,820 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/boron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
--- | ||
dist: trusty | ||
language: node_js | ||
node_js: | ||
- "4.6.0" | ||
|
||
sudo: false | ||
|
||
cache: | ||
yarn: true | ||
directories: | ||
- node_modules | ||
- $HOME/.cache # includes bowers cache | ||
|
||
before_install: | ||
- cp .env-travis .env | ||
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH | ||
- npm config set spin false | ||
- npm install -g bower | ||
- bower --version | ||
|
||
install: | ||
- npm install | ||
- bower install | ||
- curl -o- -L https://yarnpkg.com/install.sh | bash | ||
- export PATH=$HOME/.yarn/bin:$PATH | ||
- yarn install --pure-lockfile | ||
- ./node_modules/bower/bin/bower install --config.interactive=false | ||
|
||
script: | ||
- npm run check-style && npm test | ||
- yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ | |
margin-right: -50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 25px; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* jshint worker:true */ | ||
/* global dcodeIO */ | ||
|
||
importScripts('bcryptjs/dist/bcrypt.min.js'); | ||
const bcrypt = dcodeIO.bcrypt; | ||
|
||
const bounds = [ | ||
[49, 57], // 1-9 | ||
[65, 90], // A-Z | ||
]; | ||
|
||
const possible = []; | ||
|
||
for (let b = 0; b < bounds.length; b++) { | ||
const bound = bounds[b]; | ||
const upperBound = bound[1] + 1; | ||
|
||
for (let i = bound[0]; i < upperBound; i++) { | ||
possible.push(String.fromCharCode(i)); | ||
} | ||
} | ||
|
||
const alphaRegex = /[A-Z]/; | ||
|
||
/** | ||
* Generates a new ID | ||
* @param len {Number} The length of the ID | ||
* @param [enforceAlpha=true] {Boolean} Whether or not to enforce alpha characters | ||
* @returns {String} The ID | ||
*/ | ||
function makeId(len, enforceAlpha=true) { | ||
const possibleLength = enforceAlpha ? possible.length : 9; | ||
let text = ''; | ||
|
||
for (let i = 0; i < len; i++) { | ||
text += possible[Math.floor(Math.random() * possibleLength)]; | ||
} | ||
|
||
// Enforce alpha characters in text if flag is set and recurse if criterion is not met | ||
return enforceAlpha && !alphaRegex.test(text) ? makeId(len) : text; | ||
} | ||
|
||
/** | ||
* Web worker message receiver for generating account records | ||
* @param {Object} event | ||
* @param {Object} event.data | ||
* @param {Number} event.data.batchSize The size of the batch (how many accounts to generate) | ||
* @param {String} event.data.studyId The Study ID | ||
* @param {Object} event.data.extra The extra fields | ||
* @param {String} [event.data.tag] The tag | ||
* @returns {Object[]} The account records | ||
* @private | ||
*/ | ||
self.onmessage = event => { | ||
const {batchSize, studyId, extra, tag} = event.data; | ||
const records = []; | ||
const idSet = []; | ||
|
||
for (let i = 0; i < batchSize; i++) { | ||
postMessage({ | ||
progress: i | ||
}); | ||
|
||
let id; | ||
|
||
// Check for duplicated IDs. Unlikely, but possible. | ||
while (!id || ~idSet.indexOf(id)) { | ||
id = `${makeId(7)}${tag ? `-${tag}` : ''}`; | ||
} | ||
|
||
idSet.push(id); | ||
|
||
const salt = bcrypt.genSaltSync(12); | ||
const password = bcrypt.hashSync(studyId, salt).replace('$2a$', '$2b$'); | ||
|
||
records[i] = { | ||
id, | ||
password, | ||
extra | ||
}; | ||
} | ||
|
||
postMessage({records}); | ||
}; |
Oops, something went wrong.