add_db.js 2.8 KB

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