<commit_before>var closing_attempts = 0;
var labStatus = null;
var internal = true;
getStatus();

$('#registration').on('shown.bs.modal', function() {
  $('#name').focus();
});

$('#registration').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#name').val('');
  $('#userIdNumber').val('');
  $('#approval').val('');
  $('#passphrase').val('');
  $('#username').val('');
  $("#passwordRegistration").val('');
  $("#confirmPasswordRegistration").val('');
  $("#approvalGroup").removeClass('has-error');
  $("#userIdNumberGroup").removeClass('has-error');
  $("#passphraseGroup").removeClass('has-error');
  $("#usernameGroup").removeClass('has-error');
  $("#passwordRegistrationCloup").removeClass('has-error');
});

$('#closeModal').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#password').val('');
  $("#passwordGroup").removeClass('has-error');
});

$('#closeModal').on('shown.bs.modal', function() {
  $('#password').focus();
});

$('#kickModal').on('hidden.bs.modal', function(){
  $('#idNumber').val('');
});

$('#passwordModal').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#currentPassword').val('');
  $('#newPassword').val('');
  $('#repeatPassword').val('');
  $("#currentPasswordGroup").removeClass('has-error');
  $("#repeatPasswordGroup").removeClass('has-error');
  $('#currentPasswordGroup').removeClass('hidden');
});

$('#passwordModal').on('shown.bs.modal', function() {
  if($('#currentPassword').val() != ''){
    $('#newPassword').focus();
  }else{
    $('#currentPassword').focus();
  }
});

function showNeedsPassword(idNumber){
  $('#hiddenId').val(idNumber);
  $('#passwordModal').modal('show');
}

function submitLogin(){
    var idNumber = document.getElementById('idNumber').value;
    var convertedId = convertSwipe(idNumber);
    document.getElementById('idNumber').value = '';
    if(!isValidId(convertedId) && !isValidUsername(idNumber)){
        showMessage('Please try again!', 3000, 'error');
        return;
    }
    if(convertedId){
      swipe(convertedId);
    }else{
      swipe(idNumber);
    }
    document.getElementById('idNumber').focus();
    return false;
}

function swipe(idNumber){
  var data = JSON.stringify({'idNumber':idNumber});
  postData('/lab/swipe', data,
  function(statusCode){
      switch(statusCode){
          case 0: showMessage('Success!'); getStatus(); break;
          case 1: showMessage('Lab is currently closed!', 2000, 'error'); break;
          case 2: showRegistration(idNumber); break;
          case 3: showUsersPresent(idNumber); break;
          case 4: showNeedsPassword(idNumber); break;
          default: showFailure(); break;
      }
  });
}

function showMessage(message, time, type){
  message = message || 'Success!';
  time = time || 2000;
  type = type || 'success';
  $('#idNumber').notify(message, {className: type, elementPosition: 'left middle', autoHideDelay: time});
}

function showUsersPresent(idNumber){
  if(closing_attempts == 1){
    $("#closeModal").modal('show');
    $("#hiddenId").val(idNumber);
    $("#password").focus();
    closing_attempts = 0;
  }else{
    showMessage('Users are still present! Swipe again to close!', 4000, 'error');
    closing_attempts++;
    setTimeout( function() {
      closing_attempts = 0;
    }, 30000);
  }
}

function hideModals(){
  $('#kickModal').modal('hide');
  $('#passwordModal').modal('hide');
  $('#registration').modal('hide');
  $('#closeModal').modal('hide');
  getStatus();
}

function showRegistration(idNumber){
  if(!labStatus.open){
    showMessage('Lab is currently closed!', 2000, 'error');
    return;
  }
  if(isValidId(idNumber)){
    document.getElementById('userIdNumber').value = idNumber;
  }else{
    document.getElementById('username').value = idNumber;
  }
  $('#registration').modal('show');
}

function failedPassword(){
  $('#currentPassword').val('');
  $('#currentPassword').notify('Password is incorrect!', {className: 'error', elementPosition:'right'});
  $('#currentPassword').focus();
  $('#currentPasswordGroup').addClass('has-error');
}

