| 1 | package iRedAdmin::User; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | has 'ref' => (is => 'ro'); | |||||||||
| 6 | |||||||||||
| 7 | 0 | ▶ | sub Add { | ||||||||
|
Subroutine
Add: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 8 | 0 | my ($self, %data) = @_; | |||||||||
| 9 | |||||||||||
| 10 | 0 | ▶ | if (Email::Valid->address($data{email})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $self->Add(%data) if $success == 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | return $success ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | }else{ | ||||||||||
| 29 | 0 | $self->ref->set_error('Email is invalid!'); | |||||||||
| 30 | 0 | return 0; | |||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub Edit { | ||||||||
|
Subroutine
Edit: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||
| 35 | 0 | my ($self, %data) = @_; | |||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | if (Email::Valid->address($data{email})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | $self->ref->mech->get($self->ref->_address . '/profile/user/general/' . $data{email}); | |||||||||
| 39 | |||||||||||
| 40 | 0 | my %form; | |||||||||
| 41 | 0 | ▶ | $form{cn} = $data{name} if exists $data{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | ▶ | $form{preferredLanguage} = $self->ref->_lang($data{lang}) if $data{lang}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | ▶ | $form{mailQuota} = $data{quota} if $data{quota}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | $form{employeeNumber} = $data{user_id} if exists $data{user_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | ▶ | if (exists $data{domainGlobalAdmin}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | $form{domainGlobalAdmin} = 'global' if $data{global_admin}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | ▶ | $self->ref->mech->untick('domainGlobalAdmin', 'global') unless $data{global_admin}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | 0 | ▶ | if (exists $data{enable}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | $form{accountStatus} = 'active' if $data{enable}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | ▶ | $self->ref->mech->untick('accountStatus', 'active') unless $data{enable}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $self->Add(%data) if $success == 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | return $success ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | }else{ | ||||||||||
| 62 | 0 | $self->ref->set_error('Email is invalid!'); | |||||||||
| 63 | 0 | return 0; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub Password { | ||||||||
|
Subroutine
Password: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 68 | 0 | my ($self, %data) = @_; | |||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | if (Email::Valid->address($data{email})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $self->Password(%data) if $success == 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | ▶ | return $success ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | }else{ | ||||||||||
| 85 | 0 | $self->ref->set_error('Email is invalid!'); | |||||||||
| 86 | 0 | return 0; | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub Enable { | ||||||||
|
Subroutine
Enable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 91 | 0 | my ($self, @email) = @_; | |||||||||
| 92 | |||||||||||
| 93 | 0 | $self->_apply('enable', [@email]); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub Disable { | ||||||||
|
Subroutine
Disable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 97 | 0 | my ($self, @email) = @_; | |||||||||
| 98 | |||||||||||
| 99 | 0 | $self->_apply('disable', [@email]); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | sub Delete { | ||||||||
|
Subroutine
Delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 103 | 0 | my ($self, @email) = @_; | |||||||||
| 104 | |||||||||||
| 105 | 0 | $self->_apply('delete', [@email]); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub _apply { | ||||||||
|
Subroutine
_apply: not called CC=6 SCAR=37.4
| |||||||||||
| 109 | 0 | my ($self, $type, @email) = @_; | |||||||||
| 110 | |||||||||||
| 111 | 0 | my $domain = undef; | |||||||||
| 112 | 0 | for(@{$email[0]}){ | |||||||||
| 113 | 0 | $_ =~ m!@(.*?)$!s; | |||||||||
| 114 | 0 | ▶ | if ($domain) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | ▶ | if ($domain ne $1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $self->_apply($type, @email) if $success == 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | ▶ | return $success ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 1 | 1; | |||||||||
| 140 | |||||||||||
| 141 | __END__ | ||||||||||