bin/reset-password
#!/usr/bin/env perl
# ===================================================================
# File: bin/reset-password
# Project: ShinyCMS
# Purpose: Command-line tool to reset user passwords
#
# Author: Denny de la Haye <2019@denny.me>
# Copyright (c) 2009-2019 Denny de la Haye
#
# ShinyCMS is free software; you can redistribute it and/or modify it
# under the terms of either the GPL 2.0 or the Artistic License 2.0
# ===================================================================
package ShinyCMS::ResetPassword;
use Moose;
with 'MooseX::Getopt';
has 'username' => ( is => 'ro', isa => 'Str', required => 1,
# cmd_aliases => [ 'user', 'u' ],
);
has 'password' => ( is => 'ro', isa => 'Str', required => 1,
# cmd_aliases => [ 'pass', 'p' ],
);
1;
package main;
use strict;
use warnings;
# Load local helper script for connecting to database
use FindBin qw( $Bin );
use lib "$Bin/lib";
require 'helpers.pl'; ## no critic
my $schema = get_schema();
my $opts = ShinyCMS::ResetPassword->new_with_options();
my $user = $schema->resultset( 'User' )->find({ username => $opts->username });
die 'Could not find user with username: ' . $opts->username unless $user;
$user->password( $opts->password );
$user->update;
print 'Password updated for user with username: ', $opts->username, "\n";