function submitRegistration(){
  var name = $('#name').val().trim();
  var newId = convertSwipe($('#userIdNumber').val().trim());
  var approval = convertSwipe($('#approval').val().trim());
  var username = $('#username').val().trim();
  var passphrase = $('#passphrase').val().trim();
  var password = $('#passwordRegistration').val().trim();
  var confirmPasswod = $('#confirmPasswordRegistration').val().trim();

  if(isValidId(newId)){
    $('#userIdNumber').val(newId);
  }

  if(isValidId(approval)){
    $('#approval').val(approval);
  }

  if(name == ''){
    addError('name', 'Name is a required field!');
    return false;
  }

  if(!isNaN(name)){
    if(name != newId && name.length == 9){
      $('#approval').val(name);
      $('#approval').notify('Moved ID Here!', {className: 'success', elementPosition:'right middle', autoHideDelay: 1000});
    }
    addError('name', 'Name goes here!');
    return false;
  }

  if(!isValidName(name)){
    addError('name','Name can only contain a-z, A-Z!');
    return false;
  }

  if(newId == ''){
    $('#userIdNumber').focus();
    return false;
  }

  if(newId.length != 9 || isNaN(parseInt(newId))){
    addError('userIdNumber', 'Invalid swipe, try again!');
    return false;
  }


  if(password == '' && confirmPassword == ''){
    $('#passwordRegistration').focus();
    return false;
  }

  if(password != confirmPasswod){
    addError('confirmPasswordRegistration', 'Passwords do not match!');
    addError('passwordRegistration', 'Passwords do not match!');
    return false;
  }

  if(password.length < 5){
    addError('passwordRegistration', 'Must be at least five characters long!');
    $('#confirmPasswordRegistration').val('');
    return false;
  }

  if(passphrase == ''){
    if(approval == ''){
      $('#approval').focus();
      return false;
    }
  }

  if((approval.length != 9 || isNaN(parseInt(approval))) && passphrase == ''){
    addError('approval', 'Invalid swipe, try again!');
    return false;
  }
  if(username.length < 4){
    addError('username', 'Username must consist of at least 4 alphanumeric character!');<commit_msg>typos<commit_after>var closing_attempts = 0;
var labStatus = null;
var internal = true;
getStatus();

$('#registration').on('shown.bs.modal', function() {
  $('#name').focus();
});

$('#registration').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#name').val('');
  $('#userIdNumber').val('');
  $('#approval').val('');
  $('#passphrase').val('');
  $('#username').val('');
  $("#passwordRegistration").val('');
  $("#confirmPasswordRegistration").val('');
  $("#approvalGroup").removeClass('has-error');
  $("#userIdNumberGroup").removeClass('has-error');
  $("#passphraseGroup").removeClass('has-error');
  $("#usernameGroup").removeClass('has-error');
  $("#passwordRegistrationCloup").removeClass('has-error');
});

$('#closeModal').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#password').val('');
  $("#passwordGroup").removeClass('has-error');
});

$('#closeModal').on('shown.bs.modal', function() {
  $('#password').focus();
});

$('#kickModal').on('hidden.bs.modal', function(){
  $('#idNumber').val('');
});

$('#passwordModal').on('hidden.bs.modal', function() {
  $('#idNumber').focus();
  $('#currentPassword').val('');
  $('#newPassword').val('');
  $('#repeatPassword').val('');
  $("#currentPasswordGroup").removeClass('has-error');
  $("#repeatPasswordGroup").removeClass('has-error');
  $('#currentPasswordGroup').removeClass('hidden');
});

$('#passwordModal').on('shown.bs.modal', function() {
  if($('#currentPassword').val() != ''){
    $('#newPassword').focus();
  }else{
    $('#currentPassword').focus();
  }
});

function showNeedsPassword(idNumber){
  $('#hiddenId').val(idNumber);
  $('#passwordModal').modal('show');
}

function submitLogin(){
    var idNumber = document.getElementById('idNumber').value;
    var convertedId = convertSwipe(idNumber);
    document.getElementById('idNumber').value = '';
    if(!isValidId(convertedId) && !isValidUsername(idNumber)){
        showMessage('Please try again!', 3000, 'error');
        return;
    }
    if(convertedId){
      swipe(convertedId);
    }else{
      swipe(idNumber);
    }
    document.getElementById('idNumber').focus();
    return false;
}

