edit_mail_acc.js 6.8 KB

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