Do some formatting
Change-Id: I58a658098339cc8c0b8a55cd89ccb6f470db9b71
diff --git a/static/main.js b/static/main.js
index 6fd5249..0f0025e 100644
--- a/static/main.js
+++ b/static/main.js
@@ -1,14 +1,14 @@
// Example starter JavaScript for disabling form submissions if there are invalid fields
-(function () {
+(function() {
'use strict';
- window.addEventListener('load', function () {
+ window.addEventListener('load', function() {
update_total_due();
update_paper_id_field();
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
- var validation = Array.prototype.filter.call(forms, function (form) {
- form.addEventListener('submit', function (event) {
+ var validation = Array.prototype.filter.call(forms, function(form) {
+ form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
@@ -24,7 +24,7 @@
if ($('#participate').is(":checked")) {
- costs += parseInt($("#conference_fee").text(),10);
+ costs += parseInt($("#conference_fee").text(), 10);
if ($('#student').is(":checked")) {
costs -= parseInt($("#student_discount").text(), 10);
}
@@ -32,7 +32,7 @@
costs += parseInt($("#conference_dinner_price").text(), 10);
}
}
- $("#total_due").val(costs.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}));
+ $("#total_due").val(costs.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }));
}
function update_paper_id_field() {
@@ -42,7 +42,11 @@
paper_id.attr('placeholder', '0000');
paper_id.attr('pattern', '\\d{4}');
paper_id.attr('required', 'required');
+ //if (paper_id.attr('oldval').match(/^\\d{4}$/)) {
+ // paper_id.val(paper_id.attr('oldval'));
+ //}
} else {
+ paper_id.attr('oldval', paper_id.val());
paper_id.val('');
paper_id.attr('disabled', 'disabled');
paper_id.removeAttr('placeholder');
@@ -80,7 +84,7 @@
REP_NE = 'Passwords not identical';
PWNED = 'Password found in public password list';
-String.prototype.strReverse = function () {
+String.prototype.strReverse = function() {
var newstring = '';
for (var s = 0; s < this.length; s++)
newstring = this.charAt(s) + newstring;
@@ -91,7 +95,7 @@
const sha1Hash = CryptoJS.enc.Hex.stringify(CryptoJS.SHA1(pass)).toUpperCase();
const passwordChunk1 = sha1Hash.substring(0, 5);
const passwordChunk2 = sha1Hash.substring(5);
- $.get('https://api.pwnedpasswords.com/range/' + passwordChunk1).done(function (data, status) {
+ $.get('https://api.pwnedpasswords.com/range/' + passwordChunk1).done(function(data, status) {
var isPwned = false;
if (status == "success") {
if (data && data.length) {
@@ -134,24 +138,33 @@
nScore = 4 * nLength;
// check for upper-/lowercase, numeric and special chars pattern matches
- var nAlphaUC = 0, nAlphaLC = 0, nNumber = 0, nSpecial = 0;
- var nMidChar = 0, nRepChar = 0, nRepInc = 0;
- var nConsecAlphaUC = 0, nConsecAlphaLC = 0, nConsecNumber = 0;
- var nTmpAlphaUC = '', nTmpAlphaLC = '', nTmpNumber = '';
+ var nAlphaUC = 0,
+ nAlphaLC = 0,
+ nNumber = 0,
+ nSpecial = 0;
+ var nMidChar = 0,
+ nRepChar = 0,
+ nRepInc = 0;
+ var nConsecAlphaUC = 0,
+ nConsecAlphaLC = 0,
+ nConsecNumber = 0;
+ var nTmpAlphaUC = '',
+ nTmpAlphaLC = '',
+ nTmpNumber = '';
for (var i = 0; i < nLength; i++) {
- if (pass[i].match(/[A-Z]/g)) { // uppercase characters
+ if (pass[i].match(/[A-Z]/g)) { // uppercase characters
if (nTmpAlphaUC !== '' && (nTmpAlphaUC + 1) == i) {
nConsecAlphaUC++;
}
nTmpAlphaUC = i;
nAlphaUC++;
- } else if (pass[i].match(/[a-z]/g)) { // lowercase characters
+ } else if (pass[i].match(/[a-z]/g)) { // lowercase characters
if (nTmpAlphaLC !== '' && (nTmpAlphaLC + 1) == i) {
nConsecAlphaLC++;
}
nTmpAlphaLC = i;
nAlphaLC++;
- } else if (pass[i].match(/[0-9]/g)) { // numbers
+ } else if (pass[i].match(/[0-9]/g)) { // numbers
if (i > 0 && i < (nLength - 1)) {
nMidChar++;
}
@@ -160,7 +173,7 @@
}
nTmpNumber = i;
nNumber++;
- } else { // special characters
+ } else { // special characters
if (i > 0 && i < (nLength - 1)) {
nMidChar++;
}
@@ -188,8 +201,8 @@
for (var i = 0; i < 23; i++) {
var sFwd = sAlphas.substring(i, i + 3);
var sRev = sFwd.strReverse();
- if (pass.toLowerCase().indexOf(sFwd) != -1
- || pass.toLowerCase().indexOf(sRev) != -1)
+ if (pass.toLowerCase().indexOf(sFwd) != -1 ||
+ pass.toLowerCase().indexOf(sRev) != -1)
nSeqAlpha++;
}
@@ -199,41 +212,41 @@
for (var i = 0; i < 8; i++) {
var sFwd = sNumerics.substring(i, i + 3);
var sRev = sFwd.strReverse();
- if (pass.toLowerCase().indexOf(sFwd) != -1
- || pass.toLowerCase().indexOf(sRev) != -1)
+ if (pass.toLowerCase().indexOf(sFwd) != -1 ||
+ pass.toLowerCase().indexOf(sRev) != -1)
nSeqNumber++;
}
// general point assignment
- if (nAlphaUC > 0 && nAlphaUC < nLength) // uppercase characters
+ if (nAlphaUC > 0 && nAlphaUC < nLength) // uppercase characters
nScore += 2 * (nLength - nAlphaUC);
- if (nAlphaLC > 0 && nAlphaLC < nLength) // lowercase characters
+ if (nAlphaLC > 0 && nAlphaLC < nLength) // lowercase characters
nScore += 2 * (nLength - nAlphaLC);
- if (nNumber > 0 && nNumber < nLength) // numbers
+ if (nNumber > 0 && nNumber < nLength) // numbers
nScore += 2 * nNumber;
- if (nSpecial > 0) // special characters
+ if (nSpecial > 0) // special characters
nScore += 4 * nSpecial;
- if (nMidChar > 0) // mid numbers/special characters
+ if (nMidChar > 0) // mid numbers/special characters
nScore += 2 * nMidChar;
// point deductions for poor practices
- if ((nAlphaLC > 0 || nAlphaUC > 0)
- && nSpecial === 0 && nNumber === 0) // characters only
+ if ((nAlphaLC > 0 || nAlphaUC > 0) &&
+ nSpecial === 0 && nNumber === 0) // characters only
nScore -= nLength;
- if (nAlphaLC === 0 && nAlphaUC === 0
- && nSpecial === 0 && nNumber > 0) // numbers only
+ if (nAlphaLC === 0 && nAlphaUC === 0 &&
+ nSpecial === 0 && nNumber > 0) // numbers only
nScore -= nLength;
- if (nRepChar > 0) // same character exists more than once
+ if (nRepChar > 0) // same character exists more than once
nScore -= nRepInc;
- if (nConsecAlphaUC > 0) // consecutive uppercase letters exist
+ if (nConsecAlphaUC > 0) // consecutive uppercase letters exist
nScore -= 2 * nConsecAlphaUC;
- if (nConsecAlphaLC > 0) // consecutive lowercase letters exist
+ if (nConsecAlphaLC > 0) // consecutive lowercase letters exist
nScore -= 2 * nConsecAlphaLC;
- if (nConsecNumber > 0) // consecutive numbers exist
+ if (nConsecNumber > 0) // consecutive numbers exist
nScore -= 2 * nConsecNumber;
- if (nSeqAlpha > 0) // sequential alpha strings exist (3 chars or more)
+ if (nSeqAlpha > 0) // sequential alpha strings exist (3 chars or more)
nScore -= 3 * nSeqAlpha;
- if (nSeqNumber > 0) // sequential numeric strings exist (3 chars or more)
+ if (nSeqNumber > 0) // sequential numeric strings exist (3 chars or more)
nScore -= 3 * nSeqNumber;
// determine if mandatory requirements have been met
@@ -289,7 +302,7 @@
$("#password-div")[0].classList.add('was-validated');
$('#btn_change').prop('disabled', pass !== pass2);
$("#pw1")[0].setCustomValidity("");
- isPasswordPwned(pass, function (isPwned) {
+ isPasswordPwned(pass, function(isPwned) {
if (isPwned) {
$('#pwqinfo').val(PWNED);
progress.removeClass().addClass('low');
@@ -303,4 +316,4 @@
$("#pw1")[0].setCustomValidity("Password is to week");
}
-}
+}
\ No newline at end of file