Repository navigation
Expand file tree
/
Copy pathuser_add.pl
More file actions
executable file
·75 lines (56 loc) · 1.59 KB
/
Copy pathuser_add.pl
File metadata and controls
executable file
·75 lines (56 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env perl
use strict;
use warnings;
use WebApplicationDBHandle;
use Getopt::Long;
sub usage {
print "user_add.pl >>> add a user to the web application database\n";
print "user_add.pl -firstname <fn> -lastname <ln> -login <login> -email <email> [ -comment <text> ]\n";
}
# read in parameters
my $firstname = '';
my $lastname = '';
my $login = '';
my $email = '';
my $comment = '';
GetOptions ( 'firstname=s' => \$firstname,
'lastname=s' => \$lastname,
'login=s' => \$login,
'email=s' => \$email,
'comment=s' => \$comment,
);
unless ($firstname and $lastname and $login and $email) {
&usage();
exit 0;
}
# initialize db-master
my ($dbmaster, $error) = WebApplicationDBHandle->new();
# check if we got a dbmaster
if ($error) {
print $error."\n";
exit 0;
}
print "Creating user $login ($firstname $lastname, $email).\n";
# sanity checks
my $user;
if ($user = $dbmaster->User->init({ email => $email })) {
print "This email has already been registered for ".$user->login.", aborting.\n";
exit 0;
}
if ($user = $dbmaster->User->init({ login => $login })) {
print "This login has already been registered for ".
$user->firstname." ".$user->lastname.", aborting.\n";
exit 0;
}
# create the user in the db
$user = $dbmaster->User->create( { email => $email,
firstname => $firstname,
lastname => $lastname,
login => $login,
active => 1,
} );
unless (ref $user and $user->isa('WebServerBackend::User')) {
print "Unable to create user. Quit.\n";
exit 0;
}
print "Done.\n";