| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | package Apache::Sling::UserUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use Apache::Sling::URL; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | require Exporter; | |||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 3 | our @EXPORT_OK = (); | |||||||||
| 16 | |||||||||||
| 17 | 3 | our $VERSION = '0.27'; | |||||||||
| 18 | |||||||||||
| 19 | #{{{sub add_setup | ||||||||||
| 20 | |||||||||||
| 21 | 6 | ▶ | sub add_setup { | ||||||||
|
Subroutine
add_setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 22 | 6 | my ( $base_url, $act_on_user, $act_on_pass, $properties ) = @_; | |||||||||
| 23 | 6 | ▶ | if ( !defined $base_url ) { croak 'No base url defined to add against!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 5 | ▶ | if ( !defined $act_on_user ) { croak 'No user name defined to add!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 3 | ▶ | if ( !defined $act_on_pass ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 1 | croak "No user password defined to add for user $act_on_user!"; | |||||||||
| 27 | } | ||||||||||
| 28 | 2 | my $property_post_vars = | |||||||||
| 29 | Apache::Sling::URL::properties_array_to_string($properties); | ||||||||||
| 30 | 2 | my $post_variables = | |||||||||
| 31 | "\$post_variables = [':name','$act_on_user','pwd','$act_on_pass','pwdConfirm','$act_on_pass'"; | ||||||||||
| 32 | 2 | ▶ | if ( $property_post_vars ne q{} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 1 | $post_variables .= ",$property_post_vars"; | |||||||||
| 34 | } | ||||||||||
| 35 | 2 | $post_variables .= ']'; | |||||||||
| 36 | 2 | return "post $base_url/system/userManager/user.create.html $post_variables"; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | #}}} | ||||||||||
| 40 | |||||||||||
| 41 | #{{{sub add_eval | ||||||||||
| 42 | # Return true if the return code is 200 or 201 | ||||||||||
| 43 | # to support Sakai Nakamura using the more correct | ||||||||||
| 44 | # 201 "Created" return code: | ||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | sub add_eval { | ||||||||
|
Subroutine
add_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 47 | 1 | my ($res) = @_; | |||||||||
| 48 | 1 | return ( ${$res}->code =~ /^20(0|1)$/x ); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | #}}} | ||||||||||
| 52 | |||||||||||
| 53 | #{{{sub change_password_setup | ||||||||||
| 54 | |||||||||||
| 55 | 7 | ▶ | sub change_password_setup { | ||||||||
|
Subroutine
change_password_setup: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 56 | 7 | my ( $base_url, $act_on_user, $act_on_pass, $new_pass, $new_pass_confirm ) = | |||||||||
| 57 | @_; | ||||||||||
| 58 | 7 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 6 | ▶ | if ( !defined $act_on_user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 2 | croak 'No user name defined to change password for!'; | |||||||||
| 61 | } | ||||||||||
| 62 | 4 | ▶ | if ( !defined $act_on_pass ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 1 | croak "No current password defined for $act_on_user!"; | |||||||||
| 64 | } | ||||||||||
| 65 | 3 | ▶ | if ( !defined $new_pass ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 1 | croak "No new password defined for $act_on_user!"; | |||||||||
| 67 | } | ||||||||||
| 68 | 2 | ▶ | if ( !defined $new_pass_confirm ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 1 | croak "No confirmation of new password defined for $act_on_user!"; | |||||||||
| 70 | } | ||||||||||
| 71 | 1 | my $post_variables = | |||||||||
| 72 | "\$post_variables = ['oldPwd','$act_on_pass','newPwd','$new_pass','newPwdConfirm','$new_pass_confirm']"; | ||||||||||
| 73 | return | ||||||||||
| 74 | 1 | "post $base_url/system/userManager/user/$act_on_user.changePassword.html $post_variables"; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | #}}} | ||||||||||
| 78 | |||||||||||
| 79 | #{{{sub change_password_eval | ||||||||||
| 80 | |||||||||||
| 81 | 1 | ▶ | sub change_password_eval { | ||||||||
|
Subroutine
change_password_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 1 | my ($res) = @_; | |||||||||
| 83 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | #}}} | ||||||||||
| 87 | |||||||||||
| 88 | #{{{sub delete_setup | ||||||||||
| 89 | |||||||||||
| 90 | 4 | ▶ | sub delete_setup { | ||||||||
|
Subroutine
delete_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 91 | 4 | my ( $base_url, $act_on_user ) = @_; | |||||||||
| 92 | 4 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 1 | croak 'No base url defined to delete against!'; | |||||||||
| 94 | } | ||||||||||
| 95 | 3 | ▶ | if ( !defined $act_on_user ) { croak 'No user name defined to delete!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 1 | my $post_variables = '$post_variables = []'; | |||||||||
| 97 | return | ||||||||||
| 98 | 1 | "post $base_url/system/userManager/user/$act_on_user.delete.html $post_variables"; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | #}}} | ||||||||||
| 102 | |||||||||||
| 103 | #{{{sub delete_eval | ||||||||||
| 104 | |||||||||||
| 105 | 1 | ▶ | sub delete_eval { | ||||||||
|
Subroutine
delete_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 106 | 1 | my ($res) = @_; | |||||||||
| 107 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | #}}} | ||||||||||
| 111 | |||||||||||
| 112 | #{{{sub exists_setup | ||||||||||
| 113 | |||||||||||
| 114 | 4 | ▶ | sub exists_setup { | ||||||||
|
Subroutine
exists_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 115 | 4 | my ( $base_url, $act_on_user ) = @_; | |||||||||
| 116 | 4 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 1 | croak 'No base url to check existence against!'; | |||||||||
| 118 | } | ||||||||||
| 119 | 3 | ▶ | if ( !defined $act_on_user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | 2 | croak 'No user to check existence of defined!'; | |||||||||
| 121 | } | ||||||||||
| 122 | 1 | return "get $base_url/system/userManager/user/$act_on_user.tidy.json"; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | #}}} | ||||||||||
| 126 | |||||||||||
| 127 | #{{{sub exists_eval | ||||||||||
| 128 | |||||||||||
| 129 | 2 | ▶ | sub exists_eval { | ||||||||
|
Subroutine
exists_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 130 | 2 | my ($res) = @_; | |||||||||
| 131 | 2 | return ( ${$res}->code eq '200' ); | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | #}}} | ||||||||||
| 135 | |||||||||||
| 136 | #{{{sub update_setup | ||||||||||
| 137 | |||||||||||
| 138 | 4 | ▶ | sub update_setup { | ||||||||
|
Subroutine
update_setup: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 139 | 4 | my ( $base_url, $act_on_user, $properties ) = @_; | |||||||||
| 140 | 4 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 1 | croak 'No base url defined to update against!'; | |||||||||
| 142 | } | ||||||||||
| 143 | 3 | ▶ | if ( !defined $act_on_user ) { croak 'No user name defined to update!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | 2 | my $property_post_vars = | |||||||||
| 145 | Apache::Sling::URL::properties_array_to_string($properties); | ||||||||||
| 146 | 2 | my $post_variables = '$post_variables = ['; | |||||||||
| 147 | 2 | ▶ | if ( $property_post_vars ne q{} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 1 | $post_variables .= "$property_post_vars"; | |||||||||
| 149 | } | ||||||||||
| 150 | 2 | $post_variables .= ']'; | |||||||||
| 151 | return | ||||||||||
| 152 | 2 | "post $base_url/system/userManager/user/$act_on_user.update.html $post_variables"; | |||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | #}}} | ||||||||||
| 156 | |||||||||||
| 157 | #{{{sub update_eval | ||||||||||
| 158 | |||||||||||
| 159 | 1 | ▶ | sub update_eval { | ||||||||
|
Subroutine
update_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 160 | 1 | my ($res) = @_; | |||||||||
| 161 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | #}}} | ||||||||||
| 165 | |||||||||||
| 166 | 3 | 1; | |||||||||
| 167 | |||||||||||
| 168 | __END__ | ||||||||||