lib/MojoMojo/Controller/User.pm

filter: Statementstmt 55.0% 125 / 227 Branchbran 29.4% 20 / 68 Conditioncond 19.5% 9 / 46 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 76.4% 26 / 34 Podpod 100% 14 / 14 totaltotal 47.7% 197 / 413 CC 51 SCAR 29.9
CC
51
Cov
45%
editprofile
72.0
page_user
42.0
register
33.2
CRAP 19.9
« lib/MojoMojo/Controller/Page.pm ↑ Summary lib/MojoMojo/Controller/Export.pm »
1 package MojoMojo::Controller::User;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use parent qw/Catalyst::Controller::HTML::FormFu/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 35 ▶use Digest::MD5 qw/md5_hex/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use Text::Password::Pronounceable;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 35 my $auth_class = MojoMojo->config->{auth_class};
10  
11 =head1 NAME
12  
13 MojoMojo::Controller::User - Login/User Management Controller
14  
15  
16 =head1 DESCRIPTION
17  
18 This controller performs user management: registration, login, logout,
19 password recovery and profile editing.
20  
21  
22 =head1 ACTIONS
23  
24 =head2 login (/.login)
25  
26 Log in through the authentication system.
27  
28 =cut
29  
30 14 ▶sub login : Global : FormConfig {
Subroutine login: called CC=7 SCAR=19.5
31 14 my ( $self, $c ) = @_;
32 14 ▶ $c->stash->{message} ||= $c->flash->{message};
Condition100%3/3
$c->stash->{"message"} ||= $c->flash->{"message"}
l!l&&r!l&&!r
1112
MC/DC100%2/2
$c->stash->{"message"} ||= $c->flash->{"message"}
$c->stash->{"message"} $c->flash->{"message"}
Truth table100%3/3
A ||= B
A= $c->stash->{"message"}B= $c->flash->{"message"}
ABresult
1X1
011
000
33 14 my $form = $c->stash->{form};
34  
35 14 ▶ if ( $form->submitted_and_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 10 4 14
36 10 ▶ if ($c->req->method ne 'POST') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->req->method ne 'POST') { } 1 9 10
elsif ($c->authenticate({'login', $form->param_value('login'), 'pass', $form->param_value('pass')})) { } 8 1 9
37 # general error - we want a POST
38 1 $c->res->status(400);
39 } elsif (
40 $c->authenticate(
41 {
42 login => $form->param_value('login'),
43 pass => $form->param_value('pass'),
44 }
45 )
46 )
47 {
48  
49 8 $c->stash->{user} = $c->user->obj;
50 $c->res->redirect( $c->uri_for( $c->stash->{path} ) )
51 8 ▶ unless $c->stash->{template};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->stash->{"template"} 7 1 8
52 8 return;
53 }
54 else {
55 1 $c->stash->{fail} = 1;
56 $c->stash->{message} =
57 1 $c->loc('Could not authenticate that login.');
58 # big debate in #catalyst on the status code that should be returned if authentication failed
59 # 400 is too vague, 401 says "MUST supply WWW-Authenticate", 451 is a M$ extension
60 # also note that IE doesn't display the error page if it's shorter than 512 bytes (not the case here)
61 1 $c->res->status(403); # works fine with IE6
62 }
63 }
64 6 ▶ $c->stash->{template} ||= "user/login.tt";
Condition100%2/2
$c->stash->{"template"} ||= "user/login.tt"
l!l
15
MC/DC100%1/1
$c->stash->{"template"} ||= "user/login.tt"
$c->stash->{"template"}
Truth table100%2/2
A
A= $c->stash->{"template"}
Aresult
11
00
65 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 =head2 logout ( /.logout )
68  
69 Log out the user.
70  
71 =cut
72  
73 2 ▶sub logout : Global {
Subroutine logout: called CC=1 SCAR=0.0
Pod documented
74 2 my ( $self, $c ) = @_;
75 2 $c->logout;
76 2 undef $c->stash->{user};
77  
78 2 $c->response->redirect( $c->uri_for('view') );
79 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 =head2 users ( /.users )
82  
83 Show a list of the active users with links to the pages they edited.
84  
85 =cut
86  
87 2 ▶sub users : Global {
Subroutine users: called CC=2 SCAR=7.0
Pod documented
88 2 my ( $elf, $c ) = @_;
89 2 ▶ my $res = $c->model("DBIC::Person")->search(
Condition50%1/2
$c->req->param('page') || 1
l!l
02
MC/DC0%0/1
$c->req->param('page') || 1
$c->req->param('page')
Truth table50%1/2
A
A= $c->req->param('page')
Aresult
11
00
90 { active => 1 },
91 {
92 page => $c->req->param('page') || 1,
93 rows => 20,
94 order_by => 'login'
95 }
96 );
97 2 $c->stash->{users} = $res;
98 2 $c->stash->{pager} = $res->pager;
99 2 $c->stash->{template} = 'user/list.tt';
100 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
101  
102 =head2 page_user
103  
104 Show a user's preferences
105  
106 =cut
107  
108 0 ▶sub page_user : Private {
Subroutine page_user: not called CC=6 SCAR=37.4
Pod documented
109 0 my ( $self, $c ) = @_;
110 0 my $user = $c->stash->{user};
111 my $login = (
112 $c->stash->{proto_pages}[-1]
113 ? $c->stash->{proto_pages}[-1]->{name} # FIXME: why not ->{name_orig}, like in editprofile() ?
114 : $c->stash->{page}->name
115 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'proto_pages'}[-1] ? : 0 0 0
116 0 my $page_user = $c->model("DBIC::Person")->get_user($login);
117  
118 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($page_user and $user and $page_user->id eq $user->id || $user->is_admin) { } 0 0 0
Condition0%0/9
$page_user and $user and $page_user->id eq $user->id || $user->is_admin
!ll&&!rl&&r
000
$page_user and $user
!ll&&!rl&&r
000
$page_user->id eq $user->id or $user->is_admin
l!l&&r!l&&!r
000
MC/DC0%0/4
$page_user and $user and $page_user->id eq $user->id || $user->is_admin
$page_user $user $page_user->id eq $user->id $user->is_admin
Truth table0%0/5
A and B and C or D
A= $page_userB= $userC= $page_user->id eq $user->idD= $user->is_admin
ABCDresult
0XXX0
10XX0
11000
111X1
11011
119 $page_user
120 && $user
121 && ( $page_user->id eq $user->id || $user->is_admin() )
122 )
123 {
124 0 $c->stash->{template} = 'user/prefs.tt';
125 0 $c->stash->{page_user} = $page_user;
126 }
127 else {
128 0 $c->stash->{message} = $c->loc('User not found: x', $login);
129 0 $c->stash->{template} = 'message.tt';
130 }
131 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 =head2 prefs ( .prefs )
134  
135 Main user preferences screen.
136  
137 =cut
138  
139  
140 0 ▶sub prefs : Global FormConfig {
Subroutine prefs: not called CC=3 SCAR=24.8
Pod documented
141 0 my ( $self, $c ) = @_;
142 0 my $form = $c->stash->{form};
143 0 $c->forward('page_user');
144 0 my $page_user = $c->stash->{page_user};
145 0 $form->model->default_values( $c->stash->{user} );
146 0 ▶ if ( $form->submitted_and_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 0 0 0
147 0 my $old_email = $page_user->email;
148 0 $form->model->update($page_user);
149 0 $c->stash->{message} = $c->loc('Updated preferences');
150 0 ▶ if ( $form->params->{email} ne $old_email ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->params->{"email"} ne $old_email) 0 0 0
151 0 $page_user->active(-1);
152 0 $page_user->update;
153 0 $c->forward( 'do_register', [$page_user] );
154 }
155 }
156 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158 =head2 password ( .prefs/password )
159  
160 Change password action.
161  
162 B<template:> user/password.tt
163  
164 =cut
165  
166 0 ▶sub password : Path('/prefs/password') FormConfig {
Subroutine password: not called CC=3 SCAR=24.8
Pod documented
167 0 my ( $self, $c ) = @_;
168 0 $c->forward('page_user');
169 0 my $page_user = $c->stash->{page_user};
170 0 my $form = $c->stash->{form};
171 0 ▶ if ( $form->submitted_and_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 0 0 0
172  
173 # FIXME: Should be moved into a formfu validator
174 0 ▶ unless ( $page_user->valid_pass( $form->params->{current} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page_user->valid_pass($form->params->{"current"})) 0 0 0
175 0 $c->stash->{message} = $c->loc('Invalid password');
176 0 return;
177 }
178 0 $page_user->pass( $form->params->{pass} );
179 0 $page_user->update();
180 0 $c->stash->{message} = $c->loc('Your password has been updated');
181 }
182 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 =head2 recover_pass
185  
186 Email a user a new password
187  
188 =cut
189  
190 2 ▶sub recover_pass : Global {
Subroutine recover_pass: called CC=4 SCAR=14.5
Pod documented
191 2 my ( $self, $c ) = @_;
192 2 ▶ return unless ( $c->req->method eq 'POST' );
Branch: 1 branch
BranchTrueFalseTotal
unless $c->req->method eq "POST" 1 1 2
193 1 my $id = $c->req->param('recover');
194 1 my $user =
195 $c->model('DBIC::Person')->search( [ email => $id, login => $id ] )
196 ->first;
197 1 ▶ unless ( $user ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 1 1
198 0 $c->flash->{message} = $c->loc('Could not recover password');
199 0 return $c->res->redirect( $c->uri_for('login') );
200 }
201  
202 $c->stash(
203 user => $user,
204 password => Text::Password::Pronounceable->generate(6, 10),
205 email => {
206 from => $c->config->{system_mail},
207 1 to => $user->login . ' <' . $user->email . '>',
208 subject => $c->loc('Your new password on x', $c->pref('name')),
209 template => 'reset_password.tt',
210 },
211 );
212  
213 1 $c->forward( $c->view('Email') );
214 1 ▶ if ( scalar( @{ $c->error } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$c->error;}) { } 0 1 1
215 0 $c->clear_errors;
216 $c->stash->{message} =
217 0 $c->loc('Error occurred while emailing you your new password.');
218 }
219 else {
220 1 $user->pass( $c->stash->{password} );
221 1 $user->update();
222 1 $c->flash->{message} = $c->loc('Emailed you your new password.');
223 1 return $c->res->redirect( $c->uri_for('login') );
224 }
225 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227 =head2 register ( /.register )
228  
229 Show new user registration form.
230  
231 B<template:> C<user/register.tt>
232  
233 =cut
234  
235 2 ▶sub register : Global FormConfig {
Subroutine register: called CC=12 SCAR=35.0
Pod documented
236 2 my ( $self, $c ) = @_;
237  
238 2 ▶ if ( !$c->pref('open_registration')
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->pref("open_registration") or $c->stash->{"user"} and $c->stash->{"user"}->is_admin) 0 2 2
Condition16%1/6
$c->pref("open_registration") or $c->stash->{"user"} and $c->stash->{"user"}->is_admin
l!l&&r!l&&!r
200
$c->stash->{"user"} and $c->stash->{"user"}->is_admin
!ll&&!rl&&r
000
MC/DC0%0/3
$c->pref("open_registration") or $c->stash->{"user"} and $c->stash->{"user"}->is_admin
$c->pref("open_registration") $c->stash->{"user"} $c->stash->{"user"}->is_admin
Truth table25%1/4
A or B and C
A= $c->pref("open_registration")B= $c->stash->{"user"}C= $c->stash->{"user"}->is_admin
ABCresult
1XX1
0111
00X0
0100
239 && ( !( $c->stash->{user} && $c->stash->{user}->is_admin ) ) )
240 {
241 0 $c->stash->{template} = 'message.tt';
242 0 return $c->stash->{message} = $c->loc('Registration is closed!');
243 }
244  
245 2 $c->stash->{template} = 'user/register.tt';
246 2 $c->stash->{message} = $c->loc(
247 'Please fill in the following information to register. All fields are mandatory.'
248 );
249 2 my $form = $c->stash->{form};
250 2 $c->stash->{newuser} = $c->model('DBIC::Person')->new_result( {} );
251 2 $c->stash->{template} = 'user/register.tt';
252  
253 2 ▶ if ( $c->pref('use_captcha')
Branch: 1 branch
BranchTrueFalseTotal
if ($c->pref("use_captcha") and not $c->stash->{"user"} && $c->stash->{"user"}->is_admin) 0 2 2
Condition16%1/6
$c->pref("use_captcha") and not $c->stash->{"user"} && $c->stash->{"user"}->is_admin
!ll&&!rl&&r
200
$c->stash->{'user'} && $c->stash->{'user'}->is_admin
!ll&&!rl&&r
000
MC/DC0%0/3
$c->pref("use_captcha") and not $c->stash->{"user"} && $c->stash->{"user"}->is_admin
$c->pref("use_captcha") $c->stash->{'user'} $c->stash->{'user'}->is_admin
Truth table25%1/4
A and not(B && C)
A= $c->pref("use_captcha")B= $c->stash->{'user'}C= $c->stash->{'user'}->is_admin
ABCresult
0XX0
1110
10X1
1101
254 && ( !( $c->stash->{user} && $c->stash->{user}->is_admin ) ) )
255 {
256 0 ▶ my $captcha_lang = $c->session->{lang} || $c->pref('default_lang');
Condition0%0/3
$c->session->{'lang'} || $c->pref('default_lang')
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->session->{'lang'} || $c->pref('default_lang')
$c->session->{'lang'} $c->pref('default_lang')
Truth table0%0/3
A || B
A= $c->session->{'lang'}B= $c->pref('default_lang')
ABresult
1X1
011
000
257 0 my $captcha = $form->element({
258 type => 'reCAPTCHA',
259 name => 'captcha',
260 recaptcha_options => { lang => $captcha_lang, theme => 'white' }
261 });
262 0 $form->process;
263 }
264  
265 2 $form->model->default_values( $c->stash->{newuser} );
266 2 ▶ if ( $form->submitted_and_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 1 1 2
267 # Need to check if login or email already exists.
268 1 ▶ if ( $c->forward('is_account_taken') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->forward("is_account_taken")) 0 1 1
269 0 $c->stash->{account_taken} = $c->loc('Account Taken. Try another.');
270 0 $c->detach();
271 }
272 1 $c->stash->{newuser}->active(-1);
273  
274 # XXX - need to add this so FormFu->model->update properly populates
275 # the required registered field. The other way to do this is by using
276 # DBIx::Class::DynamicDefaults, but I've restrained myself from adding
277 # yet another dependency -lestrrat
278 # $form->add_valid( registered => time() );
279 1 $form->model->update( $c->stash->{newuser} );
280 1 $c->stash->{newuser}->insert();
281 1 ▶ if ( $c->stash->{user} && $c->stash->{user}->is_admin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash->{'user'} and $c->stash->{'user'}->is_admin) { } 0 1 1
Condition33%1/3
$c->stash->{"user"} and $c->stash->{"user"}->is_admin
!ll&&!rl&&r
100
MC/DC0%0/2
$c->stash->{"user"} and $c->stash->{"user"}->is_admin
$c->stash->{"user"} $c->stash->{"user"}->is_admin
Truth table33%1/3
A and B
A= $c->stash->{"user"}B= $c->stash->{"user"}->is_admin
ABresult
0X0
100
111
282 0 $c->stash->{newuser}->update({active=>1});
283 0 $c->res->redirect( $c->uri_for('/.admin/user') );
284 }
285 else {
286 1 $c->forward( 'do_register', [ $c->stash->{newuser} ] );
287 }
288 }
289 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
290  
291 =head2 is_account_taken
292  
293 Test to see if a login or email is already in use.
294  
295 =cut
296  
297 1 ▶sub is_account_taken : Private {
Subroutine is_account_taken: called CC=1 SCAR=0.0
Pod documented
298 1 my ( $self, $c ) = @_;
299  
300 1 my $login = $c->request->body_params->{login};
301 1 my $email = $c->request->body_params->{email};
302 1 my $person_rs =
303 $c->model('DBIC::Person')
304 ->search( [ { login => $login }, { email => $email } ] );
305  
306 1 return $person_rs->count;
307 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
308  
309 =head2 do_register ( /.register )
310  
311 New user registration processing.
312  
313 B<templates:> C<user/password.tt>, C<user/validate.tt>
314  
315 =cut
316  
317 1 ▶sub do_register : Private {
Subroutine do_register: called CC=3 SCAR=11.4
Pod documented
318 1 my ( $self, $c, $user ) = @_;
319 1 $c->forward('/user/login');
320 1 ▶ $c->pref('entropy') || $c->pref( 'entropy', rand );
Branch: 1 branch
BranchTrueFalseTotal
$c->pref("entropy") or $c->pref("entropy", rand) 0 1 1
321 $c->stash(
322 secret => md5_hex( $user->email . $c->pref('entropy') ),
323 email => {
324 from => $c->config->{system_mail},
325 1 to => $user->email,
326 subject => $c->loc( '~[x~] New User Validation', $c->pref('name') ),
327 template => 'validate.tt',
328 },
329 );
330 1 $c->model('DBIC::Page')->create_page($user->link,
331 $c->loc("# Home node for x\n\nPut whatever you like here.",$user->name),
332 $user);
333  
334 1 $c->forward( $c->view('Email') );
335 1 ▶ if ( scalar( @{ $c->error } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$c->error;}) 0 1 1
336 0 $c->clear_errors;
337 0 $c->stash->{error} = $c->loc('An error occourred. Sorry.');
338 }
339 1 $c->stash->{user} = $user;
340 1 $c->stash->{template} = 'user/validate.tt';
341 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
342  
343 =head2 validate ( /.validate )
344  
345 Validation of user email. Will accept a md5_hex mailed to the user
346 earlier. Non-validated users will only be able to log out.
347  
348 =cut
349  
350 0 ▶sub validate : Global {
Subroutine validate: not called CC=4 SCAR=30.0
Pod documented
351 0 my ( $self, $c, $user, $check ) = @_;
352 0 $user = $c->model("DBIC::Person")->find( { login => $user } );
353 0 ▶ if ( $user and $check eq md5_hex( $user->email . $c->pref('entropy') ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user and $check eq md5_hex($user->email . $c->pref("entropy"))) 0 0 0
Condition0%0/3
$user and $check eq md5_hex($user->email . $c->pref("entropy"))
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $check eq md5_hex($user->email . $c->pref("entropy"))
$user $check eq md5_hex($user->email . $c->pref("entropy"))
Truth table0%0/3
A and B
A= $userB= $check eq md5_hex($user->email . $c->pref("entropy"))
ABresult
0X0
100
111
354 0 $user->update({active=>1});
355 0 ▶ if ( $c->stash->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash->{'user'}) { } 0 0 0
356 $c->res->redirect(
357 0 $c->uri_for( '/', $c->stash->{user}->link, '.edit' ) );
358 }
359 else {
360 $c->flash->{message} =
361 0 $c->loc( 'Welcome, x your email is validated. Please log in.',
362 $user->name );
363 0 return $c->res->redirect( $c->uri_for('login') );
364 }
365 0 return;
366 }
367 0 $c->stash->{template} = 'user/validate.tt';
368 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
369  
370 =head2 reconfirm
371  
372 Send the confirmation mail again to another address.
373  
374 =cut
375  
376 0 ▶sub reconfirm : Local {
Subroutine reconfirm: not called CC=4 SCAR=30.0
Pod documented
377 0 my ( $self, $c ) = @_;
378 0 ▶ $c->detach('/default') unless $c->req->method eq 'POST';
Branch: 1 branch
BranchTrueFalseTotal
unless $c->req->method eq "POST" 0 0 0
379 0 ▶ if ( $c->user->obj->email ne $c->req->param('email') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->user->obj->email ne $c->req->param("email")) 0 0 0
380 0 ▶ if ( $c->model('DBIC::Person')
Branch: 1 branch
BranchTrueFalseTotal
if ($c->model("DBIC::Person")->search({"email", $c->req->param("email")})->count) 0 0 0
381 ->search( { email => $c->req->param('email') } )->count )
382 {
383 0 return $c->stash->{error} = $c->loc('That mail is already in use');
384 }
385 }
386 0 my $user = $c->user->obj;
387 0 $user->email( $c->req->params->{email} );
388 0 $user->active(-1);
389 0 $user->update();
390 0 $c->forward( 'do_register', [$user] );
391 0 $c->flash->{message} = $c->loc('confirmation message resent');
392 0 $c->res->redirect( $c->uri_for('/') );
393 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
394  
395 =head2 profile ( .profile )
396  
397 Show user profile.
398  
399 =cut
400  
401 0 ▶sub profile : Global {
Subroutine profile: not called CC=3 SCAR=24.8
Pod documented
402 0 my ( $self, $c ) = @_;
403 0 my $page = $c->stash->{page};
404 my $login = (
405 $c->stash->{proto_pages}[-1]
406 ? $c->stash->{proto_pages}[-1]->{name} # FIXME: why not ->{name_orig}, like in editprofile() ?
407 0 ▶ : $page->name
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'proto_pages'}[-1] ? : 0 0 0
408 );
409 0 my $user = $c->model('DBIC::Person')->get_user($login);
410 0 ▶ if ($user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) { } 0 0 0
411 0 $c->stash->{person} = $user;
412 0 $c->stash->{template} = 'user/profile.tt';
413 }
414 else {
415 0 $c->stash->{template} = 'message.tt';
416 0 $c->stash->{message} = $c->loc( 'User not found: x', $login );
417 }
418 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
419  
420 =head2 editprofile
421  
422 Form to edit a person's profile
423  
424 =cut
425  
426 0 ▶sub editprofile : Global FormConfig {
Subroutine editprofile: not called CC=8 SCAR=42.8
Pod documented
427 0 my ( $self, $c ) = @_;
428 0 my $form = $c->stash->{form};
429 0 my $page = $c->stash->{page};
430 my $login = (
431 $c->stash->{proto_pages}[-1]
432 ? $c->stash->{proto_pages}[-1]->{name_orig}
433 0 ▶ : $page->name
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'proto_pages'}[-1] ? : 0 0 0
434 );
435 0 my $user = $c->model('DBIC::Person')->get_user($login);
436 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($user and $c->stash->{'user'} and $c->stash->{'user'}->is_admin || $user->id eq $c->stash->{'user'}->id) { } 0 0 0
Condition0%0/9
$user and $c->stash->{"user"} and $c->stash->{"user"}->is_admin || $user->id eq $c->stash->{"user"}->id
!ll&&!rl&&r
000
$user and $c->stash->{"user"}
!ll&&!rl&&r
000
$c->stash->{"user"}->is_admin or $user->id eq $c->stash->{"user"}->id
l!l&&r!l&&!r
000
MC/DC0%0/4
$user and $c->stash->{"user"} and $c->stash->{"user"}->is_admin || $user->id eq $c->stash->{"user"}->id
$user $c->stash->{"user"} $c->stash->{"user"}->is_admin $user->id eq $c->stash->{"user"}->id
Truth table0%0/5
A and B and C or D
A= $userB= $c->stash->{"user"}C= $c->stash->{"user"}->is_adminD= $user->id eq $c->stash->{"user"}->id
ABCDresult
0XXX0
10XX0
11000
111X1
11011
437 $user
438 && $c->stash->{user}
439 && ( $c->stash->{user}->is_admin
440 || $user->id eq $c->stash->{user}->id )
441 )
442 {
443 0 ▶ if ( $form->submitted_and_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 0 0 0
444 0 $form->model->update($user);
445 0 $c->res->redirect( $c->uri_for('profile') );
446 }
447 0 ▶ $form->model->default_values($user) unless $form->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $form->submitted 0 0 0
448 }
449 else {
450 0 $c->stash->{template} = 'message.tt';
451 0 $c->stash->{message} = $c->loc('User not found: x', $login);
452 }
453  
454 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
455  
456 =head2 do_editprofile
457  
458 Apply the edits to a person's profile
459  
460 =cut
461  
462 0 ▶sub do_editprofile : Global {
Subroutine do_editprofile: not called CC=4 SCAR=30.0
Pod documented
463 0 my ( $self, $c ) = @_;
464 0 $c->form(
465 required => [qw(name email)],
466 optional => [ $c->model("DBIC::Person")->result_source->columns ],
467 defaults => { gender => undef },
468 constraint_methods =>
469 { born => ymd_to_datetime(qw(birth_year birth_month birth_day)) },
470 untaint_all_constraints => 1,
471 );
472  
473 0 ▶ if ( $c->form->has_missing ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->form->has_missing) { } 0 0 0
elsif ($c->form->has_invalid) { } 0 0 0
474 $c->stash->{message} =
475 0 $c->loc('You have to fill in all required fields.')
476 . $c->loc('the following are missing:') . ' <b>'
477 . join( ', ', $c->form->missing() ) . '</b>';
478 }
479 elsif ( $c->form->has_invalid ) {
480 0 $c->stash->{message} = $c->loc(
481 'Some fields are invalid. Please correct them and try again:');
482 }
483 else {
484 0 my $page = $c->stash->{page};
485 my $user = $c->model('DBIC::Person')->get_user(
486 $c->stash->{proto_pages}[-1]
487 ? $c->stash->{proto_pages}[-1]->{name_orig}
488 0 ▶ : $page->name
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'proto_pages'}[-1] ? : 0 0 0
489 );
490 0 $user->set_columns( $c->form->{valid} );
491 0 $user->update();
492 0 return $c->forward('profile');
493 }
494 0 $c->forward('editprofile');
495 35 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
496  
497 =head1 AUTHOR
498  
499 David Naughton <naughton@cpan.org>,
500 Marcus Ramberg <mramberg@cpan.org>
501  
502 =head1 LICENSE
503  
504 This library is free software. You can redistribute it and/or modify
505 it under the same terms as Perl itself.
506  
507 =cut
508  
509 35 1;
« lib/MojoMojo/Controller/Page.pm ↑ Summary lib/MojoMojo/Controller/Export.pm »