|
1 $(function() |
|
2 { |
|
3 $('table.sort-me').tablesorter({ |
|
4 headers: { |
|
5 4: { sorter: false } |
|
6 } |
|
7 }); |
|
8 |
|
9 var updateCNAndUsername = function() |
|
10 { |
|
11 $(document.forms.userCreateForm.cn).val( |
|
12 $(document.forms.userCreateForm.givenName).val() + ' ' + |
|
13 $(document.forms.userCreateForm.surname).val() |
|
14 ); |
|
15 |
|
16 $(document.forms.userCreateForm.uid).val( |
|
17 $(document.forms.userCreateForm.givenName).val().charAt(0).toLowerCase() + |
|
18 $(document.forms.userCreateForm.surname).val().toLowerCase().replace(/[^a-z0-9]/g, '') |
|
19 ); |
|
20 }; |
|
21 |
|
22 $(document.forms.userCreateForm.givenName).blur(updateCNAndUsername); |
|
23 $(document.forms.userCreateForm.surname).blur(updateCNAndUsername); |
|
24 $(document.forms.userCreateForm.uid).blur(function() |
|
25 { |
|
26 var me = this; |
|
27 $.get('/ajax.php?op=checkAvailability&uid=' + $(this).val(), function(response) |
|
28 { |
|
29 if ( typeof(response) == 'string' ) |
|
30 { |
|
31 $(me).parents('.control-group').removeClass('success').addClass('error'); |
|
32 $('p.help-block', $(me).parent()).text(response); |
|
33 } |
|
34 else |
|
35 { |
|
36 $(me).parents('.control-group').removeClass('error').addClass('success'); |
|
37 $('p.help-block', $(me).parent()).text("Username is available"); |
|
38 } |
|
39 }, 'json'); |
|
40 }) |
|
41 .focus(function() |
|
42 { |
|
43 $(this).parents('.control-group').removeClass('error').removeClass('success'); |
|
44 $('p.help-block', $(this).parent()).text("All lowercase. Will be used for logging in to the admin/resale portal, e-mail, etc."); |
|
45 }); |
|
46 |
|
47 var passwordValidate = function() |
|
48 { |
|
49 var status = $('p.compliance-status', $(this).parents('div.controls')); |
|
50 var result = checkPasswordCompliance($(this).val()); |
|
51 if ( typeof(result) == 'boolean' && result ) |
|
52 { |
|
53 $(this).parents('div.control-group').removeClass('error').addClass('success'); |
|
54 $(status).text('Password meets security requirements.'); |
|
55 } |
|
56 else if ( typeof(result) == 'string' ) |
|
57 { |
|
58 $(this).parents('div.control-group').removeClass('success').addClass('error'); |
|
59 $(status).text('Password does not meet security requirements: ' + result + '.'); |
|
60 } |
|
61 }; |
|
62 |
|
63 var passwordConfirmValidate = function() |
|
64 { |
|
65 var status = $('p.compliance-status', $(this).parents('div.controls')); |
|
66 if ( $(this).val() == $('input[name="password"]', $(this).parents('div.modal-body')).val() ) |
|
67 { |
|
68 $(this).parents('div.control-group').removeClass('error').addClass('success'); |
|
69 $(status).text('Passwords match.'); |
|
70 } |
|
71 else |
|
72 { |
|
73 $(this).parents('div.control-group').removeClass('success').addClass('error'); |
|
74 $(status).text('Passwords do not match.'); |
|
75 } |
|
76 } |
|
77 |
|
78 $(document.forms.userCreateForm.password).bind('keyup', passwordValidate); |
|
79 $(document.forms.userCreateForm.password_confirm).bind('keyup', passwordConfirmValidate); |
|
80 |
|
81 $(document.forms.userResetForm.password).bind('keyup', passwordValidate); |
|
82 $(document.forms.userResetForm.password_confirm).bind('keyup', passwordConfirmValidate); |
|
83 |
|
84 $('form[name="userCreateForm"], form[name="userResetForm"]').bind('submit', function() |
|
85 { |
|
86 if ( $('div.control-group.error', this).length ) |
|
87 { |
|
88 $('div.control-group.error:first input:first', this).focus(); |
|
89 return false; |
|
90 } |
|
91 }); |
|
92 |
|
93 $('.show-tooltip').tooltip(); |
|
94 }); |
|
95 |
|
96 function checkPasswordCompliance(str) |
|
97 { |
|
98 if ( str.length < 8 ) |
|
99 return 'must be at least 8 characters in length'; |
|
100 |
|
101 if ( countUniqueChars(str) < 6 ) |
|
102 return 'must have at least 6 unique characters'; |
|
103 |
|
104 if ( str.length <= 16 ) |
|
105 { |
|
106 if ( !(/[a-z]/).test(str) ) |
|
107 return 'must contain at least one lowercase letter'; |
|
108 |
|
109 if ( !(/[A-Z]/).test(str) ) |
|
110 return 'must contain at least one uppercase letter'; |
|
111 |
|
112 if ( !(/[0-9]/).test(str) ) |
|
113 return 'must contain at least one digit (0-9)'; |
|
114 |
|
115 if ( !(/[^A-Za-z0-9]/).test(str) ) |
|
116 return 'must contain at least one symbol'; |
|
117 } |
|
118 |
|
119 return true; |
|
120 } |
|
121 |
|
122 function countUniqueChars(str) |
|
123 { |
|
124 var count = 0; |
|
125 var uniq = ''; |
|
126 for ( var i = 0; i < str.length; i++ ) |
|
127 { |
|
128 if ( uniq.indexOf(str.charAt(i)) == -1 ) |
|
129 uniq += str.charAt(i); |
|
130 } |
|
131 |
|
132 return uniq.length; |
|
133 } |
|
134 |
|
135 function resetPassword(username) |
|
136 { |
|
137 $('#userResetForm input[name="uid"]').val(username); |
|
138 $('#userResetForm').bind('shown', function() |
|
139 { |
|
140 $('input[name="password"]', this).focus(); |
|
141 }); |
|
142 $('#userResetForm').modal('show'); |
|
143 } |