diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index d6bac0c22..75a49ec96 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -338,20 +338,6 @@ or an empty string if the check was successful. =cut -sub checkField { - my $self = shift; - my $session = $self->session; - $session->http->setMimeType( 'application/json' ); - - my $input = $session->form->param('input'); - my $fieldName = $session->form->param('fieldName'); - my $fieldType = $session->form->param('fieldType'); - - my $checkClass = 'WebGUI::Form::'. ucfirst $fieldType; - my (%checkResults) = "$checkClass"->check($session, $input); - return JSON::encode_json(\%checkResults); -} - #------------------------------------------------------------------- sub displayAccount { my $self = shift; @@ -800,7 +786,7 @@ sub new { my $session = shift; my $authMethod = $_[0]; my $userId = $_[1]; - my @callable = ('validateEmail','createAccount','deactivateAccount','displayAccount','displayLogin','login','logout','recoverPassword','resetExpiredPassword','recoverPasswordFinish','createAccountSave','deactivateAccountConfirm','resetExpiredPasswordSave','updateAccount', 'emailResetPassword', 'emailResetPasswordFinish','checkField'); + my @callable = ('validateEmail','createAccount','deactivateAccount','displayAccount','displayLogin','login','logout','recoverPassword','resetExpiredPassword','recoverPasswordFinish','createAccountSave','deactivateAccountConfirm','resetExpiredPasswordSave','updateAccount', 'emailResetPassword', 'emailResetPasswordFinish'); my $self = WebGUI::Auth->new($session,$authMethod,$userId,\@callable); bless $self, $class; } diff --git a/lib/WebGUI/Form/Username.pm b/lib/WebGUI/Form/Username.pm index d423df332..c1d6509f4 100644 --- a/lib/WebGUI/Form/Username.pm +++ b/lib/WebGUI/Form/Username.pm @@ -92,15 +92,15 @@ sub toHtml { $self->session->style->setScript($self->session->url->extras('yui/build/datasource/datasource-min.js'), {type=>'text/javascript'}); $self->session->style->setScript($self->session->url->extras('yui-webgui/build/i18n/i18n.js'), {type=>'text/javascript'}); my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters(scalar $self->getOriginalValue))); - $self->set("extras", $self->get('extras') . ' onblur="new WebGUI.FieldCheck(\''. $self->get("id").'\',\'username\',1);"'); + $self->set("extras", $self->get('extras') . ' onblur="new WebGUI.FieldCheck(\''. $self->get("id").'\',\'Username\',1);"'); return 'get("extras").' />'; } #------------------------------------------------------------------- -=head2 check ( $session, $input ) +=head2 www_check ($session) -check() is called as a class method. +www_check() is called by an Ajax call from the user registration page. It checks whether a user name is free for registration. Returns a hash (error => $error) @@ -108,16 +108,19 @@ if the username is not free. =cut -sub check { - my ($class, $session, $input) = @_; +sub www_check { + my $session = shift; + my $input = $session->form->param('input'); + + $session->http->setMimeType( 'application/json' ); my $i18n = WebGUI::International->new($session, 'Form_Username'); my $error = ''; my ($existingUserId) = $session->db->quickArray("select userId from users where username=".$session->db->quote($input)); $error = $i18n->get('username in use') if $existingUserId; - my %checkInfo = (error => $error); - return %checkInfo; + my %checkResults = (error => $error); + return JSON::encode_json(\%checkResults); } 1; diff --git a/www/extras/form/fieldCheck.js b/www/extras/form/fieldCheck.js index db18c3778..4b8414511 100644 --- a/www/extras/form/fieldCheck.js +++ b/www/extras/form/fieldCheck.js @@ -30,7 +30,6 @@ WebGUI.FieldCheck.prototype.initialize = function() { var fieldType=this.fieldType; var required=this.required; var field=document.getElementById(fieldId); - var fieldName=field.name; var input=field.value; var myAjaxEvent = new WebGUI.FieldCheck.AjaxEvent(); @@ -44,7 +43,7 @@ WebGUI.FieldCheck.prototype.initialize = function() { return false; } - myAjaxEvent.connect(fieldId,'/?op=auth;method=checkField;fieldName='+fieldName+';fieldType='+fieldType+';input='+input); + myAjaxEvent.connect(fieldId,'/?op=formHelper;sub=check;class='+fieldType+';input='+input); } WebGUI.FieldCheck.AjaxEvent = function() {