edit_mail_acc.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. App.Actions.MAIL_ACC.enable_unlimited = function(elm, source_elm) {
  2. $(elm).data('checked', true);
  3. $(elm).data('prev_value', $(elm).val()); // save prev value in order to restore if needed
  4. $(elm).val(App.Constants.UNLIM_TRANSLATED_VALUE);
  5. $(elm).attr('disabled', true);
  6. $(source_elm).css('opacity', '1');
  7. }
  8. App.Actions.MAIL_ACC.disable_unlimited = function(elm, source_elm) {
  9. $(elm).data('checked', false);
  10. if ($(elm).data('prev_value') && $(elm).data('prev_value').trim() != '') {
  11. var prev_value = $(elm).data('prev_value').trim();
  12. $(elm).val(prev_value);
  13. if (App.Helpers.isUnlimitedValue(prev_value)) {
  14. $(elm).val('0');
  15. }
  16. }
  17. else {
  18. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  19. $(elm).val('0');
  20. }
  21. }
  22. $(elm).attr('disabled', false);
  23. $(source_elm).css('opacity', '0.5');
  24. }
  25. //
  26. App.Actions.MAIL_ACC.toggle_unlimited_feature = function(evt) {
  27. var elm = $(evt.target);
  28. var ref = elm.prev('.vst-input');
  29. if (!$(ref).data('checked')) {
  30. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  31. }
  32. else {
  33. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  34. }
  35. }
  36. App.Listeners.MAIL_ACC.checkbox_unlimited_feature = function() {
  37. $('.unlim-trigger').on('click', App.Actions.MAIL_ACC.toggle_unlimited_feature);
  38. }
  39. App.Listeners.MAIL_ACC.init = function() {
  40. $('.unlim-trigger').each(function(i, elm) {
  41. var ref = $(elm).prev('.vst-input');
  42. if (App.Helpers.isUnlimitedValue($(ref).val())) {
  43. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  44. }
  45. else {
  46. $(ref).data('prev_value', $(ref).val());
  47. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  48. }
  49. });
  50. }
  51. App.Actions.MAIL_ACC.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.MAIL_ACC.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.MAIL_ACC.update_v_password(elm, $(elm).val());
  71. }, 100);
  72. });
  73. }
  74. App.Listeners.MAIL_ACC.keypress_v_password();
  75. randomString = function(min_length = 16) {
  76. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  77. var string_length = min_length;
  78. var randomstring = '';
  79. for (var i = 0; i < string_length; i++) {
  80. var rnum = Math.floor(Math.random() * chars.length);
  81. randomstring += chars.substr(rnum, 1);
  82. }
  83. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  84. if(!regex.test(randomstring)){
  85. randomString();
  86. }else{
  87. $('input[name=v_password]').val(randomstring);
  88. if($('input[name=v_password]').attr('type') == 'text')
  89. $('#v_password').text(randomstring);
  90. else
  91. $('#v_password').text(Array(randomstring.length+1).join('*'));
  92. App.Actions.MAIL_ACC.update_v_password();
  93. generate_mail_credentials();
  94. }
  95. }
  96. generate_mail_credentials = function() {
  97. var div = $('.mail-infoblock').clone();
  98. div.find('#mail_configuration').remove();
  99. var pass=div.find('#v_password').text();
  100. if (pass=="") div.find('#v_password').html(' ');
  101. var output = div.text();
  102. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  103. output=output.replace(/ /g, "");
  104. output=output.replace(/\|\|/g, "|");
  105. output=output.replace(/\|\|/g, "|");
  106. output=output.replace(/\|\|/g, "|");
  107. output=output.replace(/^\|+/g, "");
  108. output=output.replace(/\|$/, "");
  109. output=output.replace(/ $/, "");
  110. output=output.replace(/:\|/g, ": ");
  111. output=output.replace(/\|/g, "\n");
  112. //console.log(output);
  113. $('#v_credentials').val(output);
  114. }
  115. $(document).ready(function() {
  116. $('#v_account').text($('input[name=v_account]').val());
  117. $('#v_password').text($('input[name=v_password]').val());
  118. generate_mail_credentials();
  119. $('input[name=v_account]').change(function(){
  120. $('#v_account').text($(this).val());
  121. generate_mail_credentials();
  122. });
  123. $('input[name=v_password]').change(function(){
  124. if($('input[name=v_password]').attr('type') == 'text')
  125. $('#v_password').text($(this).val());
  126. else
  127. $('#v_password').text(Array($(this).val().length+1).join('*'));
  128. generate_mail_credentials();
  129. });
  130. $('.toggle-psw-visibility-icon').click(function(){
  131. if($('input[name=v_password]').attr('type') == 'text')
  132. $('#v_password').text($('input[name=v_password]').val());
  133. else
  134. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  135. generate_mail_credentials();
  136. });
  137. $('#mail_configuration').change(function(evt){
  138. var opt = $(evt.target).find('option:selected');
  139. switch(opt.attr('v_type')){
  140. case 'hostname':
  141. $('#td_imap_hostname').html(opt.attr('domain'));
  142. $('#td_smtp_hostname').html(opt.attr('domain'));
  143. break;
  144. case 'starttls':
  145. $('#td_imap_port').html('143');
  146. $('#td_imap_encryption').html('STARTTLS');
  147. $('#td_smtp_port').html('587');
  148. $('#td_smtp_encryption').html('STARTTLS');
  149. break;
  150. case 'ssl':
  151. $('#td_imap_port').html('993');
  152. $('#td_imap_encryption').html('SSL / TLS');
  153. $('#td_smtp_port').html('465');
  154. $('#td_smtp_encryption').html('SSL / TLS');
  155. break;
  156. case 'no_encryption':
  157. $('#td_imap_hostname').html(opt.attr('domain'));
  158. $('#td_smtp_hostname').html(opt.attr('domain'));
  159. $('#td_imap_port').html('143');
  160. $('#td_imap_encryption').html(opt.attr('no_encryption'));
  161. $('#td_smtp_port').html('25');
  162. $('#td_smtp_encryption').html(opt.attr('no_encryption'));
  163. break;
  164. }
  165. generate_mail_credentials();
  166. });
  167. });