function swipe(idNumber){
  var data = JSON.stringify({'idNumber':idNumber});
  postData('/lab/swipe', data,
  function(statusCode){
      switch(statusCode){
          case 0: showMessage('Success!'); getStatus(); break;
          case 1: showMessage('Lab is currently closed!', 2000, 'error'); break;
          case 2: showRegistration(idNumber); break;
          case 3: showUsersPresent(idNumber); break;
          case 4: showNeedsPassword(idNumber); break;
          default: showFailure(); break;
      }
  });
}

function showMessage(message, time, type){
  message = message || 'Success!';
  time = time || 2000;
  type = type || 'success';
  $('#idNumber').notify(message, {className: type, elementPosition: 'left middle', autoHideDelay: time});
}

function showUsersPresent(idNumber){
  if(closing_attempts == 1){
    $("#closeModal").modal('show');
    $("#hiddenId").val(idNumber);
    $("#password").focus();
    closing_attempts = 0;
  }else{
    showMessage('Users are still present! Swipe again to close!', 4000, 'error');
    closing_attempts++;
    setTimeout( function() {
      closing_attempts = 0;
    }, 30000);
  }
}

function hideModals(){
  $('#kickModal').modal('hide');
  $('#passwordModal').modal('hide');
  $('#registration').modal('hide');
  $('#closeModal').modal('hide');
  getStatus();
}

function showRegistration(idNumber){
  if(!labStatus.open){
    showMessage('Lab is currently closed!', 2000, 'error');
    return;
  }
  if(isValidId(idNumber)){
    document.getElementById('userIdNumber').value = idNumber;
  }else{
    document.getElementById('username').value = idNumber;
  }
  $('#registration').modal('show');
}

function failedPassword(){
  $('#currentPassword').val('');
  $('#currentPassword').notify('Password is incorrect!', {className: 'error', elementPosition:'right'});
  $('#currentPassword').focus();
  $('#currentPasswordGroup').addClass('has-error');
}

function submitRegistration(){
  var name = $('#name').val().trim();
  var newId = convertSwipe($('#userIdNumber').val().trim());
  var approval = convertSwipe($('#approval').val().trim());
  var username = $('#username').val().trim();
  var passphrase = $('#passphrase').val().trim();
  var password = $('#passwordRegistration').val().trim();
  var confirmPassword = $('#confirmPasswordRegistration').val().trim();

  if(isValidId(newId)){
    $('#userIdNumber').val(newId);
  }

  if(isValidId(approval)){
    $('#approval').val(approval);
  }

  if(name == ''){
    addError('name', 'Name is a required field!');
    return false;
  }

  if(!isNaN(name)){
    if(name != newId && name.length == 9){
      $('#approval').val(name);
      $('#approval').notify('Moved ID Here!', {className: 'success', elementPosition:'right middle', autoHideDelay: 1000});
    }
    addError('name', 'Name goes here!');
    return false;
  }

  if(!isValidName(name)){
    addError('name','Name can only contain a-z, A-Z!');
    return false;
  }

  if(newId == ''){
    $('#userIdNumber').focus();
    return false;
  }

  if(newId.length != 9 || isNaN(parseInt(newId))){
    addError('userIdNumber', 'Invalid swipe, try again!');
    return false;
  }


  if(password == '' && confirmPassword == ''){
    $('#passwordRegistration').focus();
    return false;
  }

  if(password != confirmPassword){
    addError('confirmPasswordRegistration', 'Passwords do not match!');
    addError('passwordRegistration', 'Passwords do not match!');
    return false;
  }

  if(password.length < 5){
    addError('passwordRegistration', 'Must be at least five characters long!');
    $('#confirmPasswordRegistration').val('');
    return false;
  }

  if(passphrase == ''){
    if(approval == ''){
      $('#approval').focus();
      return false;
    }
  }

  if((approval.length != 9 || isNaN(parseInt(approval))) && passphrase == ''){
    addError('approval', 'Invalid swipe, try again!');
    return false;
  }
  if(username.length < 4){
    addError('username', 'Username must consist of at least 4 alphanumeric character!');
{'fraction_non_alphanumeric': 0.2235503149733484, 'fraction_numerical': 0.0071070909384590535, 'mean_word_length': 4.631195998180991, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5792741', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3781, 'n_words': 683}