From 15e3894b86fe45323edecb028df8a11d8ec8fe3f Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Sat, 14 Jul 2007 00:04:20 +0000 Subject: [PATCH] forward port of bugfix from 7.3.21 --- docs/changelog/7.x.x.txt | 3 ++ lib/WebGUI/Auth.pm | 89 ++++++++++++++++++------------- lib/WebGUI/Auth/WebGUI.pm | 20 +++++-- lib/WebGUI/i18n/English/WebGUI.pm | 5 ++ 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a1f9927d4..cd6693dca 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -72,6 +72,9 @@ - add: Password recovery can now be based on profile fields or simply by the user's e-mail address. +7.3.21 + - fix: Self-deactivation doesn't show login screen after success + 7.3.20 - Added beta label to the beta components in the system, so people can more easily tell which parts of the system are a work in progress. diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index a7213817a..c57881da4 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -337,26 +337,43 @@ sub deactivateAccount { #------------------------------------------------------------------- -=head2 deactivateAccountConfirm ( method ) +=head2 deactivateAccountConfirm ( ) Superclass method that performs general functionality for deactivating accounts. =cut sub deactivateAccountConfirm { - my $self = shift; - return $self->session->privilege->vitalComponent() if($self->userId eq '1' || $self->userId eq '3'); - my $u = $self->user; - $u->status("Selfdestructed"); - $self->session->var->end(); - $self->session->user({userId=>'1'}); + my $self = shift; + + # Cannot deactivate "Visitor" or "Admin" users this way + return $self->session->privilege->vitalComponent + if $self->userId eq '1' || $self->userId eq '3'; + + my $i18n = WebGUI::International->new($self->session); + + # Change user's status + my $user = $self->user; + $user->status("Selfdestructed"); + + # TODO: Fix displayLogin in all subclasses to have the same prototype. THIS WILL BREAK API! + # Show the login form + #$self->logout; + #return $self->displayLogin(undef, { + #'login.message' => sprintf( $i18n->get("deactivateAccount success"), $user->username ) + #}); + + $self->logout; + return undef; } #------------------------------------------------------------------- =head2 deleteParams ( ) -Removes the user's authentication parameters from the database for all authentication methods. This is primarily useful when deleting the user's account. +Removes the user's authentication parameters from the database for all +authentication methods. This is primarily useful when deleting the user's +account. =cut @@ -436,35 +453,35 @@ Array ref of template vars from subclass =cut sub displayLogin { - my $self = shift; - my $method = $_[0] || "login"; - my $vars = $_[1]; - # Automatically set redirectAfterLogin unless we've linked here directly - # or it's already been set to perform another operation - unless ($self->session->form->process("op") eq "auth" - || ($self->session->scratch->get("redirectAfterLogin") =~ /op=\w+/) ) { - $self->session->scratch->set("redirectAfterLogin",$self->session->url->page($self->session->env->get("QUERY_STRING"))); - } + my $self = shift; + my $method = $_[0] || "login"; + my $vars = $_[1]; + # Automatically set redirectAfterLogin unless we've linked here directly + # or it's already been set to perform another operation + unless ($self->session->form->process("op") eq "auth" + || ($self->session->scratch->get("redirectAfterLogin") =~ /op=\w+/) ) { + $self->session->scratch->set("redirectAfterLogin",$self->session->url->page($self->session->env->get("QUERY_STRING"))); + } my $i18n = WebGUI::International->new($self->session); - $vars->{title} = $i18n->get(66); - my $action; - if ($self->session->setting->get("encryptLogin")) { - $action = $self->session->url->page(undef,1); - $action =~ s/http:/https:/; - } - $vars->{'login.form.header'} = WebGUI::Form::formHeader($self->session,{action=>$action}); - $vars->{'login.form.hidden'} = WebGUI::Form::hidden($self->session,{"name"=>"op","value"=>"auth"}); - $vars->{'login.form.hidden'} .= WebGUI::Form::hidden($self->session,{"name"=>"method","value"=>$method}); - $vars->{'login.form.username'} = WebGUI::Form::text($self->session,{"name"=>"username"}); - $vars->{'login.form.username.label'} = $i18n->get(50); - $vars->{'login.form.password'} = WebGUI::Form::password($self->session,{"name"=>"identifier"}); - $vars->{'login.form.password.label'} = $i18n->get(51); - $vars->{'login.form.submit'} = WebGUI::Form::submit($self->session,{"value"=>$i18n->get(52)}); - $vars->{'login.form.footer'} = WebGUI::Form::formFooter($self->session,); - $vars->{'anonymousRegistration.isAllowed'} = ($self->session->setting->get("anonymousRegistration")); - $vars->{'createAccount.url'} = $self->session->url->page('op=auth;method=createAccount'); - $vars->{'createAccount.label'} = $i18n->get(67); - return WebGUI::Asset::Template->new($self->session,$self->getLoginTemplateId)->process($vars); + $vars->{title} = $i18n->get(66); + my $action; + if ($self->session->setting->get("encryptLogin")) { + $action = $self->session->url->page(undef,1); + $action =~ s/http:/https:/; + } + $vars->{'login.form.header'} = WebGUI::Form::formHeader($self->session,{action=>$action}); + $vars->{'login.form.hidden'} = WebGUI::Form::hidden($self->session,{"name"=>"op","value"=>"auth"}); + $vars->{'login.form.hidden'} .= WebGUI::Form::hidden($self->session,{"name"=>"method","value"=>$method}); + $vars->{'login.form.username'} = WebGUI::Form::text($self->session,{"name"=>"username"}); + $vars->{'login.form.username.label'} = $i18n->get(50); + $vars->{'login.form.password'} = WebGUI::Form::password($self->session,{"name"=>"identifier"}); + $vars->{'login.form.password.label'} = $i18n->get(51); + $vars->{'login.form.submit'} = WebGUI::Form::submit($self->session,{"value"=>$i18n->get(52)}); + $vars->{'login.form.footer'} = WebGUI::Form::formFooter($self->session,); + $vars->{'anonymousRegistration.isAllowed'} = ($self->session->setting->get("anonymousRegistration")); + $vars->{'createAccount.url'} = $self->session->url->page('op=auth;method=createAccount'); + $vars->{'createAccount.label'} = $i18n->get(67); + return WebGUI::Asset::Template->new($self->session,$self->getLoginTemplateId)->process($vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index 6a2b770ae..496c4b37f 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -263,9 +263,21 @@ sub deactivateAccount { #------------------------------------------------------------------- sub deactivateAccountConfirm { - my $self = shift; - return $self->displayLogin unless ($self->session->setting->get("selfDeactivation")); - return $self->SUPER::deactivateAccountConfirm; + my $self = shift; + return $self->displayLogin unless ($self->session->setting->get("selfDeactivation")); + + # Keep the username for a nice message + my $username = $self->user->username; + + # Deactivate the account + my $response = $self->SUPER::deactivateAccountConfirm; + + # If there was a response, it's probably an error + return $response if $response; + + # Otherwise show the login form with a friendly message + my $i18n = WebGUI::International->new($self->session); + return $self->displayLogin(sprintf( $i18n->get("deactivateAccount success"), $username )); } #------------------------------------------------------------------- @@ -297,7 +309,7 @@ sub displayAccount { =head2 displayLogin ( ) - The initial login screen an unauthenticated user sees +The initial login screen an unauthenticated user sees =cut diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index abfeba26a..49125cde6 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -4261,6 +4261,11 @@ Get a copy of wget and use this: wget -p -r --html-extension -k http://the message => "Settings saved!", lastUpdated => 0, }, + + 'deactivateAccount success' => { + message => q{%s has been deactivated}, + lastUpdated => 0, + }, };