edit_mail_acc.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. $('#v_blackhole').on('click', function(evt){
  75. if($('#v_blackhole').is(':checked')){
  76. $('#v_fwd').prop('disabled', true);
  77. $('#v_fwd_for').prop('checked', true);
  78. $('#id_fwd_for').hide();
  79. }else{
  80. $('#v_fwd').prop('disabled', false);
  81. $('#id_fwd_for').show();
  82. }
  83. });
  84. App.Listeners.MAIL_ACC.keypress_v_password();
  85. randomString = function (min_length = 16) {
  86. var randomstring = randomString2(min_length);
  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. generate_mail_credentials = function() {
  96. var div = $('.mail-infoblock').clone();
  97. div.find('#mail_configuration').remove();
  98. var pass=div.find('#v_password').text();
  99. if (pass=="") div.find('#v_password').text(' ');
  100. var output = div.text();
  101. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  102. output=output.replace(/ /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(/\|$/, "");
  108. output=output.replace(/ $/, "");
  109. output=output.replace(/:\|/g, ": ");
  110. output=output.replace(/\|/g, "\n");
  111. $('#v_credentials').val(output);
  112. }
  113. $(document).ready(function() {
  114. $('#v_account').text($('input[name=v_account]').val());
  115. $('#v_password').text($('input[name=v_password]').val());
  116. generate_mail_credentials();
  117. $('input[name=v_account]').change(function(){
  118. $('#v_account').text($(this).val());
  119. generate_mail_credentials();
  120. });
  121. $('input[name=v_password]').change(function(){
  122. if($('input[name=v_password]').attr('type') == 'text')
  123. $('#v_password').text($(this).val());
  124. else
  125. $('#v_password').text(Array($(this).val().length+1).join('*'));
  126. generate_mail_credentials();
  127. });
  128. $('.toggle-psw-visibility-icon').click(function(){
  129. if($('input[name=v_password]').attr('type') == 'text')
  130. $('#v_password').text($('input[name=v_password]').val());
  131. else
  132. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  133. generate_mail_credentials();
  134. });
  135. $('#mail_configuration').change(function(evt){
  136. var opt = $(evt.target).find('option:selected');
  137. switch(opt.attr('v_type')){
  138. case 'hostname':
  139. $('#td_imap_hostname').text(opt.attr('domain'));
  140. $('#td_smtp_hostname').text(opt.attr('domain'));
  141. break;
  142. case 'starttls':
  143. $('#td_imap_port').text('143');
  144. $('#td_imap_encryption').text('STARTTLS');
  145. $('#td_smtp_port').text('587');
  146. $('#td_smtp_encryption').text('STARTTLS');
  147. break;
  148. case 'ssl':
  149. $('#td_imap_port').text('993');
  150. $('#td_imap_encryption').text('SSL / TLS');
  151. $('#td_smtp_port').text('465');
  152. $('#td_smtp_encryption').text('SSL / TLS');
  153. break;
  154. case 'no_encryption':
  155. $('#td_imap_hostname').text(opt.attr('domain'));
  156. $('#td_smtp_hostname').text(opt.attr('domain'));
  157. $('#td_imap_port').text('143');
  158. $('#td_imap_encryption').text(opt.attr('no_encryption'));
  159. $('#td_smtp_port').text('25');
  160. $('#td_smtp_encryption').text(opt.attr('no_encryption'));
  161. break;
  162. }
  163. generate_mail_credentials();
  164. });
  165. });