From a70e0cf66ad5386b5a13466fb94cb052654044e6 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Wed, 17 Sep 2008 00:58:50 +0000 Subject: [PATCH] Registration form to keep user entries on error - required and errored out fields are now highlighted. --- docs/changelog/7.x.x.txt | 1 + ...ldap_anonymous_registration_template.wgpkg | Bin 0 -> 1673 bytes ...bgui_anonymous_registration_template.wgpkg | Bin 0 -> 1786 bytes lib/WebGUI/Auth.pm | 46 ++++++++++++---- lib/WebGUI/Auth/LDAP.pm | 23 +++++--- lib/WebGUI/Auth/WebGUI.pm | 51 +++++++++++++----- 6 files changed, 92 insertions(+), 29 deletions(-) create mode 100644 docs/upgrades/packages-7.6.0/default_ldap_anonymous_registration_template.wgpkg create mode 100644 docs/upgrades/packages-7.6.0/default_webgui_anonymous_registration_template.wgpkg diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 838d43f84..191008a1d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -68,6 +68,7 @@ - rfe: VIM perl mode for skeletons - rfe: Add edit button to Manage Revisions page - rfe: Protected profile fields don't show delete icon + - rfe: Registration form to keep user entries on error - required and errored fields are now highlighted. 7.5.22 - fixed: Layout template now gets prepared correctly diff --git a/docs/upgrades/packages-7.6.0/default_ldap_anonymous_registration_template.wgpkg b/docs/upgrades/packages-7.6.0/default_ldap_anonymous_registration_template.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..bf891a3c689edd78997ddf4fba853097ad37538e GIT binary patch literal 1673 zcmV;426p)$iwFP!000001MOJtQ`_`Dw`C37cDwomCeowd^ZsJFYmfhUp0~5Ty|!lFjl!GE9&fE$ z^%`|=yIOBl*GRS2@EU6bNFV=6l%^6yi$ltzen|c6a-QGX2j$>FCGlO3@}FBpsjKt9 zwd{ZQN{Q%!qy_Xwz5XTtSF1a<`hx!(-pXkjfK=K=-_UYgdv{FD16B%Z0=9ZQD@63 z?m^~hA+82&K$B2kh5?N)X(XcQSS0FFvLRQ%KywjYYBq+#09q9FqDnEHL7(qypuqf^ z|Jk<4xjL6Z3q6ffW7vvvb6`6nGcZKaGSHr$Ol4>-4VEk$&|0A z{al2ZSQafRpV6jgP=$c_5PWL4=NQN?Q@-S}aY@f16B_bi1Y26fJ!h|62;HGOF5Pl5-L`XqRCX=CuzjgYI$n*)_fY@#|8 zBF;k>V-0H8fX^aqRTpGvu7N%b*_cK8yL?cBQ>IdyPe!NJ65zX|S|$B4*X5#pBXI{p z=q$-iCBSMB@X0J~sqc#<(r1{o3i2wiPDz;m3#BULdu>Wak_{l8=ZPGOA&*=r)O%J! zrptLMQ;-|ZBW?=bu4Lft3W&02RZAX?nB@A643DH3pHm6G#j0wTW9(T6BN`3A(9}X6 zv8_;uhha>&GxY>uA$mAxpsg@EU56Do`DXGS{ zGpf6s+@*;g4LAz}7(hNHT(aO&3K9$v?z8#Az{OK15YrEy^%OBmVRB|WF-l;~A9-mooQ?V9k#VN+>Vnckrn6y1?N8CdrroTUabM(YaM=pD zna6B(45(NEG0WY<3F%TpD8q4Db-+9!x$a-e=OklD{yr)GS z4f&mI)}^2*vx5!$U3SPIRSvIu;aHucuH4#>mvhfoU19z`igqqeXJ7F5H0OO^0Qz zYOTK2+-@`*7IzqBVdluB_4>D)x8n5Yi`VbpC;g-3({CN|_ID?{x4V0C_Yn7jKQMk+ T;D-hN{}%WgtRI3M02}}SeQ`nT literal 0 HcmV?d00001 diff --git a/docs/upgrades/packages-7.6.0/default_webgui_anonymous_registration_template.wgpkg b/docs/upgrades/packages-7.6.0/default_webgui_anonymous_registration_template.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..1c9bc595d888e7bae30821436ab857996bf4797e GIT binary patch literal 1786 zcmV}rV>m`BFf`lM1!kpo!=S<=io9Glc?Xh7lo7M3p}LoCv8|xNAn^G>XiuTq2N+!r!5 zV@AVsI;fmZm0~)ddbX!WNn}c5`r~<)C8>;zmXP&n8tKbx)*Gb!lExyQj6|v~B^z)B zIyD#ZrDlMKZkGeW)tMAp=t+`=!*-RcV;+VqHd<`m11ZwvBs>hc&PII;cd86y-x>Nl z9rWgMOeN7=M{K84gO^>|jqxuVOY{GeiLX00a%55_i1qg{$2|iE^ToE^siaGFXBFj zm0vd0h2c3~rTv)Pkr0WMa?ri{9CAHN@nsh!M{_ar4kI>VvHmXCDsZY?%E}6T%I!xN zp+q5r_i3VoA-yNR%H=DphcWTRUc9w!K>#)D=%&3eEdGFx;XdOwgXv zbKL2dH3Z|G8n)!n1bWwaj;cYTG5v=Bl__e}8#WP1sDv%o7;#Hv+wJ4?7tbq$fSh43 z62X<3-%)x3tN^(Z?()FqYJn=%7jb7DfP9(N1|cZBZs;% zwFw;xu^x)iIvYa`&p*TY5<6Qh!?}~HqS3wEJw82kQ_Umy5TRWWADq5;4Ouc-?Wb{o zOpvTTwq3{84Jmqr%eIdTLbl0Fn6R;4Bck__%uT~CiBrvT;{!|sG1oj#qh=IrfSNIU@(33bS9Q+m0n<5aRC^N>Vcc?7 ztF+H+MqIW8ZoXo+I|wS404fP|zZ@k{ny;k!oJ@@Lboctr|&7+(9 c_(=N$<3|L3MBqmR9v}jL1E=W!?EoGC01FmwiU0rr literal 0 HcmV?d00001 diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index 03324959a..0b8cf4fd6 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -187,8 +187,8 @@ sub createAccount { my $i18n = WebGUI::International->new($self->session); $vars->{title} = $i18n->get(54); - $vars->{'create.form.header'} - = WebGUI::Form::formHeader($self->session,{}) + $vars->{'create.form.header'} + = WebGUI::Form::formHeader($self->session) . WebGUI::Form::hidden($self->session,{"name"=>"op","value"=>"auth"}) . WebGUI::Form::hidden($self->session,{"name"=>"method","value"=>$method}) ; @@ -197,11 +197,18 @@ sub createAccount { my $userInvitation = $self->session->setting->get('userInvitationsEnabled'); $vars->{'create.form.profile'} = []; foreach my $field (@{WebGUI::ProfileField->getRegistrationFields($self->session)}) { - my $id = $field->getId; - my $label = $field->getLabel; + my $id = $field->getId; + my $label = $field->getLabel; + my $required = $field->isRequired; - # Get the default email from the invitation + my $properties = {}; + if ($required) { + my $fieldValue = $self->session->form->process($field->getId,$field->get("fieldType")); + $properties->{extras} = $self->getExtrasStyle($fieldValue); + } + my $formField; + # Get the default email from the invitation if ($field->get('fieldName') eq "email" && $userInvitation ) { my $code = $self->session->form->get('code') || $self->session->form->get('uniqueUserInvitationCode'); @@ -211,12 +218,12 @@ sub createAccount { [$code] ); $vars->{'create.form.header'} .= WebGUI::Form::hidden($self->session, {name=>"uniqueUserInvitationCode", value=>$code}); - $formField = $field->formField(undef, undef, undef, undef, $defaultValue); + $formField = $field->formField($properties, undef, undef, undef, $defaultValue); } else { - $formField = $field->formField(); + $formField = $field->formField($properties); } - my $required = $field->isRequired; + # Old-style field loop. push @{$vars->{'create.form.profile'}}, { @@ -615,7 +622,28 @@ sub getCreateAccountTemplateId { #------------------------------------------------------------------- -=head2 getAccountTemplateId ( ) +=head2 getExtrasStyle ( ) + +This method returns the proper field to display for required fields. + +=cut + +sub getExtrasStyle { + my $self = shift; + my $value = shift; + + my $requiredStyleOff = q{class="authfield_required_off"}; + my $requiredStyle = q{class="authfield_required"}; + my $errorStyle = q{class="authfield_error"}; #Required Field Not Filled In and Error Returend + + return $errorStyle if($self->error && $value eq ""); + return $requiredStyle unless($value); + return $requiredStyleOff; +} + +#------------------------------------------------------------------- + +=head2 getLoginTemplateId ( ) This method should be overridden by the subclass and should return the template ID for the login screen. diff --git a/lib/WebGUI/Auth/LDAP.pm b/lib/WebGUI/Auth/LDAP.pm index 9c77b4cb8..1142d9ad3 100644 --- a/lib/WebGUI/Auth/LDAP.pm +++ b/lib/WebGUI/Auth/LDAP.pm @@ -241,13 +241,24 @@ sub createAccount { value=>[$connection->{ldapLinkId}], extras=>qq|onchange="location.href='$url'+this.options[this.selectedIndex].value"| }); - $vars->{'create.form.ldapId'} = WebGUI::Form::text($self->session,{"name"=>"authLDAP_ldapId","value"=>$self->session->form->process("authLDAP_ldapId")}); - $vars->{'create.form.ldapId.label'} = $connection->{ldapIdentityName}; - $vars->{'create.form.password'} = WebGUI::Form::password($self->session,{"name"=>"authLDAP_identifier","value"=>$self->session->form->process("authLDAP_identifier")}); - $vars->{'create.form.password.label'} = $connection->{ldapPasswordName}; + my $ldapId = $self->session->form->process("authLDAP_ldapId"); + $vars->{'create.form.ldapId'} = WebGUI::Form::text($self->session,{ + name =>"authLDAP_ldapId", + value =>$ldapId, + extras => $self->getExtrasStyle($ldapId) + }); + $vars->{'create.form.ldapId.label'} = $connection->{ldapIdentityName}; + + my $ldapPwd = $self->session->form->process("authLDAP_identifier"); + $vars->{'create.form.password'} = WebGUI::Form::password($self->session,{ + "name"=>"authLDAP_identifier", + "value"=> $ldapPwd, + extras => $self->getExtrasStyle($ldapPwd) + }); + $vars->{'create.form.password.label'} = $connection->{ldapPasswordName}; - $vars->{'create.form.hidden'} = WebGUI::Form::hidden($self->session,{"name"=>"confirm","value"=>$confirm}); - return $self->SUPER::createAccount("createAccountSave",$vars); + $vars->{'create.form.hidden'} = WebGUI::Form::hidden($self->session,{"name"=>"confirm","value"=>$confirm}); + return $self->SUPER::createAccount("createAccountSave",$vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index 0e5ecd025..64c586da1 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -131,43 +131,63 @@ sub authenticate { #------------------------------------------------------------------- sub createAccount { my $self = shift; + my $session = $self->session; + my $form = $session->form; + my $setting = $session->setting; + my $message = shift; - my $confirm = shift || $self->session->form->process("confirm"); - my $vars = shift || {}; + my $confirm = shift || $form->process("confirm"); + my $vars = shift || {}; + my $i18n = WebGUI::International->new($session); - #$self->session->errorHandler->warn('WebGUI::Auth::createAccount called'); if ($self->session->user->isRegistered) { return $self->displayAccount; } - elsif (!$self->session->setting->get("anonymousRegistration") && !$self->session->setting->get('userInvitationsEnabled')) { + elsif (!$setting->get("anonymousRegistration") && !$setting->get('userInvitationsEnabled')) { return $self->displayLogin; } - my $i18n = WebGUI::International->new($self->session); + $vars->{'create.message'} = '
    '.$message.'
