Added commands for creating and promoting accounts

This commit is contained in:
swagg boi 2023-04-22 00:48:30 -04:00
parent 28c914565f
commit 25e370bba5
3 changed files with 55 additions and 0 deletions

View file

@ -6,6 +6,8 @@ has description => 'Hash a string with Argon2';
has usage => sub ($self) { $self->extract_usage };
sub run($self, @args) {
die $self->usage unless $args[0];
say $self->app->authenticator->hash_password($_) for @args
}

View file

@ -0,0 +1,31 @@
package PostText::Command::create;
use Mojo::Base 'Mojolicious::Command', -signatures;
use Mojo::Util qw{getopt};
has description => 'Create a moderator account';
has usage => sub ($self) { $self->extract_usage };
sub run($self, @args) {
die $self->usage unless $args[0];
getopt \@args,
'n|name=s' => \my $name,
'e|email=s' => \my $email,
'p|password=s' => \my $password;
say 'Moderator created successfully.'
if $self->app->moderator->create($name, $email, $password);
}
1;
=head1 SYNOPSIS
Usage: APPLICATION create OPTIONS
Options:
-n, --name Moderator's name
-e, --email Moderator's email
-p, --password Moderator's password
=cut

View file

@ -0,0 +1,22 @@
package PostText::Command::promote;
use Mojo::Base 'Mojolicious::Command', -signatures;
has description => 'Promote a moderator account to admin';
has usage => sub ($self) { $self->extract_usage };
sub run($self, @args) {
die $self->usage unless $args[0];
for my $email (@args) {
say "Promoted $email." if $self->app->moderator->promote($email)
}
}
1;
=head1 SYNOPSIS
Usage: APPLICATION EMAIL(S)
=cut