edit_mail_acc.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. } else {
  17. if (App.Helpers.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 (App.Helpers.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.Helpers.isUnlimitedValue = function (value) {
  49. var value = value.trim();
  50. if (value == App.Constants.UNLIM_VALUE || value == App.Constants.UNLIM_TRANSLATED_VALUE) {
  51. return true;
  52. }
  53. return false;
  54. };
  55. App.Listeners.MAIL_ACC.init();
  56. App.Listeners.MAIL_ACC.checkbox_unlimited_feature();
  57. App.Actions.MAIL_ACC.update_password_meter = function () {
  58. var password = $('input[name="v_password"]').val();
  59. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  60. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  61. var min_num = new RegExp(/^(?=.*\d).+$/);
  62. var min_length = 8;
  63. var score = 0;
  64. if (password.length >= min_length) {
  65. score = score + 1;
  66. }
  67. if (min_small.test(password)) {
  68. score = score + 1;
  69. }
  70. if (min_cap.test(password)) {
  71. score = score + 1;
  72. }
  73. if (min_num.test(password)) {
  74. score = score + 1;
  75. }
  76. $('.password-meter').val(score);
  77. };
  78. App.Listeners.MAIL_ACC.keypress_v_password = function () {
  79. var ref = $('input[name="v_password"]');
  80. ref.bind('keypress input', function (evt) {
  81. clearTimeout(window.frp_usr_tmt);
  82. window.frp_usr_tmt = setTimeout(function () {
  83. var elm = $(evt.target);
  84. App.Actions.MAIL_ACC.update_password_meter(elm, $(elm).val());
  85. }, 100);
  86. });
  87. };
  88. $('#v_blackhole').on('click', function (evt) {
  89. if ($('#v_blackhole').is(':checked')) {
  90. $('#v_fwd').prop('disabled', true);
  91. $('#v_fwd_for').prop('checked', true);
  92. $('#id_fwd_for').hide();
  93. } else {
  94. $('#v_fwd').prop('disabled', false);
  95. $('#id_fwd_for').show();
  96. }
  97. });
  98. App.Listeners.MAIL_ACC.keypress_v_password();
  99. applyRandomString = function (min_length = 16) {
  100. var randomString = randomString2(min_length);
  101. $('input[name=v_password]').val(randomString);
  102. if ($('input[name=v_password]').attr('type') == 'text')
  103. $('.js-password-output').text(randomString);
  104. else $('.js-password-output').text(Array(randomString.length + 1).join('*'));
  105. App.Actions.MAIL_ACC.update_password_meter();
  106. generate_mail_credentials();
  107. };
  108. generate_mail_credentials = function () {
  109. var div = $('.mail-infoblock').clone();
  110. div.find('#mail_configuration').remove();
  111. var pass = div.find('.js-password-output').text();
  112. if (pass == '') div.find('.js-password-output').text(' ');
  113. var output = div.text();
  114. output = output.replace(/(?:\r\n|\r|\n|\t)/g, '|');
  115. output = output.replace(/ {2}/g, '');
  116. output = output.replace(/\|\|/g, '|');
  117. output = output.replace(/\|\|/g, '|');
  118. output = output.replace(/\|\|/g, '|');
  119. output = output.replace(/^\|+/g, '');
  120. output = output.replace(/\|$/, '');
  121. output = output.replace(/ $/, '');
  122. output = output.replace(/:\|/g, ': ');
  123. output = output.replace(/\|/g, '\n');
  124. $('.js-hidden-credentials').val(output);
  125. };
  126. $(document).ready(function () {
  127. $('.js-account-output').text($('input[name=v_account]').val());
  128. $('.js-password-output').text($('input[name=v_password]').val());
  129. generate_mail_credentials();
  130. $('input[name=v_account]').change(function () {
  131. $('.js-account-output').text($(this).val());
  132. generate_mail_credentials();
  133. });
  134. $('input[name=v_password]').change(function () {
  135. if ($('input[name=v_password]').attr('type') == 'text')
  136. $('.js-password-output').text($(this).val());
  137. else $('.js-password-output').text(Array($(this).val().length + 1).join('*'));
  138. generate_mail_credentials();
  139. });
  140. $('.toggle-psw-visibility-icon').click(function () {
  141. if ($('input[name=v_password]').attr('type') == 'text')
  142. $('.js-password-output').text($('input[name=v_password]').val());
  143. else
  144. $('.js-password-output').text(Array($('input[name=v_password]').val().length + 1).join('*'));
  145. generate_mail_credentials();
  146. });
  147. $('#mail_configuration').change(function (evt) {
  148. var opt = $(evt.target).find('option:selected');
  149. switch (opt.attr('v_type')) {
  150. case 'hostname':
  151. $('#td_imap_hostname').text(opt.attr('domain'));
  152. $('#td_smtp_hostname').text(opt.attr('domain'));
  153. break;
  154. case 'starttls':
  155. $('#td_imap_port').text('143');
  156. $('#td_imap_encryption').text('STARTTLS');
  157. $('#td_smtp_port').text('587');
  158. $('#td_smtp_encryption').text('STARTTLS');
  159. break;
  160. case 'ssl':
  161. $('#td_imap_port').text('993');
  162. $('#td_imap_encryption').text('SSL / TLS');
  163. $('#td_smtp_port').text('465');
  164. $('#td_smtp_encryption').text('SSL / TLS');
  165. break;
  166. case 'no_encryption':
  167. $('#td_imap_hostname').text(opt.attr('domain'));
  168. $('#td_smtp_hostname').text(opt.attr('domain'));
  169. $('#td_imap_port').text('143');
  170. $('#td_imap_encryption').text(opt.attr('no_encryption'));
  171. $('#td_smtp_port').text('25');
  172. $('#td_smtp_encryption').text(opt.attr('no_encryption'));
  173. break;
  174. }
  175. generate_mail_credentials();
  176. });
  177. });