Rubric/WebApp/Login.pm

filter: Statementstmt 88.0% 22 / 25 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 100% 8 / 8 totaltotal 75.8% 44 / 58 CC 7 SCAR 14.9
CC
7
Cov
76%
check_for_login
8.6
get_login_username
2.0
authenticate_login
2.0
CRAP 4.4
« Rubric/User.pm ↑ Summary Rubric/EntryTag.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Rubric::WebApp::Login 0.157;
4 # ABSTRACT: web login processing
5  
6 #pod =head1 DESCRIPTION
7 #pod
8 #pod This module checks for information needed to confirm that a user is logged into
9 #pod the Rubric.
10 #pod
11 #pod =head1 METHODS
12 #pod
13 #pod =head2 Rubric::WebApp::Login->check_for_login($webapp)
14 #pod
15 #pod This method is called by the WebApp's C<cgiapp_init>, and checks for a login
16 #pod attempt in the submitted request.
17 #pod
18 #pod It looks for a login username by calling C<get_login_username>, then converts
19 #pod the login name to a Rubric name by calling C<map_username> and returns
20 #pod immediately if the name can't be shown valid by calling C<valid_username>.
21 #pod
22 #pod It retrieves the User object by calling C<get_login_user> or, if needed,
23 #pod C<autocreate_user>, and returns if it can't get a User object. It tries to
24 #pod authenticate by calling C<authenticate_login>. If the user is authorized but
25 #pod isn't verified, he won't be logged in and the C<user_pending> parameter will be
26 #pod set on the Rubric::WebApp object. Otherwise, he will be logged in with
27 #pod C<set_current_user>.
28 #pod
29 #pod Most of the methods above are virtual methods in this class, and should be
30 #pod implemented in subclasses. The bundled L<Rubric::WebApp::Login::Post> (the
31 #pod default) and L<Rubric::WebApp::Login::HTTP> serve as examples.
32 #pod
33 #pod =cut
34  
35 48 ▶sub check_for_login {
Subroutine check_for_login: called CC=7 SCAR=21.5
Pod documented
36 48 my ($self, $webapp) = @_;
37  
38 48 ▶ return unless my $username = $self->get_login_username($webapp);
Branch: 1 branch
BranchTrueFalseTotal
unless my $username = $self->get_login_username($webapp) 31 17 48
39  
40 17 $username = $self->map_username($username);
41 17 ▶ return unless $self->valid_username($username);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid_username($username) 0 17 17
42 17 ▶ return unless my $user =
Branch: 1 branch
BranchTrueFalseTotal
unless my $user = $self->get_login_user($username) || $self->autocreate_user($username) 0 17 17
Condition33%1/3
$self->get_login_user($username) || $self->autocreate_user($username)
l!l&&r!l&&!r
1700
MC/DC0%0/2
$self->get_login_user($username) || $self->autocreate_user($username)
$self->get_login_user($username) $self->autocreate_user($username)
Truth table33%1/3
A || B
A= $self->get_login_user($username)B= $self->autocreate_user($username)
ABresult
1X1
011
000
43 $self->get_login_user($username) || $self->autocreate_user($username);
44 17 ▶ return unless $self->authenticate_login($webapp, $user);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->authenticate_login($webapp, $user) 0 17 17
45 17 ▶ if ($user->verification_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user->verification_code) { } 0 17 17
46 0 $webapp->param('user_pending', 1);
47 } else {
48 17 $self->set_current_user($webapp, $user);
49 }
50 }
51  
52 #pod =head2 get_login_username($webapp)
53 #pod
54 #pod This method returns the login username taken from the request. It is not
55 #pod necessarily the name of a Rubric user (see C<map_username>).
56 #pod
57 #pod This must be implemented by the login subclass.
58 #pod
59 #pod =cut
60  
61 0 ▶sub get_login_username { die "get_login_username unimplemented" }
Subroutine get_login_username: not called CC=1 SCAR=6.9
Pod documented
62  
63 #pod =head2 map_username($username)
64 #pod
65 #pod This method returns the Rubric username to which the login name maps. By
66 #pod default, it returns the C<$username> verbatim.
67 #pod
68 #pod =cut
69  
70 17 ▶sub map_username { $_[1] }
Subroutine map_username: called CC=1 SCAR=0.0
Pod documented
71  
72 #pod =head2 valid_username($username)
73 #pod
74 #pod Returns a true or false value, depending on whether the given username string
75 #pod is a valid username.
76 #pod
77 #pod =cut
78  
79 17 ▶sub valid_username {
Subroutine valid_username: called CC=1 SCAR=0.0
Pod documented
80 17 my ($self, $username) = @_;
81 17 $username =~ /^[\pL\d_]+$/;
82 }
83  
84 #pod =head2 get_login_user($username)
85 #pod
86 #pod Given a username, this method returns the Rubric::User object for the user.
87 #pod
88 #pod =cut
89  
90 17 ▶sub get_login_user {
Subroutine get_login_user: called CC=1 SCAR=0.0
Pod documented
91 17 my ($self, $username) = @_;
92 17 Rubric::User->retrieve($username);
93 }
94  
95 #pod =head2 autocreate_user($username)
96 #pod
97 #pod If C<get_login_user> can't find a user, this method is called to try to create
98 #pod the user automatically. By default, it always returns nothing. It may be
99 #pod subclassed for implementation. (For example, one could create domain users
100 #pod from a directory.)
101 #pod
102 #pod =cut
103  
104 0 ▶sub autocreate_user { }
Subroutine autocreate_user: not called CC=1 SCAR=0.0
Pod documented
105  
106 #pod =head2 authenticate_login($webapp, $user)
107 #pod
108 #pod This method attempts to authenticate the user's login, checking the given
109 #pod password or performing any other needed check. It returns true or false.
110 #pod
111 #pod This must be implemented by the login subclass.
112 #pod
113 #pod =cut
114  
115 0 ▶sub authenticate_login { die "authenticate_login unimplemented" }
Subroutine authenticate_login: not called CC=1 SCAR=6.9
Pod documented
116  
117 #pod =head2 set_current_user($webapp, $user)
118 #pod
119 #pod This method sets the current user on the WebApp by setting the WebApp's
120 #pod "current_user" attribute to the Rubric::User object.
121 #pod
122 #pod =cut
123  
124 17 ▶sub set_current_user {
Subroutine set_current_user: called CC=1 SCAR=0.0
Pod documented
125 17 my ($self, $webapp, $user) = @_;
126  
127 17 $webapp->param(current_user => $user);
128 }
129  
130 2 1;
131  
132 __END__
« Rubric/User.pm ↑ Summary Rubric/EntryTag.pm »