edit_mail_acc.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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(Alpine.store('globals').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 (Alpine.store('globals').isUnlimitedValue(prev_value)) {
  14. $(elm).val('0');
  15. }
  16. } else {
  17. if (Alpine.store('globals').isUnlimitedValue($(elm).val())) {
  18. $(elm).val('0');
  19. }
  20. }
  21. $(elm).attr('disabled', false);
  22. $(source_elm).css('opacity', '0.5');
  23. };
  24. //
  25. App.Actions.MAIL_ACC.toggle_unlimited_feature = function (evt) {
  26. var elm = $(evt.target);
  27. var ref = elm.prev('.form-control');
  28. if (!$(ref).data('checked')) {
  29. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  30. } else {
  31. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  32. }
  33. };
  34. App.Listeners.MAIL_ACC.checkbox_unlimited_feature = function () {
  35. $('.unlim-trigger').on('click', App.Actions.MAIL_ACC.toggle_unlimited_feature);
  36. };
  37. App.Listeners.MAIL_ACC.init = function () {
  38. $('.unlim-trigger').each(function (i, elm) {
  39. var ref = $(elm).prev('.form-control');
  40. if (Alpine.store('globals').isUnlimitedValue($(ref).val())) {
  41. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  42. } else {
  43. $(ref).data('prev_value', $(ref).val());
  44. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  45. }
  46. });
  47. };
  48. App.Listeners.MAIL_ACC.init();
  49. App.Listeners.MAIL_ACC.checkbox_unlimited_feature();
  50. App.Actions.MAIL_ACC.update_password_meter = function () {
  51. var password = $('input[name="v_password"]').val();
  52. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  53. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  54. var min_num = new RegExp(/^(?=.*\d).+$/);
  55. var min_length = 8;
  56. var score = 0;
  57. if (password.length >= min_length) {
  58. score = score + 1;
  59. }
  60. if (min_small.test(password)) {
  61. score = score + 1;
  62. }
  63. if (min_cap.test(password)) {
  64. score = score + 1;
  65. }
  66. if (min_num.test(password)) {
  67. score = score + 1;
  68. }
  69. $('.js-password-meter').val(score);
  70. };
  71. App.Listeners.MAIL_ACC.keypress_v_password = function () {
  72. var ref = $('input[name="v_password"]');
  73. ref.bind('keypress input', function (evt) {
  74. clearTimeout(window.frp_usr_tmt);
  75. window.frp_usr_tmt = setTimeout(function () {
  76. var elm = $(evt.target);
  77. App.Actions.MAIL_ACC.update_password_meter(elm, $(elm).val());
  78. }, 100);
  79. });
  80. };
  81. $('#v_blackhole').on('click', function () {
  82. if ($('#v_blackhole').is(':checked')) {
  83. $('#v_fwd').prop('disabled', true);
  84. $('#v_fwd_for').prop('checked', true);
  85. $('#id_fwd_for').hide();
  86. } else {
  87. $('#v_fwd').prop('disabled', false);
  88. $('#id_fwd_for').show();
  89. }
  90. });
  91. App.Listeners.MAIL_ACC.keypress_v_password();
  92. applyRandomPassword = function (min_length = 16) {
  93. var randomPassword = randomString(min_length);
  94. $('input[name=v_password]').val(randomPassword);
  95. if ($('input[name=v_password]').attr('type') == 'text')
  96. $('.js-password-output').text(randomPassword);
  97. else $('.js-password-output').text(Array(randomPassword.length + 1).join('*'));
  98. App.Actions.MAIL_ACC.update_password_meter();
  99. generate_mail_credentials();
  100. };
  101. generate_mail_credentials = function () {
  102. var div = $('.js-mail-info').clone();
  103. div.find('#mail_configuration').remove();
  104. var pass = div.find('.js-password-output').text();
  105. if (pass == '') div.find('.js-password-output').text(' ');
  106. var output = div.text();
  107. output = output.replace(/(?:\r\n|\r|\n|\t)/g, '|');
  108. output = output.replace(/ {2}/g, '');
  109. output = output.replace(/\|\|/g, '|');
  110. output = output.replace(/\|\|/g, '|');
  111. output = output.replace(/\|\|/g, '|');
  112. output = output.replace(/^\|+/g, '');
  113. output = output.replace(/\|$/, '');
  114. output = output.replace(/ $/, '');
  115. output = output.replace(/:\|/g, ': ');
  116. output = output.replace(/\|/g, '\n');
  117. $('.js-hidden-credentials').val(output);
  118. };
  119. $(document).ready(function () {
  120. $('.js-account-output').text($('input[name=v_account]').val());
  121. $('.js-password-output').text($('input[name=v_password]').val());
  122. generate_mail_credentials();
  123. $('input[name=v_account]').change(function () {
  124. $('.js-account-output').text($(this).val());
  125. generate_mail_credentials();
  126. });
  127. $('input[name=v_password]').change(function () {
  128. if ($('input[name=v_password]').attr('type') == 'text')
  129. $('.js-password-output').text($(this).val());
  130. else $('.js-password-output').text(Array($(this).val().length + 1).join('*'));
  131. generate_mail_credentials();
  132. });
  133. $('.toggle-psw-visibility-icon').click(function () {
  134. if ($('input[name=v_password]').attr('type') == 'text')
  135. $('.js-password-output').text($('input[name=v_password]').val());
  136. else
  137. $('.js-password-output').text(Array($('input[name=v_password]').val().length + 1).join('*'));
  138. generate_mail_credentials();
  139. });
  140. $('#mail_configuration').change(function (evt) {
  141. var opt = $(evt.target).find('option:selected');
  142. switch (opt.attr('v_type')) {
  143. case 'hostname':
  144. $('#td_imap_hostname').text(opt.attr('domain'));
  145. $('#td_smtp_hostname').text(opt.attr('domain'));
  146. break;
  147. case 'starttls':
  148. $('#td_imap_port').text('143');
  149. $('#td_imap_encryption').text('STARTTLS');
  150. $('#td_smtp_port').text('587');
  151. $('#td_smtp_encryption').text('STARTTLS');
  152. break;
  153. case 'ssl':
  154. $('#td_imap_port').text('993');
  155. $('#td_imap_encryption').text('SSL / TLS');
  156. $('#td_smtp_port').text('465');
  157. $('#td_smtp_encryption').text('SSL / TLS');
  158. break;
  159. case 'no_encryption':
  160. $('#td_imap_hostname').text(opt.attr('domain'));
  161. $('#td_smtp_hostname').text(opt.attr('domain'));
  162. $('#td_imap_port').text('143');
  163. $('#td_imap_encryption').text(opt.attr('no_encryption'));
  164. $('#td_smtp_port').text('25');
  165. $('#td_smtp_encryption').text(opt.attr('no_encryption'));
  166. break;
  167. }
  168. generate_mail_credentials();
  169. });
  170. });