add_user.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. randomString = function(min_length = 16) {
  16. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  17. var string_length = min_length;
  18. var randomstring = '';
  19. for (var i = 0; i < string_length; i++) {
  20. var rnum = Math.floor(Math.random() * chars.length);
  21. randomstring += chars.substr(rnum, 1);
  22. }
  23. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  24. if(!regex.test(randomstring)){
  25. randomString();
  26. }else{
  27. $('input[name=v_password]').val(randomstring);
  28. App.Actions.WEB.update_v_password();
  29. }
  30. }
  31. App.Actions.WEB.update_v_password = function (){
  32. var password = $('input[name="v_password"]').val();
  33. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  34. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  35. var min_num = new RegExp(/^(?=.*\d).+$/);
  36. var min_length = 8;
  37. var score = 0;
  38. if(password.length >= min_length) { score = score + 1; }
  39. if(min_small.test(password)) { score = score + 1;}
  40. if(min_cap.test(password)) { score = score + 1;}
  41. if(min_num.test(password)) { score = score+ 1; }
  42. $('#meter').val(score);
  43. }
  44. App.Listeners.WEB.keypress_v_password = function() {
  45. var ref = $('input[name="v_password"]');
  46. ref.bind('keypress input', function(evt) {
  47. clearTimeout(window.frp_usr_tmt);
  48. window.frp_usr_tmt = setTimeout(function() {
  49. var elm = $(evt.target);
  50. App.Actions.WEB.update_v_password(elm, $(elm).val());
  51. }, 100);
  52. });
  53. }
  54. App.Listeners.WEB.keypress_v_password();