| 1 | package CAM::UserApp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | CAM::UserApp - Extension of CAM::App to support web login | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Copyright 2005 Clotho Advanced Media, Inc., <cpan@clotho.com> | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | This library is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | CAM::UserApp provides generic session-based login capabilities. It | ||||||||||||||||||||||||||||
| 17 | supports login, state maintenance and password changing in a framework | ||||||||||||||||||||||||||||
| 18 | that supports either SOAP or cookie-based HTML, among other | ||||||||||||||||||||||||||||
| 19 | possibilities. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | CAM::UserApp is not complete by itself. Some of its methods must be | ||||||||||||||||||||||||||||
| 22 | implemented by a subclass. In particular, retrieveUser() must be | ||||||||||||||||||||||||||||
| 23 | supplied. In an HTML or other human-interaction environment, the | ||||||||||||||||||||||||||||
| 24 | offerLogin() and offerChangePassword() methods should be implemented. | ||||||||||||||||||||||||||||
| 25 | Others are optional, and are described below. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | A nearly-complete example subclass: | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | package MyApp; | ||||||||||||||||||||||||||||
| 32 | use CAM::UserApp; | ||||||||||||||||||||||||||||
| 33 | our @ISA=qw(CAM::UserApp); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub retrieveUser { | ||||||||||||||||||||||||||||
| 36 | my ($self, $user, $pass) = @_; | ||||||||||||||||||||||||||||
| 37 | # (do some SQL lookup perhaps) | ||||||||||||||||||||||||||||
| 38 | my $user = Some::Pkg->new($user, $pass); | ||||||||||||||||||||||||||||
| 39 | return $user; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub offerLogin { | ||||||||||||||||||||||||||||
| 43 | my ($self, %args) = @_; | ||||||||||||||||||||||||||||
| 44 | print $self->header(); | ||||||||||||||||||||||||||||
| 45 | $self->getTemplate("login.tmpl", | ||||||||||||||||||||||||||||
| 46 | error=>$args{error}, | ||||||||||||||||||||||||||||
| 47 | passthru=>$args{passthru}) | ||||||||||||||||||||||||||||
| 48 | ->print(); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub offerChangePassword { | ||||||||||||||||||||||||||||
| 52 | my ($self, %args) = @_; | ||||||||||||||||||||||||||||
| 53 | print $self->header(); | ||||||||||||||||||||||||||||
| 54 | $self->getTemplate("changePass.tmpl", error=>$args{error}) | ||||||||||||||||||||||||||||
| 55 | ->print(); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 1; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | A CGI script that uses CAM::UserApp through that subclass: | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | #!perl | ||||||||||||||||||||||||||||
| 62 | use Config; | ||||||||||||||||||||||||||||
| 63 | use MyApp; | ||||||||||||||||||||||||||||
| 64 | my $app = MyApp->new(config => Config->new()); | ||||||||||||||||||||||||||||
| 65 | $app->authenticate() or exit(0); | ||||||||||||||||||||||||||||
| 66 | my $user = $app->getUser(); | ||||||||||||||||||||||||||||
| 67 | if ($app->getCGI()->param('logout')) { | ||||||||||||||||||||||||||||
| 68 | $app->deauthenticate(); | ||||||||||||||||||||||||||||
| 69 | exit(0); | ||||||||||||||||||||||||||||
| 70 | } elsif ($app->getCGI()->param('changepass')) { | ||||||||||||||||||||||||||||
| 71 | $app->changePassword($user->getUsername()) or exit(0); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | print $app->header(); | ||||||||||||||||||||||||||||
| 75 | print "Welcome " . $user->getName() . "!\n"; | ||||||||||||||||||||||||||||
| 76 | ... | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Note that the class for $user is not defined here. You must build | ||||||||||||||||||||||||||||
| 79 | that yourself. The new() and getName() and getUsername() methods | ||||||||||||||||||||||||||||
| 80 | shown above are for example only. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Note that authentication is performed separately from initialization | ||||||||||||||||||||||||||||
| 83 | for the sake of applications where login is optional. If your | ||||||||||||||||||||||||||||
| 84 | application requires login, we recommend that your CAM::UserApp | ||||||||||||||||||||||||||||
| 85 | subclass include methods like the following in addition to those shown | ||||||||||||||||||||||||||||
| 86 | in the subclass above. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | use Config; | ||||||||||||||||||||||||||||
| 89 | sub new { | ||||||||||||||||||||||||||||
| 90 | my $pkg = shift; | ||||||||||||||||||||||||||||
| 91 | return $pkg->SUPER::new(config => Config->new(), | ||||||||||||||||||||||||||||
| 92 | needPassword => 1, @_); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | sub init { | ||||||||||||||||||||||||||||
| 95 | my $self = shift; | ||||||||||||||||||||||||||||
| 96 | $self->SUPER::init() or return undef; | ||||||||||||||||||||||||||||
| 97 | $self->authenticate() or exit(0); | ||||||||||||||||||||||||||||
| 98 | if ($app->getCGI()->param('logout')) { | ||||||||||||||||||||||||||||
| 99 | $app->deauthenticate(); | ||||||||||||||||||||||||||||
| 100 | exit(0); | ||||||||||||||||||||||||||||
| 101 | } elsif ($app->getCGI()->param('changepass')) { | ||||||||||||||||||||||||||||
| 102 | $app->changePassword($app->getUser()->getUsername()) or exit(0); | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | return $self; | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Thus your CGI could look as simple as: | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | #!perl | ||||||||||||||||||||||||||||
| 110 | use MyApp; | ||||||||||||||||||||||||||||
| 111 | my $app = MyApp->new(); | ||||||||||||||||||||||||||||
| 112 | print $app->header(); | ||||||||||||||||||||||||||||
| 113 | print "Welcome " . $app->getUser()->getName() . "!\n"; | ||||||||||||||||||||||||||||
| 114 | ... | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | while still including full login support. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #--------------------------------# | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | require 5.005_62; | |||||||||||||||||||||||||||
| 123 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | 1 | ▶ | use CAM::App; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | our @ISA = qw(CAM::App); | |||||||||||||||||||||||||||
| 128 | 1 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | #--------------------------------# | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =over 4 | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | #--------------------------------# | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item usernameCGIKey | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =item passwordCGIKey | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item password1CGIKey | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =item password2CGIKey | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Simple accessors that return the CGI parameter names used to input | ||||||||||||||||||||||||||||
| 149 | login details. These are provided so they can be overrided by | ||||||||||||||||||||||||||||
| 150 | subclasses. The defaults are: | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | usernameCGIKey "username" | ||||||||||||||||||||||||||||
| 153 | passwordCGIKey "password" | ||||||||||||||||||||||||||||
| 154 | password1CGIKey "password1" | ||||||||||||||||||||||||||||
| 155 | password2CGIKey "password2" | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | username and password are used for input to authenticate() while | ||||||||||||||||||||||||||||
| 158 | password1, password2 and (optionally) password are used for | ||||||||||||||||||||||||||||
| 159 | changePassword(). | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub usernameCGIKey { "username" } | ||||||||||||||||||||||||||
|
Subroutine
usernameCGIKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub passwordCGIKey { "password" } | ||||||||||||||||||||||||||
|
Subroutine
passwordCGIKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub password1CGIKey { "password1" } | ||||||||||||||||||||||||||
|
Subroutine
password1CGIKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub password2CGIKey { "password2" } | ||||||||||||||||||||||||||
|
Subroutine
password2CGIKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | #--------------------------------# | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item new [argument list...] | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Overrides the superclass constructor to add boolean settings. These | ||||||||||||||||||||||||||||
| 173 | settings are used in the authenticate() and changePassword() methods | ||||||||||||||||||||||||||||
| 174 | below. Both of those methods allow callers to override this value | ||||||||||||||||||||||||||||
| 175 | directly if desired. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | All other arguments are passed on the to the superclass constructor. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | interactive => boolean (default: true) | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | If true, login or change password failures yield calls to offerLogin() | ||||||||||||||||||||||||||||
| 182 | or offerChangePassword(), respectively. If false, these calls are | ||||||||||||||||||||||||||||
| 183 | skipped. The equivalent effect to interactive = false can be achieved | ||||||||||||||||||||||||||||
| 184 | by using a no-op offerLogin() or offerChangePassword(), which are in | ||||||||||||||||||||||||||||
| 185 | fact the default behaviors for those functions. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | useCGI => boolean (default: true) | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Specifies whether the CGI parameters should be consulted for username | ||||||||||||||||||||||||||||
| 190 | and password values, if any. CGI values override session values. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | useSession => boolean (default: true) | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Specifies whether the session record should be consulted for username | ||||||||||||||||||||||||||||
| 195 | and password values, if any. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | needPassword => boolean (default: false) | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | Specifies whether the user has to enter their old password before a | ||||||||||||||||||||||||||||
| 200 | new one can be set in changePassword(). While it defaults to the lax | ||||||||||||||||||||||||||||
| 201 | 'false' state, I recommend you set this to true for interactive | ||||||||||||||||||||||||||||
| 202 | applications! | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub new | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 0 | my $pkg = shift; | |||||||||||||||||||||||||||
| 209 | 0 | my %params = (@_); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $self = $pkg->SUPER::new(%params); | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | $self->{useCGI} = exists $params{useCGI} ? $params{useCGI} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $self->{useSession} = exists $params{useSession} ? $params{useSession} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $self->{needPassword} = exists $params{needPassword} ? $params{needPassword} : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $self->{interactive} = exists $params{interactive} ? $params{interactive} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | return $self; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | #--------------------------------# | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =back | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =head1 INSTANCE METHODS | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =over 4 | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =cut | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | #--------------------------------# | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =item retrieveUser USERNAME, PASSWORD | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | This method MUST be overridden by a subclass, or authenticate() will | ||||||||||||||||||||||||||||
| 233 | never succeed. It should return an object for the specified username | ||||||||||||||||||||||||||||
| 234 | and password, or undef if there is no such user. The object can be of | ||||||||||||||||||||||||||||
| 235 | any class as long as: 1) it is blessed, 2) it has a | ||||||||||||||||||||||||||||
| 236 | recordPassword($password) method that can be called from our | ||||||||||||||||||||||||||||
| 237 | changePassword() function. Note that this method MAY be called | ||||||||||||||||||||||||||||
| 238 | multiple times during a session, so don't do hit counting in here. | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =cut | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | sub retrieveUser | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
retrieveUser: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 245 | 0 | my $username = shift; | |||||||||||||||||||||||||||
| 246 | 0 | my $password = shift; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | my $user; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # Do something here: | ||||||||||||||||||||||||||||
| 251 | # Get a user object (likely a database record) | ||||||||||||||||||||||||||||
| 252 | # Make a record of the login? | ||||||||||||||||||||||||||||
| 253 | # Tweak the user object? | ||||||||||||||||||||||||||||
| 254 | # Return undef if retrieval fails | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # The returned object should have a recordPassword() method | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | return $user; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | #--------------------------------# | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | =item authenticate | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | Validate a login. Returns a boolean indicating success. Most | ||||||||||||||||||||||||||||
| 265 | applications should abort upon receiving a false response. If the | ||||||||||||||||||||||||||||
| 266 | login fails, or if username/password parameters are missing, the | ||||||||||||||||||||||||||||
| 267 | offerLogin() method is called before false is returned. For this | ||||||||||||||||||||||||||||
| 268 | method to succeed, the retrieveUser() method MUST be implemented by a | ||||||||||||||||||||||||||||
| 269 | subclass. After success, the getUser() method will return the cached | ||||||||||||||||||||||||||||
| 270 | result from retrieveUser(). | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | Optional arguments: | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | username => string (default: undef) | ||||||||||||||||||||||||||||
| 275 | password => string (default: undef) | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | Values to use for login. Overrides CGI and session values. | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | useCGI => boolean | ||||||||||||||||||||||||||||
| 280 | useSession => boolean | ||||||||||||||||||||||||||||
| 281 | interactive => boolean | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | These values, if not passed as arguments, are inherited from the | ||||||||||||||||||||||||||||
| 284 | CAM::UserApp instance. | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | =cut | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | sub authenticate | ||||||||||||||||||||||||||||
| 289 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
authenticate: not called CC=26 SCAR=65.5
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 291 | 0 | my %args = (@_); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | my $session; | |||||||||||||||||||||||||||
| 294 | my $cgi; | ||||||||||||||||||||||||||||
| 295 | 0 | my $passthru = ""; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | foreach my $key ("useCGI", "useSession", "interactive") | |||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | $args{$key} = $self->{$key} unless (exists $args{$key}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ($args{useCGI}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||
| 304 | 0 | $cgi = $self->getCGI(); | |||||||||||||||||||||||||||
| 305 | 0 | ▶ | $args{username} ||= $cgi->param($self->usernameCGIKey()); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"username"} ||= $cgi->param($self->usernameCGIKey)
MC/DC0%0/2
$args{"username"} ||= $cgi->param($self->usernameCGIKey)
$args{"username"}
$cgi->param($self->usernameCGIKey)
Truth table0%0/3
A ||= B
A= $args{"username"}B= $cgi->param($self->usernameCGIKey)
| |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $args{password} ||= $cgi->param($self->passwordCGIKey()); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"password"} ||= $cgi->param($self->passwordCGIKey)
MC/DC0%0/2
$args{"password"} ||= $cgi->param($self->passwordCGIKey)
$args{"password"}
$cgi->param($self->passwordCGIKey)
Truth table0%0/3
A ||= B
A= $args{"password"}B= $cgi->param($self->passwordCGIKey)
| |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||
| 309 | 0 | foreach my $key ($cgi->param) | |||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | next if ($key eq $self->usernameCGIKey() || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq $self->usernameCGIKey or $key eq $self->passwordCGIKey
MC/DC0%0/2
$key eq $self->usernameCGIKey or $key eq $self->passwordCGIKey
$key eq $self->usernameCGIKey
$key eq $self->passwordCGIKey
Truth table0%0/3
A or B
A= $key eq $self->usernameCGIKeyB= $key eq $self->passwordCGIKey
| |||||||||||||||||||||||||||||
| 312 | $key eq $self->passwordCGIKey()); | ||||||||||||||||||||||||||||
| 313 | 0 | my $hkey = $cgi->escapeHTML($key); | |||||||||||||||||||||||||||
| 314 | 0 | foreach my $value ($cgi->param($key)) | |||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $value = "" if (!defined $value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 0 | my $hvalue = $cgi->escapeHTML($value); | |||||||||||||||||||||||||||
| 318 | 0 | $passthru .= qq[<input type="hidden" name="$hkey" value="$hvalue">]; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($args{useSession}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | 0 | $session = $self->getSession(); | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | unless ($session->isNewSession()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | $args{username} ||= $session->get("username"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"username"} ||= $session->get("username")
MC/DC0%0/2
$args{"username"} ||= $session->get("username")
$args{"username"}
$session->get("username")
Truth table0%0/3
A ||= B
A= $args{"username"}B= $session->get("username")
| |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $args{password} ||= $session->get("password"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"password"} ||= $session->get("password")
MC/DC0%0/2
$args{"password"} ||= $session->get("password")
$args{"password"}
$session->get("password")
Truth table0%0/3
A ||= B
A= $args{"password"}B= $session->get("password")
| |||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | ▶ | unless ($args{username} || $args{password}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"username"} or $args{"password"}
MC/DC0%0/2
$args{"username"} or $args{"password"}
$args{"username"}
$args{"password"}
Truth table0%0/3
A or B
A= $args{"username"}B= $args{"password"}
| |||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||
| 337 | 0 | $self->offerLogin(passthru => $passthru); | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | 0 | return undef; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 0 | ▶ | unless ($args{username}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||
| 346 | 0 | $self->offerLogin(error => "Please enter your username", | |||||||||||||||||||||||||||
| 347 | passthru => $passthru); | ||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | 0 | return undef; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | unless ($args{password}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||
| 356 | 0 | $self->offerLogin(error => "Please enter your password", | |||||||||||||||||||||||||||
| 357 | passthru => $passthru); | ||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | 0 | return undef; | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | my $user = $self->retrieveUser($args{username}, $args{password}); | |||||||||||||||||||||||||||
| 363 | 0 | ▶ | unless ($user) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||
| 367 | 0 | $self->offerLogin(error => "Login failed", | |||||||||||||||||||||||||||
| 368 | passthru => $passthru); | ||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | 0 | return undef; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | $self->{User} = $user; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ($session) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||
| 377 | $session->set(username => $args{username}, | ||||||||||||||||||||||||||||
| 378 | 0 | password => $args{password}); | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 0 | return $self; | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | #--------------------------------# | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =item getUser | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | Returns the User object obtained from authenticate(). If | ||||||||||||||||||||||||||||
| 389 | authentication fails, or is never attempted, this method will return | ||||||||||||||||||||||||||||
| 390 | undef. | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =cut | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | sub getUser | ||||||||||||||||||||||||||||
| 395 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getUser: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 396 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 397 | 0 | return $self->{User}; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | #--------------------------------# | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | =item deauthenticate | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | Logs out an authenticated user. If a session is present, it is wiped. | ||||||||||||||||||||||||||||
| 404 | After this, the getUser() will return undef. This method returns | ||||||||||||||||||||||||||||
| 405 | self. | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | Optional arguments: | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | useSession => boolean (default: true) | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | Specifies whether the session record should be cleared. | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | interactive => boolean (default: true) | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | If true, the offerLogin() method is called at the end of | ||||||||||||||||||||||||||||
| 416 | deauthentication. | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | =cut | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | sub deauthenticate | ||||||||||||||||||||||||||||
| 421 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
deauthenticate: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 422 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 423 | 0 | my %args = (@_); | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | ▶ | $args{useSession} = 1 unless (exists $args{useSession}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $args{interactive} = 1 unless (exists $args{interactive}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ($args{useSession}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||
| 430 | 0 | my $session = $self->getSession(); | |||||||||||||||||||||||||||
| 431 | 0 | ▶ | if ($session) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||
| 433 | 0 | $session->clear(); | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | 0 | delete $self->{User}; | |||||||||||||||||||||||||||
| 437 | 0 | ▶ | if ($args{interactive}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||
| 439 | 0 | $self->offerLogin(); | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | 0 | return $self; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | #--------------------------------# | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | =item changePassword | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | Change the users password. The user must already be authenticated. | ||||||||||||||||||||||||||||
| 449 | If the new password is missing or invalid or if the retyped value does | ||||||||||||||||||||||||||||
| 450 | not match, this calls offerChangePassword and returns undef. If the | ||||||||||||||||||||||||||||
| 451 | needPassword flag is set, the old password must be entered. It will | ||||||||||||||||||||||||||||
| 452 | be validated via the retrieveUser() method. | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | Optional arguments: | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | username => string (default: undef) | ||||||||||||||||||||||||||||
| 457 | password => string (default: undef) | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | Values to use for authentication if needPassword is true. Overrides | ||||||||||||||||||||||||||||
| 460 | CGI values. | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | password1 => string (default: undef) | ||||||||||||||||||||||||||||
| 463 | password2 => string (default: undef) | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | Values to use for the new password and password verification. | ||||||||||||||||||||||||||||
| 466 | Overrides CGI values. | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | interactive => boolean | ||||||||||||||||||||||||||||
| 469 | useCGI => boolean | ||||||||||||||||||||||||||||
| 470 | useSession => boolean | ||||||||||||||||||||||||||||
| 471 | needPassword => boolean | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | These values, if not passed as arguments, are inherited from the | ||||||||||||||||||||||||||||
| 474 | CAM::UserApp instance. | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =cut | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | sub changePassword | ||||||||||||||||||||||||||||
| 479 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
changePassword: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||
| 480 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 481 | 0 | my %args = (@_); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | foreach my $key ("useCGI", "useSession", "interactive", "needPassword") | |||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||
| 485 | 0 | ▶ | $args{$key} = $self->{$key} unless (exists $args{$key}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 0 | my $user = $self->getUser(); | |||||||||||||||||||||||||||
| 489 | 0 | my $cgi; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | if ($args{useCGI}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | { | ||||||||||||||||||||||||||||
| 493 | 0 | $cgi = $self->getCGI(); | |||||||||||||||||||||||||||
| 494 | 0 | ▶ | $args{password} ||= $cgi->param($self->passwordCGIKey()); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"password"} ||= $cgi->param($self->passwordCGIKey)
MC/DC0%0/2
$args{"password"} ||= $cgi->param($self->passwordCGIKey)
$args{"password"}
$cgi->param($self->passwordCGIKey)
Truth table0%0/3
A ||= B
A= $args{"password"}B= $cgi->param($self->passwordCGIKey)
| |||||||||||||||||||||||||||||
| 495 | 0 | ▶ | $args{password1} ||= $cgi->param($self->password1CGIKey()); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"password1"} ||= $cgi->param($self->password1CGIKey)
MC/DC0%0/2
$args{"password1"} ||= $cgi->param($self->password1CGIKey)
$args{"password1"}
$cgi->param($self->password1CGIKey)
Truth table0%0/3
A ||= B
A= $args{"password1"}B= $cgi->param($self->password1CGIKey)
| |||||||||||||||||||||||||||||
| 496 | 0 | ▶ | $args{password2} ||= $cgi->param($self->password2CGIKey()); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"password2"} ||= $cgi->param($self->password2CGIKey)
MC/DC0%0/2
$args{"password2"} ||= $cgi->param($self->password2CGIKey)
$args{"password2"}
$cgi->param($self->password2CGIKey)
Truth table0%0/3
A ||= B
A= $args{"password2"}B= $cgi->param($self->password2CGIKey)
| |||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 0 | ▶ | unless ($args{password1} || $args{password2}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"password1"} or $args{"password2"}
MC/DC0%0/2
$args{"password1"} or $args{"password2"}
$args{"password1"}
$args{"password2"}
Truth table0%0/3
A or B
A= $args{"password1"}B= $args{"password2"}
| |||||||||||||||||||||||||||||
| 500 | { | ||||||||||||||||||||||||||||
| 501 | 0 | $self->offerChangePassword(); | |||||||||||||||||||||||||||
| 502 | 0 | return undef; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | ▶ | unless ($args{password1} && $args{password2}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"password1"} and $args{"password2"}
MC/DC0%0/2
$args{"password1"} and $args{"password2"}
$args{"password1"}
$args{"password2"}
Truth table0%0/3
A and B
A= $args{"password1"}B= $args{"password2"}
| |||||||||||||||||||||||||||||
| 506 | { | ||||||||||||||||||||||||||||
| 507 | 0 | $self->offerChangePassword(error => "Please fill in all password fields"); | |||||||||||||||||||||||||||
| 508 | 0 | return undef; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if ($args{needPassword}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | { | ||||||||||||||||||||||||||||
| 513 | 0 | ▶ | unless ($args{password}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | { | ||||||||||||||||||||||||||||
| 515 | 0 | $self->offerChangePassword(error => "Please fill in all password fields"); | |||||||||||||||||||||||||||
| 516 | 0 | return undef; | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | 0 | ▶ | unless ($args{username}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 519 | { | ||||||||||||||||||||||||||||
| 520 | 0 | $self->offerChangePassword(error => "Error: no username found"); | |||||||||||||||||||||||||||
| 521 | 0 | return undef; | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | 0 | ▶ | unless ($self->retrieveUser($args{username}, $args{password})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | { | ||||||||||||||||||||||||||||
| 525 | 0 | $self->offerChangePassword(error => "Incorrect password"); | |||||||||||||||||||||||||||
| 526 | 0 | return undef; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if ($args{password1} ne $args{password2}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | { | ||||||||||||||||||||||||||||
| 532 | 0 | $self->offerChangePassword(error => "The passwords you have entered do not match"); | |||||||||||||||||||||||||||
| 533 | 0 | return undef; | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 0 | my $password = $args{password1}; # shorthand | |||||||||||||||||||||||||||
| 537 | 0 | ▶ | unless ($self->validateNewPassword($password)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | { | ||||||||||||||||||||||||||||
| 539 | 0 | $self->offerChangePassword(error => "Invalid password, please try again"); | |||||||||||||||||||||||||||
| 540 | 0 | return undef; | |||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | ▶ | unless ($user->can("recordPassword") && $user->recordPassword($password)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user->can("recordPassword") and $user->recordPassword($password)
MC/DC0%0/2
$user->can("recordPassword") and $user->recordPassword($password)
$user->can("recordPassword")
$user->recordPassword($password)
Truth table0%0/3
A and B
A= $user->can("recordPassword")B= $user->recordPassword($password)
| |||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||
| 545 | 0 | $self->offerChangePassword(error => "Unable to record your new password"); | |||||||||||||||||||||||||||
| 546 | 0 | return undef; | |||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 0 | ▶ | if ($args{useSession}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||
| 551 | # Note! We DO NOT want to create a new session here, so we don't | ||||||||||||||||||||||||||||
| 552 | # use the getSession() method. If there is no session, well, so | ||||||||||||||||||||||||||||
| 553 | # be it. | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 0 | my $session = $self->{session}; | |||||||||||||||||||||||||||
| 556 | 0 | ▶ | if ($session) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 557 | { | ||||||||||||||||||||||||||||
| 558 | 0 | $session->set(password => $password); | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 0 | return $self; | |||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | #--------------------------------# | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | =item offerLogin | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | Display an interactive login. By default, this method is a no-op. | ||||||||||||||||||||||||||||
| 569 | Interactive subclasses should override this method. The return value | ||||||||||||||||||||||||||||
| 570 | of this method is not used. A sample implementation is presented in | ||||||||||||||||||||||||||||
| 571 | the Synopsis above. | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | Optional arguments: | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | error => string | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | Indicates a reason why this method has been called, like "Login | ||||||||||||||||||||||||||||
| 578 | failure". On a fresh login, this argument is absent. | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | passthru => string | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | An accumulation of CGI parameters passed to this program, in the form | ||||||||||||||||||||||||||||
| 583 | of '<input type=hidden name=key value=value>' for each parameter. | ||||||||||||||||||||||||||||
| 584 | Implementations are welcome to ignore this, but they should pass it | ||||||||||||||||||||||||||||
| 585 | via an HTML form if they want to make the login be 'transparent', | ||||||||||||||||||||||||||||
| 586 | i.e., if the program should go back to whatever it was doing before | ||||||||||||||||||||||||||||
| 587 | when login is successful login. | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | Here's an example HTML template file for use with the offerLogin() | ||||||||||||||||||||||||||||
| 590 | implementation in the Synopsis above, using these parameters: | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | <html><head><title>Login</title></head><body> | ||||||||||||||||||||||||||||
| 593 | <form action="::myURL::" method="post"> | ||||||||||||||||||||||||||||
| 594 | ??error?? <span style="color:red">::error::</span> <br> ??error?? | ||||||||||||||||||||||||||||
| 595 | Username: <input type="text" name="username"><br> | ||||||||||||||||||||||||||||
| 596 | Password: <input type="password" name="password"><br> | ||||||||||||||||||||||||||||
| 597 | <input type="submit" value="Login"> | ||||||||||||||||||||||||||||
| 598 | ::passthru:: | ||||||||||||||||||||||||||||
| 599 | </form></body></html> | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | =cut | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | sub offerLogin | ||||||||||||||||||||||||||||
| 604 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
offerLogin: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 605 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 606 | 0 | my %args = (@_); | |||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | # do nothing unless subclass overrides | ||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | #--------------------------------# | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | =item offerChangePassword | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | Display an interactive password change screen. By default, this | ||||||||||||||||||||||||||||
| 615 | method is a no-op, so interactive subclasses should override this | ||||||||||||||||||||||||||||
| 616 | method. The return value of this method is not used. A sample | ||||||||||||||||||||||||||||
| 617 | implementation is presented in the Synopsis above. | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | Optional arguments: | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | error => string | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | Indicates a reason why this method has been called, like "Passwords do | ||||||||||||||||||||||||||||
| 624 | not match". On first hit, this argument is absent. | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | Here's an example HTML template file for use with the | ||||||||||||||||||||||||||||
| 627 | offerChangePassword() implementation in the Synopsis above, using | ||||||||||||||||||||||||||||
| 628 | this parameters: | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | <html><head><title>Change Password</title></head><body> | ||||||||||||||||||||||||||||
| 631 | <form action="::myURL::" method="post"> | ||||||||||||||||||||||||||||
| 632 | ??error?? <span style="color:red">::error::</span> <br> ??error?? | ||||||||||||||||||||||||||||
| 633 | Old Password: <input type="password" name="password"><br> | ||||||||||||||||||||||||||||
| 634 | New Password: <input type="password" name="password1"><br> | ||||||||||||||||||||||||||||
| 635 | Retype Password: <input type="password" name="password2"><br> | ||||||||||||||||||||||||||||
| 636 | <input type="submit" value="Submit"> | ||||||||||||||||||||||||||||
| 637 | </form></body></html> | ||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | =cut | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | sub offerChangePassword | ||||||||||||||||||||||||||||
| 642 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
offerChangePassword: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 643 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 644 | 0 | my %args = (@_); | |||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | # do nothing unless subclass overrides | ||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | #--------------------------------# | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | =item validateNewPassword PASSWORD | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | Performs simple checks on the validity of a new password. This | ||||||||||||||||||||||||||||
| 653 | implementation only checks that the password is defined and not the | ||||||||||||||||||||||||||||
| 654 | null string. Subclasses may implement more rigorous checks. | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | =cut | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | sub validateNewPassword | ||||||||||||||||||||||||||||
| 659 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validateNewPassword: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 660 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 661 | 0 | my $password = shift; | |||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | 0 | ▶ | return undef unless (defined $password && $password ne ""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $password and $password ne ""
MC/DC0%0/2
defined $password and $password ne ""
defined $password
$password ne ""
Truth table0%0/3
A and B
A= defined $passwordB= $password ne ""
| |||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 0 | return $self; | |||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||
| 667 | #--------------------------------# | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | 1 | 1; | |||||||||||||||||||||||||||
| 670 | __END__ | ||||||||||||||||||||||||||||