line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package iRedAdmin::User; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has 'ref' => (is => 'ro'); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub Add { |
8
|
0
|
|
|
0
|
1
|
|
my ($self, %data) = @_; |
9
|
|
|
|
|
|
|
|
10
|
0
|
0
|
|
|
|
|
if (Email::Valid->address($data{email})) { |
11
|
0
|
|
|
|
|
|
my ($email, $domain) = $data{email} =~ m!^(.*?)@(.*?)$!gs; |
12
|
0
|
|
|
|
|
|
$self->ref->mech->get($self->ref->_address . '/create/user/'); |
13
|
|
|
|
|
|
|
$self->ref->mech->submit_form( |
14
|
|
|
|
|
|
|
form_number => 1, |
15
|
|
|
|
|
|
|
fields => { |
16
|
|
|
|
|
|
|
username => $email, |
17
|
|
|
|
|
|
|
domainName => $domain, |
18
|
|
|
|
|
|
|
newpw => $data{password}, |
19
|
|
|
|
|
|
|
confirmpw => $data{password}, |
20
|
|
|
|
|
|
|
cn => $data{name}, |
21
|
|
|
|
|
|
|
mailQuota => $data{quota} |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $success = $self->ref->_success; |
26
|
0
|
0
|
|
|
|
|
$self->Add(%data) if $success == 2; |
27
|
0
|
0
|
|
|
|
|
return $success ? 1 : 0; |
28
|
|
|
|
|
|
|
}else{ |
29
|
0
|
|
|
|
|
|
$self->ref->set_error('Email is invalid!'); |
30
|
0
|
|
|
|
|
|
return 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub Edit { |
35
|
0
|
|
|
0
|
1
|
|
my ($self, %data) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if (Email::Valid->address($data{email})) { |
38
|
0
|
|
|
|
|
|
$self->ref->mech->get($self->ref->_address . '/profile/user/general/' . $data{email}); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my %form; |
41
|
0
|
0
|
|
|
|
|
$form{cn} = $data{name} if exists $data{name}; |
42
|
0
|
0
|
|
|
|
|
$form{preferredLanguage} = $self->ref->_lang($data{lang}) if $data{lang}; |
43
|
0
|
0
|
|
|
|
|
$form{mailQuota} = $data{quota} if $data{quota}; |
44
|
0
|
0
|
|
|
|
|
$form{employeeNumber} = $data{user_id} if exists $data{user_id}; |
45
|
0
|
0
|
|
|
|
|
if (exists $data{domainGlobalAdmin}) { |
46
|
0
|
0
|
|
|
|
|
$form{domainGlobalAdmin} = 'global' if $data{global_admin}; |
47
|
0
|
0
|
|
|
|
|
$self->ref->mech->untick('domainGlobalAdmin', 'global') unless $data{global_admin}; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
0
|
|
|
|
|
if (exists $data{enable}) { |
50
|
0
|
0
|
|
|
|
|
$form{accountStatus} = 'active' if $data{enable}; |
51
|
0
|
0
|
|
|
|
|
$self->ref->mech->untick('accountStatus', 'active') unless $data{enable}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
$self->ref->mech->submit_form( |
54
|
0
|
|
|
|
|
|
form_number => 1, |
55
|
|
|
|
|
|
|
fields => \%form |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $success = $self->ref->_success; |
59
|
0
|
0
|
|
|
|
|
$self->Add(%data) if $success == 2; |
60
|
0
|
0
|
|
|
|
|
return $success ? 1 : 0; |
61
|
|
|
|
|
|
|
}else{ |
62
|
0
|
|
|
|
|
|
$self->ref->set_error('Email is invalid!'); |
63
|
0
|
|
|
|
|
|
return 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub Password { |
68
|
0
|
|
|
0
|
1
|
|
my ($self, %data) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (Email::Valid->address($data{email})) { |
71
|
0
|
|
|
|
|
|
$self->ref->mech->get($self->ref->_address . '/profile/user/general/' . $data{email}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->ref->mech->submit_form( |
74
|
|
|
|
|
|
|
form_number => 2, |
75
|
|
|
|
|
|
|
fields => { |
76
|
|
|
|
|
|
|
newpw => $data{password}, |
77
|
|
|
|
|
|
|
confirmpw => $data{password} |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $success = $self->ref->_success; |
82
|
0
|
0
|
|
|
|
|
$self->Password(%data) if $success == 2; |
83
|
0
|
0
|
|
|
|
|
return $success ? 1 : 0; |
84
|
|
|
|
|
|
|
}else{ |
85
|
0
|
|
|
|
|
|
$self->ref->set_error('Email is invalid!'); |
86
|
0
|
|
|
|
|
|
return 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub Enable { |
91
|
0
|
|
|
0
|
1
|
|
my ($self, @email) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$self->_apply('enable', [@email]); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub Disable { |
97
|
0
|
|
|
0
|
1
|
|
my ($self, @email) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->_apply('disable', [@email]); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub Delete { |
103
|
0
|
|
|
0
|
1
|
|
my ($self, @email) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->_apply('delete', [@email]); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _apply { |
109
|
0
|
|
|
0
|
|
|
my ($self, $type, @email) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $domain = undef; |
112
|
0
|
|
|
|
|
|
for(@{$email[0]}){ |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$_ =~ m!@(.*?)$!s; |
114
|
0
|
0
|
|
|
|
|
if ($domain) { |
115
|
0
|
0
|
|
|
|
|
if ($domain ne $1) { |
116
|
0
|
|
|
|
|
|
$self->ref->set_error('All email needs be of same domain!'); |
117
|
0
|
|
|
|
|
|
return 0; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
}else{ |
120
|
0
|
|
|
|
|
|
$domain = $1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->ref->mech->get($self->ref->_address . '/users/' . $domain); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my %form; |
127
|
0
|
|
|
|
|
|
$form{action} = $type; |
128
|
0
|
|
|
|
|
|
$form{mail} = \@email; |
129
|
0
|
|
|
|
|
|
$self->ref->mech->submit_form( |
130
|
|
|
|
|
|
|
form_number => 1, |
131
|
|
|
|
|
|
|
fields => \%form |
132
|
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $success = $self->ref->_success; |
135
|
0
|
0
|
|
|
|
|
$self->_apply($type, @email) if $success == 2; |
136
|
0
|
0
|
|
|
|
|
return $success ? 1 : 0; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |