add_mail_acc.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. $('#v_blackhole').on('click', function(evt){
  63. if($('#v_blackhole').is(':checked')){
  64. $('#v_fwd').prop('disabled', true);
  65. $('#v_fwd_for').prop('checked', true);
  66. $('#id_fwd_for').hide();
  67. }else{
  68. $('#v_fwd').prop('disabled', false);
  69. $('#id_fwd_for').show();
  70. }
  71. });
  72. $('form[name="v_quota"]').on('submit', function(evt) {
  73. $('input:disabled').each(function(i, elm) {
  74. $(elm).attr('disabled', false);
  75. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  76. $(elm).val(App.Constants.UNLIM_VALUE);
  77. }
  78. });
  79. });
  80. App.Actions.MAIL_ACC.update_v_password = function (){
  81. var password = $('input[name="v_password"]').val();
  82. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  83. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  84. var min_num = new RegExp(/^(?=.*\d).+$/);
  85. var min_length = 8;
  86. var score = 0;
  87. if(password.length >= min_length) { score = score + 1; }
  88. if(min_small.test(password)) { score = score + 1;}
  89. if(min_cap.test(password)) { score = score + 1;}
  90. if(min_num.test(password)) { score = score+ 1; }
  91. $('#meter').val(score);
  92. }
  93. App.Listeners.MAIL_ACC.keypress_v_password = function() {
  94. var ref = $('input[name="v_password"]');
  95. ref.bind('keypress input', function(evt) {
  96. clearTimeout(window.frp_usr_tmt);
  97. window.frp_usr_tmt = setTimeout(function() {
  98. var elm = $(evt.target);
  99. App.Actions.MAIL_ACC.update_v_password(elm, $(elm).val());
  100. }, 100);
  101. });
  102. }
  103. App.Listeners.MAIL_ACC.keypress_v_password();
  104. randomString = function(min_length = 16) {
  105. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  106. var string_length = min_length;
  107. var randomstring = '';
  108. for (var i = 0; i < string_length; i++) {
  109. var rnum = Math.floor(Math.random() * chars.length);
  110. randomstring += chars.substr(rnum, 1);
  111. }
  112. var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
  113. if(!regex.test(randomstring)){
  114. randomString();
  115. }else{
  116. $('input[name=v_password]').val(randomstring);
  117. if($('input[name=v_password]').attr('type') == 'text')
  118. $('#v_password').text(randomstring);
  119. else
  120. $('#v_password').text(Array(randomstring.length+1).join('*'));
  121. App.Actions.MAIL_ACC.update_v_password();
  122. generate_mail_credentials();
  123. }
  124. }
  125. generate_mail_credentials = function() {
  126. var div = $('.mail-infoblock').clone();
  127. div.find('#mail_configuration').remove();
  128. var pass=div.find('#v_password').text();
  129. if (pass=="") div.find('#v_password').html(' ');
  130. var output = div.text();
  131. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  132. output=output.replace(/ /g, "");
  133. output=output.replace(/\|\|/g, "|");
  134. output=output.replace(/\|\|/g, "|");
  135. output=output.replace(/\|\|/g, "|");
  136. output=output.replace(/^\|+/g, "");
  137. output=output.replace(/\|$/, "");
  138. output=output.replace(/ $/, "");
  139. output=output.replace(/:\|/g, ": ");
  140. output=output.replace(/\|/g, "\n");
  141. //console.log(output);
  142. $('#v_credentials').val(output);
  143. }
  144. $(document).ready(function() {
  145. $('#v_account').text($('input[name=v_account]').val());
  146. $('#v_password').text($('input[name=v_password]').val());
  147. generate_mail_credentials();
  148. $('input[name=v_account]').change(function(){
  149. $('#v_account').text($(this).val());
  150. generate_mail_credentials();
  151. });
  152. $('input[name=v_password]').change(function(){
  153. if($('input[name=v_password]').attr('type') == 'text')
  154. $('#v_password').text($(this).val());
  155. else
  156. $('#v_password').text(Array($(this).val().length+1).join('*'));
  157. generate_mail_credentials();
  158. });
  159. $('.toggle-psw-visibility-icon').click(function(){
  160. if($('input[name=v_password]').attr('type') == 'text')
  161. $('#v_password').text($('input[name=v_password]').val());
  162. else
  163. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  164. generate_mail_credentials();
  165. });
  166. $('#mail_configuration').change(function(evt){
  167. var opt = $(evt.target).find('option:selected');
  168. switch(opt.attr('v_type')){
  169. case 'hostname':
  170. $('#td_imap_hostname').html(opt.attr('domain'));
  171. $('#td_smtp_hostname').html(opt.attr('domain'));
  172. break;
  173. case 'starttls':
  174. $('#td_imap_port').html('143');
  175. $('#td_imap_encryption').html('STARTTLS');
  176. $('#td_smtp_port').html('587');
  177. $('#td_smtp_encryption').html('STARTTLS');
  178. break;
  179. case 'ssl':
  180. $('#td_imap_port').html('993');
  181. $('#td_imap_encryption').html('SSL / TLS');
  182. $('#td_smtp_port').html('465');
  183. $('#td_smtp_encryption').html('SSL / TLS');
  184. break;
  185. case 'no_encryption':
  186. $('#td_imap_hostname').html(opt.attr('domain'));
  187. $('#td_smtp_hostname').html(opt.attr('domain'));
  188. $('#td_imap_port').html('143');
  189. $('#td_imap_encryption').html(opt.attr('no_encryption'));
  190. $('#td_smtp_port').html('25');
  191. $('#td_smtp_encryption').html(opt.attr('no_encryption'));
  192. break;
  193. }
  194. generate_mail_credentials();
  195. });
  196. });