aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Script/CreateSuperuser.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-02-27 07:39:46 +0000
committerMatthew Somerville <matthew@mysociety.org>2020-02-27 07:39:46 +0000
commitb0b6810e372a154b1af7da72c1bd2143e5e251e9 (patch)
tree1ebbc91b59f8822e483e51f1f486c347718b0e65 /perllib/FixMyStreet/Script/CreateSuperuser.pm
parent152f8f4e608abc5029104e652f4ef37d4cfe02cb (diff)
parent18adbe946c1104338e6abff159b4f9877154969c (diff)
Merge branch 'admin-only-categories'
Diffstat (limited to 'perllib/FixMyStreet/Script/CreateSuperuser.pm')
-rw-r--r--perllib/FixMyStreet/Script/CreateSuperuser.pm20
1 files changed, 14 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Script/CreateSuperuser.pm b/perllib/FixMyStreet/Script/CreateSuperuser.pm
index 69d165abb..cbbea577a 100644
--- a/perllib/FixMyStreet/Script/CreateSuperuser.pm
+++ b/perllib/FixMyStreet/Script/CreateSuperuser.pm
@@ -7,19 +7,27 @@ use FixMyStreet;
use FixMyStreet::DB;
sub createsuperuser {
- die "Specify a single email address and optionally password to create a superuser or grant superuser status to." if (@ARGV < 1 || @ARGV > 2);
+ my ($email, $password) = @_;
- my $user = FixMyStreet::DB->resultset('User')->find_or_new({ email => $ARGV[0] });
+ unless ($email) {
+ warn "Specify a single email address and optionally password to create a superuser or grant superuser status to.\n";
+ return 1;
+ }
+
+ my $user = FixMyStreet::DB->resultset('User')->find_or_new({ email => $email });
if ( !$user->in_storage ) {
- die "Specify a password for this new user." if (@ARGV < 2);
- $user->password($ARGV[1]);
+ unless ($password) {
+ warn "Specify a password for this new user.\n";
+ return 1;
+ }
+ $user->password($password);
$user->is_superuser(1);
$user->insert;
} else {
$user->update({ is_superuser => 1 });
}
print $user->email . " is now a superuser.\n";
+ return 0;
}
-
-1; \ No newline at end of file
+1;