| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/usr/bin/env perl
- package tcms::useradd;
- use strict;
- use warnings;
- use FindBin::libs;
- use Getopt::Long;
- use Pod::Usage;
- use Trog::Auth;
- =head1 SYNOPSIS
- Add or edit a tCMS user. In the event of a user edit, every option save for user is optional.
- does not update user pages. Use this to reset user passwords or fix broken users.
- =head2 USAGE
- tcms-useradd --user foo --password bar --display_name baz --contact_email foo@bar.baz --acl fred --acl wilma
- =head2 OPTIONS
- =over 4
- =item --user
- Specify the user to add, or edit if the user already exists.
- =item --password
- Set a password for the user. Leave blank if you want to keep the password for an existing user.
- =item --display_name
- Set the display name for the user.
- =item --contact_email
- Set the contact email for the user.
- =item --acl
- Set an acl for this user. May be passed multiple times.
- Defaults to 'admin' acl.
- =item --help, --man
- Display this output.
- =back
- =cut
- sub main {
- my %options;
- Getopt::Long::GetOptionsFromArray(\@_,
- 'user=s' => \$options{user},
- 'display_name=s' => \$options{display_name},
- 'help|?' => \$options{help},
- 'password=s' => \$options{password},
- 'contact_email=s' => \$options{contact_email},
- 'acl=s@' => \$options{acl},
- );
- pod2usage(-exitval => 0, -verbose => 1) if $options{help};
- $options{acl} //= [];
- $options{acl} = [$options{acl}] if $options{acl} && ref $options{acl} ne 'ARRAY';
- $options{acl} = ['admin'] unless @{$options{acl}};
- Trog::Auth::killsession($options{user});
- Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contactemail} );
- return 0;
- }
- exit main(@ARGV) unless caller;
- 1;
|