XML/Template/Element/User.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 SCAR 6.9
CC
1
Cov
0%
authenticate
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 ###############################################################################
2 # XML::Template::Element::User
3 #
4 # Copyright (c) 2002-2003 Jonathan A. Waxman <jowaxman@law.upenn.edu>
5 # All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 ###############################################################################
10 package XML::Template::Element::User;
11 use base qw(XML::Template::Element::DB);
12  
13 use strict;
14 use XML::Template::Element;
15  
16  
17 =pod
18  
19 =head1 NAME
20  
21 XML::Template::Element::User - XML::Template plugin module for the user
22 namespace.
23  
24 =head1 SYNOPSIS
25  
26 This XML::Template plugin module implements the user namespace tagset.
27 The user namespace includes tags that handle user authentication and
28 access to the user database table.
29  
30 =head1 CONSTRUCTOR
31  
32 XML::Template::Element::User inherits its constructor method, C<new>, from
33 L<XML::Template::Element>.
34  
35 =head1 USER TAGSET METHODS
36  
37 =head2 authenticate
38  
39 This method implements the authentication element which handles user
40 web authentication. The following attributes are used:
41  
42 =over 4
43  
44 =item logintemplate
45  
46 The redirection template to display upon successful login.
47  
48 =item logouttemplate
49  
50 The redirection template to display upon successful logout.
51  
52 =item logouturl
53  
54 The URL to redirect to upon logout.
55  
56 =back
57  
58 =cut
59  
60 sub authenticate {
61 my $self = shift;
62 my ($code, $attribs) = @_;
63  
64 my $logintemplate = $self->get_attrib ($attribs, 'logintemplate') || 'undef';
65 my $logouttemplate = $self->get_attrib ($attribs, 'logouttemplate') || 'undef';
66 my $logouturl = $self->get_attrib ($attribs, 'logouturl') || 'undef';
67 my $sourcename = $self->get_attrib ($attribs, 'sourcename');
68  
69 my $source_mapping_info = $self->get_source_mapping_info (namespace => $self->namespace);
70 my $host_info = $self->get_host_info ($self->{_hostname}, 'domain');
71  
72 my $outcode = qq{
73 #ServerKeySrc
74  
75 do {
76 use WWW::Auth;
77 use WWW::Auth::DB;
78  
79 my \$db = \$process->get_source ('$source_mapping_info->{source}')
80 || die XML::Template::Exception->new ('Auth', scalar (\$process->error ()));
81  
82 # Temporarily turn off CGI headers so any authentication templates
83 # (login, logout) do not display them.
84 my \$cgi_header = \$process->{_cgi_header};
85 \$process->{_cgi_header} = 0;
86 my \$auth_db = WWW::Auth::DB->new (DB => \$db)
87 || die XML::Template::Exception->new ('Auth', scalar (WWW::Auth::DB->error ()));
88 my \$auth = WWW::Auth->new (CGIHeader => 0,
89 Auth => \$auth_db,
90 Domain => '$host_info->{domain}',
91 Template => \$process,
92 LoginTemplate => $logintemplate,
93 LogoutTemplate => $logouttemplate,
94 LogoutURL => $logouturl);
95 \$process->{_cgi_header} = \$cgi_header;
96 die XML::Template::Exception->new ('Auth', scalar (WWW::Auth->error ()))
97 if ! defined \$auth;
98  
99 my \$cgi_header_printed = \$process->{_cgi_header_printed};
100 \$process->{_cgi_header_printed} = 1;
101 my (\$success, \$error) = \$auth->login ();
102 \$process->{_cgi_header_printed} = \$success ? 1 : \$cgi_header_printed;
103  
104 die XML::Template::Exception->new ('Auth', \$error) if ! \$success;
105 };
106 };
107  
108 return $outcode;
109 }
110  
111 =pod
112  
113 =head1 SQL TAGSET METHODS
114  
115 XML::Template::Element::User is a subclass of
116 L<XML::Template::Element::DB>, so derives the SQL tagset. See
117 L<XML::Template::Element::DB> for more details.
118  
119 =head1 AUTHOR
120  
121 Jonathan Waxman
122 <jowaxman@bbl.med.upenn.edu>
123  
124 =head1 COPYRIGHT
125  
126 Copyright (c) 2002-2003 Jonathan A. Waxman
127 All rights reserved.
128  
129 This program is free software; you can redistribute it and/or
130 modify it under the same terms as Perl itself.
131  
132 =cut
133  
134  
135 1;