This is better than direct field access.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Feedback.pl | 3 +-- testbot/web/ForgotPassword.pl | 12 ++---------- testbot/web/Login.pl | 6 ++---- testbot/web/Register.pl | 3 +-- testbot/web/ResetPassword.pl | 24 ++++++++++-------------- 5 files changed, 16 insertions(+), 32 deletions(-)
diff --git a/testbot/web/Feedback.pl b/testbot/web/Feedback.pl index 6185d26d22..23e1944028 100644 --- a/testbot/web/Feedback.pl +++ b/testbot/web/Feedback.pl @@ -86,8 +86,7 @@ sub OnSend($) my $FeedA = $self->GetParam("FeedA"); if ($FeedA !~ /$RegistrationARE/) { - $self->{ErrMessage} = "Wrong 'captcha' answer. Please try again."; - $self->{ErrField} = "Captcha"; + $self->AddError("Wrong 'captcha' answer. Please try again.", "Captcha"); return !1; } } diff --git a/testbot/web/ForgotPassword.pl b/testbot/web/ForgotPassword.pl index 190985264e..ee175d3d44 100644 --- a/testbot/web/ForgotPassword.pl +++ b/testbot/web/ForgotPassword.pl @@ -82,21 +82,13 @@ sub OnResetPassword($) my $Keys = $Users->GetKeys; if (scalar @$Keys == 0) { - $self->{ErrField} = "Name"; - $self->{ErrMessage} = "Unknown username or email address"; + $self->AddError("Unknown username or email address", "Name"); return !1; } $User = $Users->GetItem($Keys->[0]); }
- $self->{ErrMessage} = $User->SendResetCode(); - if (defined($self->{ErrMessage})) - { - $self->{ErrField} = "Name"; - return !1; - } - - return 1; + return $self->AddError($User->SendResetCode(), "Name") ? !1 : 1; }
sub OnAction($$) diff --git a/testbot/web/Login.pl b/testbot/web/Login.pl index 7b9a6ffebf..9380583a06 100644 --- a/testbot/web/Login.pl +++ b/testbot/web/Login.pl @@ -106,8 +106,7 @@ sub OnLogIn($) $self->GetParam("Password")); if ($ErrMessage) { - $self->{ErrMessage} = $ErrMessage; - $self->{ErrField} = "Name"; + $self->AddError($ErrMessage, "Name"); return !1; }
@@ -116,8 +115,7 @@ sub OnLogIn($) defined($self->GetParam("AutoLogin"))); if ($ErrMessage) { - $self->{ErrMessage} = $ErrMessage; - $self->{ErrField} = "Name"; + $self->AddError($ErrMessage, "Name"); return !1; }
diff --git a/testbot/web/Register.pl b/testbot/web/Register.pl index b31dc14c19..667a19b099 100644 --- a/testbot/web/Register.pl +++ b/testbot/web/Register.pl @@ -116,8 +116,7 @@ sub OnSendRequest($) my $RegA = $self->GetParam("RegA"); if ($RegA !~ /$RegistrationARE/) { - $self->{ErrMessage} = "Wrong 'captcha' answer. Please try again."; - $self->{ErrField} = "Captcha"; + $self->AddError("Wrong 'captcha' answer. Please try again.", "Captcha"); return !1; } } diff --git a/testbot/web/ResetPassword.pl b/testbot/web/ResetPassword.pl index 081e27f199..65dcdd539d 100644 --- a/testbot/web/ResetPassword.pl +++ b/testbot/web/ResetPassword.pl @@ -85,8 +85,7 @@ sub Validate($)
if ($self->GetParam("Password1") ne $self->GetParam("Password2")) { - $self->{ErrField} = "Password1"; - $self->{ErrMessage} = "Passwords don't match"; + $self->AddError("Passwords don't match", "Password1"); return !1; }
@@ -108,24 +107,22 @@ sub OnChangePassword($) my $User = $Users->GetItem($self->GetParam("Name")); if (! defined($User)) { - $self->{ErrField} = "Name"; - $self->{ErrMessage} = "Unknown username or incorrect activation code"; + $self->AddError("Unknown username or incorrect activation code", "Name"); return !1; } - $self->{ErrMessage} = $User->ResetPassword($self->GetParam("ResetCode"), - $self->GetParam("Password1")); - if (defined($self->{ErrMessage})) + my $ErrMessage = $User->ResetPassword($self->GetParam("ResetCode"), + $self->GetParam("Password1")); + if (defined $ErrMessage) { - $self->{ErrField} = "Name"; + $self->AddError($ErrMessage, "Name"); return !1; }
- my ($ErrMessage, $User) = $Users->Authenticate($self->GetParam("Name"), + ($ErrMessage, my $User) = $Users->Authenticate($self->GetParam("Name"), $self->GetParam("Password1")); - if ($ErrMessage) + if (defined $ErrMessage) { - $self->{ErrMessage} = $ErrMessage; - $self->{ErrField} = "Name"; + $self->AddError($ErrMessage, "Name"); return !1; }
@@ -134,8 +131,7 @@ sub OnChangePassword($) defined($self->GetParam("AutoLogin"))); if ($ErrMessage) { - $self->{ErrMessage} = $ErrMessage; - $self->{ErrField} = "Name"; + $self->AddError($ErrMessage, "Name"); return !1; }