aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Script/CreateSuperuser.pm
blob: cbbea577aac8a3de613c32864e73964d7743b351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package FixMyStreet::Script::CreateSuperuser;

use strict;
use warnings;

use FixMyStreet;
use FixMyStreet::DB;

sub createsuperuser {
    my ($email, $password) = @_;

    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 ) {
        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;