From: dklawren Date: Wed, 3 Jun 2020 14:57:51 +0000 (-0400) Subject: Bug 1642654 - Add ability for users to reactivate their own account when disabled... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c02efc61ba6860fff775c1eff9295d0184bfbbb;p=thirdparty%2Fbugzilla.git Bug 1642654 - Add ability for users to reactivate their own account when disabled from inactivity --- diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 911c39164..d3d989057 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -536,9 +536,15 @@ sub set_nick { sub set_password { my ($self, $password) = @_; + # Reactivate account if user was disabled due to inactivity + if ($self->password_change_reason eq 'Inactive Account') { + $self->set_disabledtext(''); + $self->set_disable_mail(0); + } $self->set('cryptpassword', $password); $self->set('password_change_required', 0); $self->set('password_change_reason', ''); + } sub set_disabledtext { diff --git a/scripts/bug_1642654.pl b/scripts/bug_1642654.pl new file mode 100755 index 000000000..937754654 --- /dev/null +++ b/scripts/bug_1642654.pl @@ -0,0 +1,68 @@ +#!/usr/bin/env perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +# This script disables users who have not logged into BMO within the last four +# years. + +use 5.10.1; +use strict; +use warnings; + +use File::Basename qw(dirname); +use File::Spec::Functions qw(catdir rel2abs); + +BEGIN { + require lib; + my $dir = rel2abs(catdir(dirname(__FILE__), '..')); + lib->import($dir, catdir($dir, 'lib'), catdir($dir, qw(local lib perl5))); +} + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Install::Util qw(indicate_progress); +use Bugzilla::User; +use Bugzilla::Util; + +use constant NEW_DISABLE_MESSAGE => <<'EOF'; +Your account has been disabled because you have not logged on to +bugzilla.mozilla.org in a long time. You can reactivate your account +by submitting a request to reset your password from the +login page. +EOF + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $sql = <<'EOF'; +SELECT + profiles.userid +FROM + profiles +WHERE + profiles.disabledtext like '%Your account has been disabled because you have not logged on to%bugzilla.mozilla.org recently%' +ORDER BY + profiles.userid +EOF + +say STDERR 'looking for users previous disabled as inactive'; +my $userids = Bugzilla->dbh->selectcol_arrayref($sql); +my $total = scalar @{$userids}; +die "no matching users found.\n" unless $total; + +say STDERR "found $total previously disabled inactive user" . ($total == 1 ? '' : 's'); +say STDERR 'press to abort, or to start'; +getc; + +my $count = 0; +foreach my $userid (@{$userids}) { + indicate_progress({total => $total, current => ++$count}); + my $user = Bugzilla::User->new($userid); + $user->set_disabledtext(NEW_DISABLE_MESSAGE); + $user->set_password_change_required(1); + $user->set_password_change_reason('Inactive Account'); + $user->update(); +} diff --git a/token.cgi b/token.cgi index 651718085..3dabf959b 100755 --- a/token.cgi +++ b/token.cgi @@ -106,8 +106,8 @@ if ($action eq 'reqpw') { $user_account = Bugzilla::User->check($login_name); - # Make sure the user account is active. - if (!$user_account->is_enabled) { + # Make sure the user account is active or was deactivated due to inactivity + if (!$user_account->is_enabled && $user_account->password_change_reason ne 'Inactive Account') { ThrowUserError('account_disabled', {disabled_reason => get_text('account_disabled', {account => $login_name})}); }