Revision 6afd06ad
Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt
SL/Dispatcher.pm | ||
---|---|---|
17 | 17 |
use List::Util qw(first); |
18 | 18 |
use POSIX; |
19 | 19 |
use SL::Auth; |
20 |
use SL::Dispatcher::AuthHandler; |
|
20 | 21 |
use SL::LXDebug; |
21 | 22 |
use SL::LxOfficeConf; |
22 | 23 |
use SL::Locale; |
... | ... | |
37 | 38 |
|
38 | 39 |
my $self = bless {}, $class; |
39 | 40 |
$self->{interface} = lc($interface || 'cgi'); |
41 |
$self->{auth_handler} = SL::Dispatcher::AuthHandler->new; |
|
40 | 42 |
|
41 | 43 |
return $self; |
42 | 44 |
} |
... | ... | |
63 | 65 |
$::lxdebug->enter_sub; |
64 | 66 |
my $template = shift; |
65 | 67 |
my $error_type = shift || ''; |
68 |
my %params = @_; |
|
66 | 69 |
|
67 | 70 |
$::locale = Locale->new($::lx_office_conf{system}->{language}); |
68 | 71 |
$::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); |
... | ... | |
70 | 73 |
$::myconfig{countrycode} = $::lx_office_conf{system}->{language}; |
71 | 74 |
|
72 | 75 |
$::form->header; |
73 |
print $::form->parse_html_template($template); |
|
76 |
print $::form->parse_html_template($template, \%params);
|
|
74 | 77 |
$::lxdebug->leave_sub; |
75 | 78 |
|
76 | 79 |
::end_of_request(); |
... | ... | |
143 | 146 |
sub _require_controller { |
144 | 147 |
my $controller = shift; |
145 | 148 |
$controller =~ s|[^A-Za-z0-9_]||g; |
149 |
$controller = "SL/Controller/${controller}"; |
|
146 | 150 |
|
147 | 151 |
eval { |
148 | 152 |
package main; |
149 |
require "SL/Controller/${controller}.pm";
|
|
153 |
require "${controller}.pm"; |
|
150 | 154 |
} or die $EVAL_ERROR; |
151 | 155 |
} |
152 | 156 |
|
... | ... | |
163 | 167 |
|
164 | 168 |
my ($script, $path, $suffix, $script_name, $action, $routing_type); |
165 | 169 |
|
166 |
$script_name = $ENV{SCRIPT_NAME}; |
|
167 |
|
|
168 | 170 |
$self->unrequire_bin_mozilla; |
169 | 171 |
|
170 | 172 |
$::locale = Locale->new($::lx_office_conf{system}->{language}); |
... | ... | |
177 | 179 |
|
178 | 180 |
$::form->read_cgi_input; |
179 | 181 |
|
180 |
eval { ($routing_type, $script_name, $action) = _route_request($script_name); 1; } or return;
|
|
182 |
eval { ($routing_type, $script_name, $action) = _route_request($ENV{SCRIPT_NAME}); 1; } or return;
|
|
181 | 183 |
|
182 | 184 |
if ($routing_type eq 'old') { |
183 | 185 |
$::form->{action} = lc $::form->{action}; |
... | ... | |
205 | 207 |
} else { |
206 | 208 |
show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result; |
207 | 209 |
|
208 |
my $login = $::auth->get_session_value('login'); |
|
209 |
show_error('login/password_error', 'password') if not defined $login; |
|
210 |
|
|
211 |
%::myconfig = $::auth->read_user(login => $login); |
|
212 |
|
|
213 |
show_error('login/password_error', 'password') unless $::myconfig{login}; |
|
214 |
|
|
215 |
$::locale = Locale->new($::myconfig{countrycode}); |
|
216 |
|
|
217 |
show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($login, undef); |
|
218 |
|
|
219 |
$::auth->create_or_refresh_session; |
|
220 |
$::auth->delete_session_value('FLASH'); |
|
221 |
delete $::form->{password}; |
|
210 |
my $auth_level = $self->{auth_handler}->handle( |
|
211 |
routing_type => $routing_type, |
|
212 |
script => $script, |
|
213 |
controller => $script_name, |
|
214 |
action => $action, |
|
215 |
); |
|
222 | 216 |
|
223 | 217 |
if ($action) { |
224 |
$::instance_conf->init; |
|
218 |
$::instance_conf->init if $auth_level eq 'user';
|
|
225 | 219 |
|
226 | 220 |
map { $::form->{$_} = $::myconfig{$_} } qw(charset) |
227 | 221 |
unless $action eq 'save' && $::form->{type} eq 'preferences'; |
Auch abrufbar als: Unified diff
Dispatcher: Auch Controller ermöglichen, die Admin-Login benötigen
Default ist für Controller, dass all ihre Funktionen User-Logins
benötigen. Kann ein Controller ändern, indem er die Sub
"get_auth_level" überschreibt (siehe Doku in
SL::Contrller::Base). Dies schafft die Basis dafür, auch Admin-Dinge
in der neuen Controller-Architektur zu implementieren.
Für die Zukunft kann man leicht ein weiteres Level neben 'user' und
'admin' einbauen, z.B. 'none' für Actions, die definitiv kein Login
benötigen.
Funktionierendes Beispiel für einen solchen Controller (Aufruf dann
über URL ".../controller.pl?action=AdminTest/proof_of_concept"):
package SL::Controller::AdminTest;
use strict;
use parent qw(SL::Controller::Base);
use Rose::Object::MakeMethods::Generic
#(
scalar => [ qw(business) ],
);
sub action_proof_of_concept {
#my ($self) = @_;
sub get_auth_level {
return 'admin';
}
1;