add_db.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. //
  3. // Updates database username dynamically, showing its prefix
  4. App.Actions.DB.update_db_username_hint = function(elm, hint) {
  5. if (hint.trim() == '') {
  6. $(elm).parent().find('.hint').text('');
  7. }
  8. $(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint);
  9. }
  10. //
  11. //
  12. // Updates database name dynamically, showing its prefix
  13. App.Actions.DB.update_db_databasename_hint = function(elm, hint) {
  14. if (hint.trim() == '') {
  15. $(elm).parent().find('.hint').text('');
  16. }
  17. $(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint);
  18. }
  19. //
  20. // listener that triggers database user hint updating
  21. App.Listeners.DB.keypress_db_username = function() {
  22. var ref = $('input[name="v_dbuser"]');
  23. var current_val = ref.val();
  24. if (current_val.trim() != '') {
  25. App.Actions.DB.update_db_username_hint(ref, current_val);
  26. }
  27. ref.bind('keypress input', function(evt) {
  28. clearTimeout(window.frp_usr_tmt);
  29. window.frp_usr_tmt = setTimeout(function() {
  30. var elm = $(evt.target);
  31. App.Actions.DB.update_db_username_hint(elm, $(elm).val());
  32. }, 100);
  33. });
  34. }
  35. //
  36. // listener that triggers database name hint updating
  37. App.Listeners.DB.keypress_db_databasename = function() {
  38. var ref = $('input[name="v_database"]');
  39. var current_val = ref.val();
  40. if (current_val.trim() != '') {
  41. App.Actions.DB.update_db_databasename_hint(ref, current_val);
  42. }
  43. ref.bind('keypress input', function(evt) {
  44. clearTimeout(window.frp_dbn_tmt);
  45. window.frp_dbn_tmt = setTimeout(function() {
  46. var elm = $(evt.target);
  47. App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
  48. }, 100);
  49. });
  50. }
  51. App.Actions.DB.update_v_password = function (){
  52. var password = $('input[name="v_password"]').val();
  53. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  54. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  55. var min_num = new RegExp(/^(?=.*\d).+$/);
  56. var min_length = 8;
  57. var score = 0;
  58. if(password.length >= min_length) { score = score + 1; }
  59. if(min_small.test(password)) { score = score + 1;}
  60. if(min_cap.test(password)) { score = score + 1;}
  61. if(min_num.test(password)) { score = score+ 1; }
  62. $('#meter').val(score);
  63. }
  64. App.Listeners.DB.keypress_v_password = function() {
  65. var ref = $('input[name="v_password"]');
  66. ref.bind('keypress input', function(evt) {
  67. clearTimeout(window.frp_usr_tmt);
  68. window.frp_usr_tmt = setTimeout(function() {
  69. var elm = $(evt.target);
  70. App.Actions.DB.update_v_password(elm, $(elm).val());
  71. }, 100);
  72. });
  73. }
  74. App.Listeners.DB.keypress_v_password();
  75. //
  76. // Page entry point
  77. // Trigger listeners
  78. App.Listeners.DB.keypress_db_username();
  79. App.Listeners.DB.keypress_db_databasename();
  80. randomString = function(min_length = 16) {
  81. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  82. var string_length = min_length;
  83. var randomstring = '';
  84. for (var i = 0; i < string_length; i++) {
  85. var rnum = Math.floor(Math.random() * chars.length);
  86. randomstring += chars.substr(rnum, 1);
  87. }
  88. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  89. if(!regex.test(randomstring)){
  90. randomString();
  91. }else{
  92. $('input[name=v_password]').val(randomstring);
  93. App.Actions.DB.update_v_password();
  94. }
  95. }