add_mail_acc.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. App.Actions.MAIL_ACC.toggle_unlimited_feature = function(evt) {
  26. var elm = $(evt.target);
  27. var ref = elm.prev('.vst-input');
  28. if (!$(ref).data('checked')) {
  29. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  30. }
  31. else {
  32. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  33. }
  34. }
  35. App.Listeners.MAIL_ACC.checkbox_unlimited_feature = function() {
  36. $('.unlim-trigger').on('click', App.Actions.MAIL_ACC.toggle_unlimited_feature);
  37. }
  38. App.Listeners.MAIL_ACC.init = function() {
  39. $('.unlim-trigger').each(function(i, elm) {
  40. var ref = $(elm).prev('.vst-input');
  41. if (App.Helpers.isUnlimitedValue($(ref).val())) {
  42. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  43. }
  44. else {
  45. $(ref).data('prev_value', $(ref).val());
  46. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  47. }
  48. });
  49. }
  50. App.Helpers.isUnlimitedValue = function(value) {
  51. var value = value.trim();
  52. if (value == App.Constants.UNLIM_VALUE || value == App.Constants.UNLIM_TRANSLATED_VALUE) {
  53. return true;
  54. }
  55. return false;
  56. }
  57. //
  58. // Page entry point
  59. // Trigger listeners
  60. App.Listeners.MAIL_ACC.init();
  61. App.Listeners.MAIL_ACC.checkbox_unlimited_feature();
  62. $('form[name="v_quota"]').on('submit', function(evt) {
  63. $('input:disabled').each(function(i, elm) {
  64. $(elm).attr('disabled', false);
  65. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  66. $(elm).val(App.Constants.UNLIM_VALUE);
  67. }
  68. });
  69. });
  70. App.Actions.MAIL_ACC.update_v_password = function (){
  71. var password = $('input[name="v_password"]').val();
  72. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  73. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  74. var min_num = new RegExp(/^(?=.*\d).+$/);
  75. var min_length = 8;
  76. var score = 0;
  77. if(password.length >= min_length) { score = score + 1; }
  78. if(min_small.test(password)) { score = score + 1;}
  79. if(min_cap.test(password)) { score = score + 1;}
  80. if(min_num.test(password)) { score = score+ 1; }
  81. $('#meter').val(score);
  82. }
  83. App.Listeners.MAIL_ACC.keypress_v_password = function() {
  84. var ref = $('input[name="v_password"]');
  85. ref.bind('keypress input', function(evt) {
  86. clearTimeout(window.frp_usr_tmt);
  87. window.frp_usr_tmt = setTimeout(function() {
  88. var elm = $(evt.target);
  89. App.Actions.MAIL_ACC.update_v_password(elm, $(elm).val());
  90. }, 100);
  91. });
  92. }
  93. App.Listeners.MAIL_ACC.keypress_v_password();
  94. randomString = function(min_length = 16) {
  95. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  96. var string_length = min_length;
  97. var randomstring = '';
  98. for (var i = 0; i < string_length; i++) {
  99. var rnum = Math.floor(Math.random() * chars.length);
  100. randomstring += chars.substr(rnum, 1);
  101. }
  102. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  103. if(!regex.test(randomstring)){
  104. randomString();
  105. }else{
  106. $('input[name=v_password]').val(randomstring);
  107. if($('input[name=v_password]').attr('type') == 'text')
  108. $('#v_password').text(randomstring);
  109. else
  110. $('#v_password').text(Array(randomstring.length+1).join('*'));
  111. App.Actions.MAIL_ACC.update_v_password();
  112. generate_mail_credentials();
  113. }
  114. }
  115. generate_mail_credentials = function() {
  116. var div = $('.mail-infoblock').clone();
  117. div.find('#mail_configuration').remove();
  118. var pass=div.find('#v_password').text();
  119. if (pass=="") div.find('#v_password').html(' ');
  120. var output = div.text();
  121. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  122. output=output.replace(/ /g, "");
  123. output=output.replace(/\|\|/g, "|");
  124. output=output.replace(/\|\|/g, "|");
  125. output=output.replace(/\|\|/g, "|");
  126. output=output.replace(/^\|+/g, "");
  127. output=output.replace(/\|$/, "");
  128. output=output.replace(/ $/, "");
  129. output=output.replace(/:\|/g, ": ");
  130. output=output.replace(/\|/g, "\n");
  131. //console.log(output);
  132. $('#v_credentials').val(output);
  133. }
  134. $(document).ready(function() {
  135. $('#v_account').text($('input[name=v_account]').val());
  136. $('#v_password').text($('input[name=v_password]').val());
  137. generate_mail_credentials();
  138. $('input[name=v_account]').change(function(){
  139. $('#v_account').text($(this).val());
  140. generate_mail_credentials();
  141. });
  142. $('input[name=v_password]').change(function(){
  143. if($('input[name=v_password]').attr('type') == 'text')
  144. $('#v_password').text($(this).val());
  145. else
  146. $('#v_password').text(Array($(this).val().length+1).join('*'));
  147. generate_mail_credentials();
  148. });
  149. $('.toggle-psw-visibility-icon').click(function(){
  150. if($('input[name=v_password]').attr('type') == 'text')
  151. $('#v_password').text($('input[name=v_password]').val());
  152. else
  153. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  154. generate_mail_credentials();
  155. });
  156. $('#mail_configuration').change(function(evt){
  157. var opt = $(evt.target).find('option:selected');
  158. switch(opt.attr('v_type')){
  159. case 'hostname':
  160. $('#td_imap_hostname').html(opt.attr('domain'));
  161. $('#td_smtp_hostname').html(opt.attr('domain'));
  162. break;
  163. case 'starttls':
  164. $('#td_imap_port').html('143');
  165. $('#td_imap_encryption').html('STARTTLS');
  166. $('#td_smtp_port').html('587');
  167. $('#td_smtp_encryption').html('STARTTLS');
  168. break;
  169. case 'ssl':
  170. $('#td_imap_port').html('993');
  171. $('#td_imap_encryption').html('SSL / TLS');
  172. $('#td_smtp_port').html('465');
  173. $('#td_smtp_encryption').html('SSL / TLS');
  174. break;
  175. case 'no_encryption':
  176. $('#td_imap_hostname').html(opt.attr('domain'));
  177. $('#td_smtp_hostname').html(opt.attr('domain'));
  178. $('#td_imap_port').html('143');
  179. $('#td_imap_encryption').html(opt.attr('no_encryption'));
  180. $('#td_smtp_port').html('25');
  181. $('#td_smtp_encryption').html(opt.attr('no_encryption'));
  182. break;
  183. }
  184. generate_mail_credentials();
  185. });
  186. });