10 use ExtUtils::MakeMaker();
13 use Text::Tradition::Directory;
15 my ($dsn, $command) = ('dbi:SQLite:dbname=db/traditions.db', 'add', undef);
16 my ($username, $password, $tradition_id);
19 'c|command:s' => \$command,
21 'u|username=s' => \$username,
22 'p|password:s' => \$password,
23 't|tradition:s' => \$tradition_id,
26 if(!$command || !($command ~~ [qw/add modify delete deactivate reactivate list/])) {
27 print "No command supplied, chickening out ... \n\n";
32 print "No username supplied, confused ... \n\n";
36 # my $userstore = Text::Tradition::UserStore->new( dsn => $dsn);
37 my $userstore = Text::Tradition::Directory->new( dsn => $dsn);
38 my $new_scope = $userstore->new_scope;
42 if(!$password || !$userstore->validate_password($password)) {
43 print "Can't add a new user without a valid password\n\n";
46 my $user = $userstore->add_user({ username => $username,
47 password => $password });
49 print "Failed to add user! (you should see errors above this..)\n";
56 if(!$tradition_id && !$password) {
57 print "Can't modify a user without a valid password or a tradition\n\n";
61 if( $password && !$userstore->validate_password($password)) {
62 print "Can't modify a user without a valid password\n\n";
67 my $user = $userstore->modify_user({ username => $username,
68 password => $password });
70 print "Failed to modify user! (you should see errors above this..)\n";
74 } elsif($tradition_id) {
75 my $tradition = $userstore->tradition($tradition_id);
76 my $user = $userstore->find_user({ username => $username });
77 if(!$tradition || !$user) {
78 print "Can't find one of '$username' or '$tradition_id' in the database!\n";
80 if(grep { $userstore->object_to_id($_)
82 $userstore->object_to_id($tradition)}
83 @{$user->traditions}) {
84 $user->remove_tradition($tradition);
86 $user->add_tradition($tradition);
88 $userstore->update($tradition);
89 $userstore->update($user);
96 my $user = $userstore->find_user({ username => $username });
98 print "Can't find user '$username'\n";
101 my $traditions = $user->traditions;
103 print "User: $username\n";
104 print "Has traditions: \n";
105 foreach my $t (@$traditions) {
106 print " ", $t->name, "\n";
111 when ('deactivate') {
112 my $user = $userstore->deactivate_user({ username => $username});
114 print "Failed to deactivate user! (you should see errors above this..)\n";
120 when ('reactivate') {
121 my $user = $userstore->reactivate_user({ username => $username});
123 print "Failed to reactivate user! (you should see errors above this..)\n";
130 my $yesno = ExtUtils::MakeMaker::prompt("Permanently delete $username? (y/N)", "n");
131 if($yesno !~ /^y$/i) {
132 print "Not deleting $username\n";
135 my $user = $userstore->delete_user({ username => $username});
137 print "Failed to delete user! (you should see errors above this..)\n";
145 print "User Admin tool, to add/modify/deactivate/reactivate/delete users\n";
146 print "===========================================\n";
147 print "Usage: $0 -c add -u jimbob -p hispassword\n";
148 print "Usage: $0 -c modify -u jimbob -p hisnewpassword\n";
149 print "Usage: $0 -c modify -u jimbob -t \"Notre besoin\"\n";
150 print "Usage: $0 -c deactivate -u jimbob\n";
155 admin_users.pl - add / modify / etc users
159 admin_user.pl -c add -u jimbob -p "jimspassword"
161 admin_user.pl -c modify -u jimbob -p "jimsnewpassword"
163 admin_user.pl -c modify -u jimbob -t "mytradition"
165 admin_user.pl -c list -u jimbob
167 admin_user.pl -c delete -u jimbob
175 The action to take, can be one of: add, modify, deactivate, reactivate, delete, list.
181 Create a new user and store it in the Directory
185 Change an existing stored user, with a -p this will change the user's
186 password, with a -t will add or remove the named tradition from the
191 List the given user's traditions.
195 Deactivate this user.
199 Re-activate this user.
203 Delete the user permanently.
207 =item -u | --username
209 The username of the new user or user to change.
211 =item -p | --password
213 The new password or password to change.
215 =item -t | --tradition
217 A Text::Tradition id or name which will be assigned to the user given.