edit_mail_acc.js 6.9 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('.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 chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  87. var string_length = min_length;
  88. var randomstring = '';
  89. for (var i = 0; i < string_length; i++) {
  90. var rnum = Math.floor(Math.random() * chars.length);
  91. randomstring += chars.substr(rnum, 1);
  92. }
  93. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  94. if(!regex.test(randomstring)){
  95. randomString();
  96. }else{
  97. $('input[name=v_password]').val(randomstring);
  98. if($('input[name=v_password]').attr('type') == 'text')
  99. $('#v_password').text(randomstring);
  100. else
  101. $('#v_password').text(Array(randomstring.length+1).join('*'));
  102. App.Actions.MAIL_ACC.update_v_password();
  103. generate_mail_credentials();
  104. }
  105. }
  106. generate_mail_credentials = function() {
  107. var div = $('.mail-infoblock').clone();
  108. div.find('#mail_configuration').remove();
  109. var pass=div.find('#v_password').text();
  110. if (pass=="") div.find('#v_password').text(' ');
  111. var output = div.text();
  112. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  113. output=output.replace(/ /g, "");
  114. output=output.replace(/\|\|/g, "|");
  115. output=output.replace(/\|\|/g, "|");
  116. output=output.replace(/\|\|/g, "|");
  117. output=output.replace(/^\|+/g, "");
  118. output=output.replace(/\|$/, "");
  119. output=output.replace(/ $/, "");
  120. output=output.replace(/:\|/g, ": ");
  121. output=output.replace(/\|/g, "\n");
  122. //console.log(output);
  123. $('#v_credentials').val(output);
  124. }
  125. $(document).ready(function() {
  126. $('#v_account').text($('input[name=v_account]').val());
  127. $('#v_password').text($('input[name=v_password]').val());
  128. generate_mail_credentials();
  129. $('input[name=v_account]').change(function(){
  130. $('#v_account').text($(this).val());
  131. generate_mail_credentials();
  132. });
  133. $('input[name=v_password]').change(function(){
  134. if($('input[name=v_password]').attr('type') == 'text')
  135. $('#v_password').text($(this).val());
  136. else
  137. $('#v_password').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. $('#v_password').text($('input[name=v_password]').val());
  143. else
  144. $('#v_password').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. });