]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1642654 - Add ability for users to reactivate their own account when disabled...
authordklawren <dklawren@users.noreply.github.com>
Wed, 3 Jun 2020 14:57:51 +0000 (10:57 -0400)
committerGitHub <noreply@github.com>
Wed, 3 Jun 2020 14:57:51 +0000 (10:57 -0400)
Bugzilla/User.pm
scripts/bug_1642654.pl [new file with mode: 0755]
token.cgi

index 911c39164d7392f173dbed9c93bce574956a7aaa..d3d989057c4ea3aa9499da16e6537a34bd013355 100644 (file)
@@ -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 (executable)
index 0000000..9377546
--- /dev/null
@@ -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
+<a href="/login">login page</a>.
+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 <ctrl-c> to abort, or <enter> 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();
+}
index 651718085379f94862636905ea1a49be1f67139f..3dabf959bf8806935937a5308e7ad1d77d18f1c5 100755 (executable)
--- 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})});
   }