add_user.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $(function () {
  2. $('#v_email').change(function () {
  3. if ($('#v_email_notify').prop('checked')) {
  4. document.getElementById('v_notify').value = document.getElementById('v_email').value;
  5. }
  6. });
  7. $('#v_email_notify').change(function () {
  8. if ($('#v_email_notify').prop('checked')) {
  9. document.getElementById('v_notify').value = document.getElementById('v_email').value;
  10. } else {
  11. document.getElementById('v_notify').value = '';
  12. }
  13. });
  14. });
  15. applyRandomPassword = function (min_length = 16) {
  16. $('input[name=v_password]').val(randomString(min_length));
  17. App.Actions.WEB.update_password_meter();
  18. };
  19. App.Actions.WEB.update_password_meter = function () {
  20. var password = $('input[name="v_password"]').val();
  21. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  22. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  23. var min_num = new RegExp(/^(?=.*\d).+$/);
  24. var min_length = 8;
  25. var score = 0;
  26. if (password.length >= min_length) {
  27. score = score + 1;
  28. }
  29. if (min_small.test(password)) {
  30. score = score + 1;
  31. }
  32. if (min_cap.test(password)) {
  33. score = score + 1;
  34. }
  35. if (min_num.test(password)) {
  36. score = score + 1;
  37. }
  38. $('.js-password-meter').val(score);
  39. };
  40. App.Listeners.WEB.keypress_v_password = function () {
  41. var ref = $('input[name="v_password"]');
  42. ref.bind('keypress input', function (evt) {
  43. clearTimeout(window.frp_usr_tmt);
  44. window.frp_usr_tmt = setTimeout(function () {
  45. var elm = $(evt.target);
  46. App.Actions.WEB.update_password_meter(elm, $(elm).val());
  47. }, 100);
  48. });
  49. };
  50. App.Listeners.WEB.keypress_v_password();