Require https for LWP, when using OpenID with google
[scpubgit/stemmatology.git] / script / admin_users,pl
CommitLineData
ef02228c 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use v5.10.0;
7
8use Getopt::Long;
9use Text::Tradition::UserStore;
10
11use lib 'lib';
12
13my ($dsn, $command) = ('dbi:SQLite:dbname=db/traditions.db', 'add', undef);
14my ($username, $password);
15
16GetOptions(
17 'c|command:s' => \$command,
18 'dsn:s' => \$dsn,
19 'u|username=s' => \$username,
20 'p|password:s' => \$password,
21 ) or usage();
22
23if(!$command || !($command ~~ [qw/add modify delete/])) {
24 print "No command supplied, chickening out ... \n\n";
25 usage();
26}
27
28if(!$username) {
29 print "No username supplied, confused ... \n\n";
30 usage();
31}
32
33my $userstore = Text::Tradition::UserStore->new( dsn => $dsn);
34
35given ($command) {
36 when ('add') {
37 if(!$password || !$userstore->validate_password($password)) {
38 print "Can't add a new user without a valid password\n\n";
39 usage();
40 }
41 my $user = $userstore->add_user({ username => $username,
42 password => $password });
43 if(!$user) {
44 print "Failed to add user! (you should see errors above this..)\n";
45 } else {
46 print "OK.\n";
47 }
48 }
49
50 when ('modify') {
51 if(!$password || !$userstore->validate_password($password)) {
52 print "Can't modify a user without a valid password\n\n";
53 usage();
54 }
55 my $user = $userstore->modify_user({ username => $username,
56 password => $password });
57 if(!$user) {
58 print "Failed to modify user! (you should see errors above this..)\n";
59 } else {
60 print "OK.\n";
61 }
62 }
63 when ('delete') {
64 my $user = $userstore->delete_user({ username => $username});
65 if(!$user) {
66 print "Failed to modify user! (you should see errors above this..)\n";
67 } else {
68 print "OK.\n";
69 }
70 }
71}
72
73sub usage {
74 print "User Admin tool, to add/remove/modify users\n";
75 print "===========================================\n";
76 print "Usage: $0 -c add -u jimbob -p hispassword\n";
77 print "Usage: $0 -c modify -u jimbob -p hisnewpassword\n";
78 print "Usage: $0 -c delete -u jimbob\n";
79}
80
81=head1 NAME
82
83admin_users.pl - add / modify / delete users
84
85=head1 SYNOPSIS
86
87 admin_user.pl -c add -u jimbob -p "jimspassword"
88
89 admin_user.pl -c modify -u jimbob -p "jimsnewpassword"
90
91 admin_user.pl -c delete -u jimbob
92
93=head1 OPTIONS
94
95=over
96
97=item -c | --command
98
99The action to take, can be one of: add, modify, delete.
100
101=item -u | --username
102
103The username of the new user or user to change.
104
105=item -p | --password
106
107The new password or password to change.
108
109=back