packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/user-create-form.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/user-create-form.js Tue Jan 08 23:13:29 2013 -0500
@@ -0,0 +1,143 @@
+$(function()
+ {
+ $('table.sort-me').tablesorter({
+ headers: {
+ 4: { sorter: false }
+ }
+ });
+
+ var updateCNAndUsername = function()
+ {
+ $(document.forms.userCreateForm.cn).val(
+ $(document.forms.userCreateForm.givenName).val() + ' ' +
+ $(document.forms.userCreateForm.surname).val()
+ );
+
+ $(document.forms.userCreateForm.uid).val(
+ $(document.forms.userCreateForm.givenName).val().charAt(0).toLowerCase() +
+ $(document.forms.userCreateForm.surname).val().toLowerCase().replace(/[^a-z0-9]/g, '')
+ );
+ };
+
+ $(document.forms.userCreateForm.givenName).blur(updateCNAndUsername);
+ $(document.forms.userCreateForm.surname).blur(updateCNAndUsername);
+ $(document.forms.userCreateForm.uid).blur(function()
+ {
+ var me = this;
+ $.get('/ajax.php?op=checkAvailability&uid=' + $(this).val(), function(response)
+ {
+ if ( typeof(response) == 'string' )
+ {
+ $(me).parents('.control-group').removeClass('success').addClass('error');
+ $('p.help-block', $(me).parent()).text(response);
+ }
+ else
+ {
+ $(me).parents('.control-group').removeClass('error').addClass('success');
+ $('p.help-block', $(me).parent()).text("Username is available");
+ }
+ }, 'json');
+ })
+ .focus(function()
+ {
+ $(this).parents('.control-group').removeClass('error').removeClass('success');
+ $('p.help-block', $(this).parent()).text("All lowercase. Will be used for logging in to the admin/resale portal, e-mail, etc.");
+ });
+
+ var passwordValidate = function()
+ {
+ var status = $('p.compliance-status', $(this).parents('div.controls'));
+ var result = checkPasswordCompliance($(this).val());
+ if ( typeof(result) == 'boolean' && result )
+ {
+ $(this).parents('div.control-group').removeClass('error').addClass('success');
+ $(status).text('Password meets security requirements.');
+ }
+ else if ( typeof(result) == 'string' )
+ {
+ $(this).parents('div.control-group').removeClass('success').addClass('error');
+ $(status).text('Password does not meet security requirements: ' + result + '.');
+ }
+ };
+
+ var passwordConfirmValidate = function()
+ {
+ var status = $('p.compliance-status', $(this).parents('div.controls'));
+ if ( $(this).val() == $('input[name="password"]', $(this).parents('div.modal-body')).val() )
+ {
+ $(this).parents('div.control-group').removeClass('error').addClass('success');
+ $(status).text('Passwords match.');
+ }
+ else
+ {
+ $(this).parents('div.control-group').removeClass('success').addClass('error');
+ $(status).text('Passwords do not match.');
+ }
+ }
+
+ $(document.forms.userCreateForm.password).bind('keyup', passwordValidate);
+ $(document.forms.userCreateForm.password_confirm).bind('keyup', passwordConfirmValidate);
+
+ $(document.forms.userResetForm.password).bind('keyup', passwordValidate);
+ $(document.forms.userResetForm.password_confirm).bind('keyup', passwordConfirmValidate);
+
+ $('form[name="userCreateForm"], form[name="userResetForm"]').bind('submit', function()
+ {
+ if ( $('div.control-group.error', this).length )
+ {
+ $('div.control-group.error:first input:first', this).focus();
+ return false;
+ }
+ });
+
+ $('.show-tooltip').tooltip();
+ });
+
+function checkPasswordCompliance(str)
+{
+ if ( str.length < 8 )
+ return 'must be at least 8 characters in length';
+
+ if ( countUniqueChars(str) < 6 )
+ return 'must have at least 6 unique characters';
+
+ if ( str.length <= 16 )
+ {
+ if ( !(/[a-z]/).test(str) )
+ return 'must contain at least one lowercase letter';
+
+ if ( !(/[A-Z]/).test(str) )
+ return 'must contain at least one uppercase letter';
+
+ if ( !(/[0-9]/).test(str) )
+ return 'must contain at least one digit (0-9)';
+
+ if ( !(/[^A-Za-z0-9]/).test(str) )
+ return 'must contain at least one symbol';
+ }
+
+ return true;
+}
+
+function countUniqueChars(str)
+{
+ var count = 0;
+ var uniq = '';
+ for ( var i = 0; i < str.length; i++ )
+ {
+ if ( uniq.indexOf(str.charAt(i)) == -1 )
+ uniq += str.charAt(i);
+ }
+
+ return uniq.length;
+}
+
+function resetPassword(username)
+{
+ $('#userResetForm input[name="uid"]').val(username);
+ $('#userResetForm').bind('shown', function()
+ {
+ $('input[name="password"]', this).focus();
+ });
+ $('#userResetForm').modal('show');
+}