| 1 | package Labyrinth::Users; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | $VERSION = '5.32'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Labyrinth::Users - Generic User Management for Labyrinth | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Contains generic user functionality that are required across the Labyrinth | ||||||||||||||||||||||||||||
| 16 | framework, and may be used within plugins. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 21 | # Export Details | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 12 | require Exporter; | |||||||||||||||||||||||||||
| 24 | 12 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 12 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 27 | 'all' => [ qw( GetUser UserName UserID FreshPassword PasswordCheck UserSelect ) ] | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 12 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 31 | 12 | @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 34 | # Library Modules | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | ▶ | use Labyrinth::Audit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 12 | ▶ | use Labyrinth::Globals; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 12 | ▶ | use Labyrinth::DBUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 12 | ▶ | use Labyrinth::MLUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 12 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 12 | ▶ | use Session::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 45 | # Variables | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 12 | my (%users,%userids); # quick lookup hashes | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 50 | # The Subs | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 PUBLIC INTERFACE METHODS | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =over 4 | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item GetUser($id) | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Given a user id, performs a database lookup, unless a previous lookup for the | ||||||||||||||||||||||||||||
| 59 | same id has already been requested. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =item UserName($id) | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Given a user id, returns the user's name. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item UserID | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Given a user's name (real name or nick name), returns the user id. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item FreshPassword | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Returns a generated password string. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item PasswordCheck | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Checks the given password against the required rules. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub GetUser { | ||||||||||||||||||||||||||
|
Subroutine
GetUser: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $uid = shift; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | return unless($uid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $users{$uid} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$users{$uid} ||= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByID", $uid);
$rows[0] if @rows
}
MC/DC0%0/2
$users{$uid} ||= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByID", $uid);
$rows[0] if @rows
}
$users{$uid}
do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByID", $uid);
$rows[0] if @rows
}
Truth table0%0/3
A ||= B
A= $users{$uid}B= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByID", $uid);
$rows[0] if @rows
}
| |||||||||||||||||||||||||||||
| 86 | 0 | my @rows = $dbi->GetQuery('hash','GetUserByID',$uid); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | $rows[0] if(@rows); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | return $users{$uid}; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub UserName { | ||||||||||||||||||||||||||
|
Subroutine
UserName: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $uid = shift; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | return unless($uid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $user = GetUser($uid); | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | return $user->{realname} || $user->{nickname}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$user->{'realname'} || $user->{'nickname'}
MC/DC0%0/2
$user->{'realname'} || $user->{'nickname'}
$user->{'realname'}
$user->{'nickname'}
Truth table0%0/3
A || B
A= $user->{'realname'}B= $user->{'nickname'}
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub UserID { | ||||||||||||||||||||||||||
|
Subroutine
UserID: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | return unless($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $userids{$name} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$userids{$name} ||= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByName", $name);
return unless @rows;
$users{$rows[0]{"userid"}} ||= $rows[0];
$rows[0]{"userid"}
}
MC/DC0%0/2
$userids{$name} ||= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByName", $name);
return unless @rows;
$users{$rows[0]{"userid"}} ||= $rows[0];
$rows[0]{"userid"}
}
$userids{$name}
do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByName", $name);
return unless @rows;
$users{$rows[0]{"userid"}} ||= $rows[0];
$rows[0]{"userid"}
}
Truth table0%0/3
A ||= B
A= $userids{$name}B= do {
my(@rows) = $Labyrinth::Users::dbi->GetQuery("hash", "GetUserByName", $name);
return unless @rows;
$users{$rows[0]{"userid"}} ||= $rows[0];
$rows[0]{"userid"}
}
| |||||||||||||||||||||||||||||
| 106 | 0 | my @rows = $dbi->GetQuery('hash','GetUserByName',$name); | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | return unless(@rows); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $users{$rows[0]->{userid}} ||= $rows[0]; | ||||||||||||||||||||||||||
|
Condition0%0/3
$users{$rows[0]{"userid"}} ||= $rows[0]
MC/DC0%0/2
$users{$rows[0]{"userid"}} ||= $rows[0]
$users{$rows[0]{"userid"}}
$rows[0]
Truth table0%0/3
A ||= B
A= $users{$rows[0]{"userid"}}B= $rows[0]
| |||||||||||||||||||||||||||||
| 109 | 0 | $rows[0]->{userid}; | |||||||||||||||||||||||||||
| 110 | }; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | return $userids{$name}; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub FreshPassword { | ||||||||||||||||||||||||||
|
Subroutine
FreshPassword: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $gen = Session::Token->new(length => 10); | |||||||||||||||||||||||||||
| 117 | 0 | return $gen->get(); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub PasswordCheck { | ||||||||||||||||||||||||||
|
Subroutine
PasswordCheck: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $password = shift || return 6; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return 6)
MC/DC0%0/1
shift() || (return 6)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 122 | 0 | my $plen = length $password; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return 4 if($password =~ /\s/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return 1 if($settings{minpasslen} && $plen < $settings{minpasslen}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Labyrinth::Users::settings{"minpasslen"} and $plen < $Labyrinth::Users::settings{"minpasslen"}
MC/DC0%0/2
$Labyrinth::Users::settings{"minpasslen"} and $plen < $Labyrinth::Users::settings{"minpasslen"}
$Labyrinth::Users::settings{"minpasslen"}
$plen < $Labyrinth::Users::settings{"minpasslen"}
Truth table0%0/3
A and B
A= $Labyrinth::Users::settings{"minpasslen"}B= $plen < $Labyrinth::Users::settings{"minpasslen"}
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return 2 if($settings{maxpasslen} && $plen > $settings{maxpasslen}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Labyrinth::Users::settings{"maxpasslen"} and $plen > $Labyrinth::Users::settings{"maxpasslen"}
MC/DC0%0/2
$Labyrinth::Users::settings{"maxpasslen"} and $plen > $Labyrinth::Users::settings{"maxpasslen"}
$Labyrinth::Users::settings{"maxpasslen"}
$plen > $Labyrinth::Users::settings{"maxpasslen"}
Truth table0%0/3
A and B
A= $Labyrinth::Users::settings{"maxpasslen"}B= $plen > $Labyrinth::Users::settings{"maxpasslen"}
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # Check unique characters | ||||||||||||||||||||||||||||
| 129 | 0 | my @chars = split //,$password ; | |||||||||||||||||||||||||||
| 130 | 0 | my %unique ; | |||||||||||||||||||||||||||
| 131 | 0 | foreach my $char (@chars) { | |||||||||||||||||||||||||||
| 132 | 0 | $unique{$char}++; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return 5 if(scalar keys %unique < 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | my $types = 0; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | $types++ if($password =~ /[a-z]/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $types++ if($password =~ /[A-Z]/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $types++ if($password =~ /\d/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $types++ if($password =~ /[^a-zA-Z\d]/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return 0 if($types > 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | return 3; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 ADMIN INTERFACE METHODS | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =over 4 | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item UserSelect | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Provides a dropdown selection box, as a XHTML code snippet, of the currently | ||||||||||||||||||||||||||||
| 154 | listed users. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | By default only users listed as searchable are listed. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =back | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub UserSelect { | ||||||||||||||||||||||||||
|
Subroutine
UserSelect: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 0 | my $opt = shift; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $multi = shift || 5; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 5
MC/DC0%0/1
shift() || 5
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $blank = shift || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $field = shift || 'userid'; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'userid'
MC/DC0%0/1
shift() || 'userid'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $title = shift || 'Name'; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'Name'
MC/DC0%0/1
shift() || 'Name'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 168 | 0 | my $all = shift; | |||||||||||||||||||||||||||
| 169 | 0 | my $search; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $search = 'WHERE search=1' unless($all); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | my @rows = $dbi->GetQuery('hash','AllUsers',{search=>$search}); | |||||||||||||||||||||||||||
| 174 | 0 | foreach (@rows) { | |||||||||||||||||||||||||||
| 175 | 0 | my @names; | |||||||||||||||||||||||||||
| 176 | 0 | ▶ | push @names, $_->{realname} if($_->{realname}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | push @names, '(' . $_->{nickname} . ')' if($_->{nickname}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $_->{name} = join(' ',@names) if(@names); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $_->{name} ||= 'No Name Given'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_->{"name"} ||= "No Name Given"
MC/DC0%0/1
$_->{"name"} ||= "No Name Given"
$_->{"name"}
Truth table0%0/2
A
A= $_->{"name"}
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | unshift @rows, {userid=>0,name=>"Select $title"} if($blank == 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return DropDownMultiRows($opt,$field,'userid','name',$multi,@rows) if($multi > 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | return DropDownRows($opt,$field,'userid','name',@rows); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 12 | 1; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | __END__ | ||||||||||||||||||||||||||||