line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Control::C::Users; |
2
|
1
|
|
|
1
|
|
60410
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
713
|
use Gantry qw/-TemplateEngine=TT/; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
690
|
use Gantry::Utils::Validate; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
658
|
use Gantry::Control; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
95
|
|
9
|
1
|
|
|
1
|
|
649
|
use Gantry::Control::Model::auth_users; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
10
|
1
|
|
|
1
|
|
793
|
use Gantry::Control::Model::auth_group_members; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
607
|
use Gantry::Utils::CRUDHelp qw( form_profile ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
13
|
1
|
|
|
1
|
|
771
|
use Gantry::Plugins::CRUD; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1241
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $crud = Gantry::Plugins::CRUD->new( |
16
|
|
|
|
|
|
|
add_action => \&_add, |
17
|
|
|
|
|
|
|
edit_action => \&_edit, |
18
|
|
|
|
|
|
|
delete_action => \&_delete, |
19
|
|
|
|
|
|
|
form => \&_form, |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
template => 'form.tt', |
22
|
|
|
|
|
|
|
text_descr => 'user', |
23
|
|
|
|
|
|
|
use_clean_dates => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @ISA = ( 'Gantry' ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $AUTH_USERS = 'Gantry::Control::Model::auth_users'; |
29
|
|
|
|
|
|
|
my $AUTH_GROUP_MEMBERS = 'Gantry::Control::Model::auth_group_members'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################ |
32
|
|
|
|
|
|
|
# Functions # |
33
|
|
|
|
|
|
|
############################################################ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#------------------------------------------------- |
36
|
|
|
|
|
|
|
# $self->do_main( $order ) |
37
|
|
|
|
|
|
|
#------------------------------------------------- |
38
|
|
|
|
|
|
|
sub do_main { |
39
|
0
|
|
|
0
|
1
|
|
my ( $self, $order ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
|
$order ||= 2; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $order_map = { |
44
|
|
|
|
|
|
|
1 => 'active', |
45
|
|
|
|
|
|
|
2 => 'user_id', |
46
|
|
|
|
|
|
|
3 => 'user_name', |
47
|
|
|
|
|
|
|
4 => 'last_name, first_name', |
48
|
|
|
|
|
|
|
5 => 'email' |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# stash template name and page title |
52
|
0
|
|
|
|
|
|
$self->stash->view->template( 'results.tt' ); |
53
|
0
|
|
|
|
|
|
$self->stash->view->title( 'Users' ); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $retval = { |
56
|
|
|
|
|
|
|
headings => [ |
57
|
|
|
|
|
|
|
'Active', |
58
|
|
|
|
|
|
|
'User ID', |
59
|
|
|
|
|
|
|
'User Name', |
60
|
|
|
|
|
|
|
'Name', |
61
|
|
|
|
|
|
|
'E-mail' |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
header_options => [ |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
text => 'Add', |
66
|
|
|
|
|
|
|
link => $self->location() . "/add", |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
], |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my @rows = $AUTH_USERS->retrieve_all( |
72
|
|
|
|
|
|
|
{ 'order_by' => $order_map->{$order} } |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
foreach my $row ( @rows ) { |
76
|
0
|
|
|
|
|
|
my $id = $row->id; |
77
|
0
|
|
|
|
|
|
push( |
78
|
0
|
0
|
|
|
|
|
@{$$retval{rows}}, |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
data => [ |
81
|
|
|
|
|
|
|
( $row->active ? 'yes' : 'no' ), |
82
|
|
|
|
|
|
|
$row->user_id, |
83
|
|
|
|
|
|
|
$row->user_name, |
84
|
|
|
|
|
|
|
( $row->last_name . ", " . $row->first_name ), |
85
|
|
|
|
|
|
|
$row->email |
86
|
|
|
|
|
|
|
], |
87
|
|
|
|
|
|
|
options => [ |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
text => 'Edit', |
90
|
|
|
|
|
|
|
link => ( $self->location . "/edit/$id" ) |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
text => 'Delete', |
94
|
|
|
|
|
|
|
link => ( $self->location . "/delete/$id" ), |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
] |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# stash view data |
102
|
0
|
|
|
|
|
|
$self->stash->view->data( $retval ); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} # end do_main |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#------------------------------------------------- |
109
|
|
|
|
|
|
|
# $self->do_add( $r ) |
110
|
|
|
|
|
|
|
#------------------------------------------------- |
111
|
|
|
|
|
|
|
sub do_add { |
112
|
0
|
|
|
0
|
1
|
|
my ( $self ) = ( shift ); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$crud->add( $self ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} # end do_add |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _add { |
119
|
0
|
|
|
0
|
|
|
my( $self, $params, $data ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my %param = %{ $params }; |
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$param{'crypt'} = encrypt( $param{passwd} ); |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $new_row = $AUTH_USERS->create( \%param ); |
126
|
0
|
|
|
|
|
|
$new_row->dbi_commit; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} # end do_add |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#------------------------------------------------- |
131
|
|
|
|
|
|
|
# $self->do_edit( $id ) |
132
|
|
|
|
|
|
|
#------------------------------------------------- |
133
|
|
|
|
|
|
|
sub do_edit { |
134
|
0
|
|
|
0
|
1
|
|
my ( $self, $id ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Load row values |
137
|
0
|
|
|
|
|
|
my $user = $AUTH_USERS->retrieve( $id ); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$crud->edit( $self, { user => $user } ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} # end do_edit |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#------------------------------------------------- |
144
|
|
|
|
|
|
|
# $self->_edit( $param, $data ) |
145
|
|
|
|
|
|
|
#------------------------------------------------- |
146
|
|
|
|
|
|
|
sub _edit { |
147
|
0
|
|
|
0
|
|
|
my( $self, $params, $data ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my %param = %{ $params }; |
|
0
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$param{'crypt'} = encrypt( $param{passwd} ); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $user = $data->{user}; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Make update |
156
|
0
|
|
|
|
|
|
$user->set( %param ); |
157
|
0
|
|
|
|
|
|
$user->update; |
158
|
0
|
|
|
|
|
|
$user->dbi_commit; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
} # end do_edit |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#------------------------------------------------- |
163
|
|
|
|
|
|
|
# $self->do_delete( $id, $yes ) |
164
|
|
|
|
|
|
|
#------------------------------------------------- |
165
|
|
|
|
|
|
|
sub do_delete { |
166
|
0
|
|
|
0
|
1
|
|
my ( $self, $id, $yes ) = @_; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Load row values |
169
|
0
|
|
|
|
|
|
my $user = $AUTH_USERS->retrieve( $id ); |
170
|
0
|
|
|
|
|
|
$crud->delete( $self, $yes, { user => $user } ); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} # end do_delete |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
#------------------------------------------------- |
175
|
|
|
|
|
|
|
# $self->_delete( $data ) |
176
|
|
|
|
|
|
|
#------------------------------------------------- |
177
|
|
|
|
|
|
|
sub _delete { |
178
|
0
|
|
|
0
|
|
|
my( $self, $data ) = @_; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $user = $data->{user}; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my @mems = $AUTH_GROUP_MEMBERS->search( user_id => $user->user_id ); |
183
|
0
|
|
|
|
|
|
foreach ( @mems ) { |
184
|
0
|
|
|
|
|
|
$_->delete; |
185
|
|
|
|
|
|
|
} |
186
|
0
|
|
|
|
|
|
$AUTH_GROUP_MEMBERS->dbi_commit; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$user->delete; |
189
|
0
|
|
|
|
|
|
$AUTH_USERS->dbi_commit(); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} # end delete_page |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#------------------------------------------------- |
195
|
|
|
|
|
|
|
# _form( $row ? ) |
196
|
|
|
|
|
|
|
#------------------------------------------------- |
197
|
|
|
|
|
|
|
sub _form { |
198
|
0
|
|
|
0
|
|
|
my ( $self, $data ) = @_; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $row = $data->{user}; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my ( @available_ids, %existing_ids ); |
203
|
0
|
|
|
|
|
|
my @users = $AUTH_USERS->retrieve_all(); |
204
|
0
|
|
|
|
|
|
foreach ( @users ) { |
205
|
0
|
|
|
|
|
|
++$existing_ids{ $_->user_id }; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
for ( my $i = 1; $i < 300; ++$i ) { |
209
|
0
|
0
|
|
|
|
|
push( @available_ids, { label => $i, value => $i } ) |
210
|
|
|
|
|
|
|
unless defined $existing_ids{ $i }; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my @fields; |
214
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
push( @fields, |
216
|
|
|
|
|
|
|
{ name => 'user_id', |
217
|
|
|
|
|
|
|
is => 'int4', |
218
|
|
|
|
|
|
|
label => 'User ID', |
219
|
|
|
|
|
|
|
type => 'select', |
220
|
|
|
|
|
|
|
options => \@available_ids, |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
) if $self->path_info =~ /add/i; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
push( @fields, |
225
|
|
|
|
|
|
|
{ name => 'active', |
226
|
|
|
|
|
|
|
label => 'Active', |
227
|
|
|
|
|
|
|
type => 'select', |
228
|
|
|
|
|
|
|
is => 'boolean', |
229
|
|
|
|
|
|
|
options => [ |
230
|
|
|
|
|
|
|
{ label => 'Yes', value => 't' }, |
231
|
|
|
|
|
|
|
{ label => 'No', value => 'f' }, |
232
|
|
|
|
|
|
|
], |
233
|
|
|
|
|
|
|
}, |
234
|
|
|
|
|
|
|
{ name => 'user_name', |
235
|
|
|
|
|
|
|
label => 'User Name', |
236
|
|
|
|
|
|
|
type => 'text', |
237
|
|
|
|
|
|
|
is => 'varchar', |
238
|
|
|
|
|
|
|
}, |
239
|
|
|
|
|
|
|
{ name => 'passwd', |
240
|
|
|
|
|
|
|
label => 'Password', |
241
|
|
|
|
|
|
|
is => 'varchar', |
242
|
|
|
|
|
|
|
type => 'password', |
243
|
|
|
|
|
|
|
}, |
244
|
|
|
|
|
|
|
{ name => 'first_name', |
245
|
|
|
|
|
|
|
label => 'First Name', |
246
|
|
|
|
|
|
|
is => 'varchar', |
247
|
|
|
|
|
|
|
type => 'text', |
248
|
|
|
|
|
|
|
}, |
249
|
|
|
|
|
|
|
{ name => 'last_name', |
250
|
|
|
|
|
|
|
label => 'Last Name', |
251
|
|
|
|
|
|
|
is => 'varchar', |
252
|
|
|
|
|
|
|
type => 'text', |
253
|
|
|
|
|
|
|
}, |
254
|
|
|
|
|
|
|
{ optional => 1, |
255
|
|
|
|
|
|
|
name => 'email', |
256
|
|
|
|
|
|
|
is => 'varchar', |
257
|
|
|
|
|
|
|
label => 'E-mail', |
258
|
|
|
|
|
|
|
type => 'text', |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
); |
261
|
|
|
|
|
|
|
|
262
|
0
|
0
|
|
|
|
|
my $form = { |
263
|
|
|
|
|
|
|
legend => $self->path_info =~ /edit/i ? 'Edit' : 'Add', |
264
|
|
|
|
|
|
|
width => 400, |
265
|
|
|
|
|
|
|
row => $row, |
266
|
|
|
|
|
|
|
fields => \@fields |
267
|
|
|
|
|
|
|
}; |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
return( $form ); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
} # end _form |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub site_links { |
274
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
return( [ |
277
|
0
|
|
|
|
|
|
{ link => ($self->app_rootp . '/users'), label => 'Users' }, |
278
|
|
|
|
|
|
|
{ link => ($self->app_rootp . '/groups'), label => 'Groups' }, |
279
|
|
|
|
|
|
|
{ link => ($self->app_rootp . '/pages'), label => 'Pages' }, |
280
|
|
|
|
|
|
|
] ); |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# EOF |
284
|
|
|
|
|
|
|
1; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
__END__ |