' if ($message); - $vars->{useCaptcha} = $self->session->setting->get("webguiUseCaptcha"); + $vars->{'useCaptcha' } = $setting->get("webguiUseCaptcha"); + if ($vars->{useCaptcha}) { use WebGUI::Form::Captcha; - my $captcha = WebGUI::Form::Captcha->new($self->session,{"name"=>"authWebGUI.captcha"}); + my $captcha = WebGUI::Form::Captcha->new($session,{ + name => "authWebGUI.captcha", + extras => $self->getExtrasStyle + }); $vars->{'create.form.captcha'} = $captcha->toHtml . '' . $captcha->get('subtext').''; $vars->{'create.form.captcha.label'} = $i18n->get("captcha label","AuthWebGUI"); } - $vars->{'create.form.username'} + + my $username = $form->process("authWebGUI.username"); + $vars->{'create.form.username'} = WebGUI::Form::text($self->session, { - "name" => "authWebGUI.username", - "value" => $self->session->form->process("authWebGUI.username"), + name => "authWebGUI.username", + value => $username, + extras => $self->getExtrasStyle($username) }); $vars->{'create.form.username.label'} = $i18n->get(50); - $vars->{'create.form.password'} + + my $password = $form->process("authWebGUI.identifier"); + $vars->{'create.form.password'} = WebGUI::Form::password($self->session, { - "name" => "authWebGUI.identifier" + name => "authWebGUI.identifier", + value => $password, + extras => $self->getExtrasStyle($password) }); $vars->{'create.form.password.label'} = $i18n->get(51); + + my $passwordConfirm = $form->process("authWebGUI.identifierConfirm"); $vars->{'create.form.passwordConfirm'} = WebGUI::Form::password($self->session, { - "name" => "authWebGUI.identifierConfirm" + name => "authWebGUI.identifierConfirm", + value => $passwordConfirm, + extras => $self->getExtrasStyle($passwordConfirm) }); $vars->{'create.form.passwordConfirm.label'} = $i18n->get(2,'AuthWebGUI'); + $vars->{'create.form.hidden'} = WebGUI::Form::hidden($self->session, { "name" => "confirm", @@ -211,7 +231,10 @@ sub createAccountSave { my ($profile, $temp, $warning) = WebGUI::Operation::Profile::validateProfileData($self->session, {regOnly => 1}); $error .= $temp; - return $self->createAccount($error) unless ($error eq ""); + unless ($error eq "") { + $self->error($error); + return $self->createAccount($error); + } # If Email address is not unique, a warning is displayed if ($warning ne "" && !$self->session->form->process("confirm")) {