X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FBase.pm;h=4dace86ed91844d63e7efd05142c499df2dc1fd1;hb=f2b76d67f773954dcfa59ff7c3ebb6f6607e2e43;hp=29289ff961ff3eda0dd0144611457d894d76f60b;hpb=d28dde0f9ee82e6400fd0caba165331d561affde;p=kivitendo-erp.git diff --git a/SL/Controller/Base.pm b/SL/Controller/Base.pm index 29289ff96..4dace86ed 100644 --- a/SL/Controller/Base.pm +++ b/SL/Controller/Base.pm @@ -21,11 +21,20 @@ sub url_for { my %params = ref($_[0]) eq 'HASH' ? %{ $_[0] } : @_; my $controller = delete($params{controller}) || $self->_controller_name; - my $action = delete($params{action}) || 'dispatch'; - $params{action} = "${controller}/${action}"; + my $action = $params{action} || 'dispatch'; + + my $script; + if ($controller =~ m/\.pl$/) { + # Old-style controller + $script = $controller; + } else { + $params{action} = "${controller}/${action}"; + $script = "controller.pl"; + } + my $query = join '&', map { uri_encode($_->[0]) . '=' . uri_encode($_->[1]) } @{ flatten(\%params) }; - return "controller.pl?${query}"; + return "${script}?${query}"; } sub redirect_to { @@ -151,10 +160,10 @@ sub _run_hooks { || ($hook->{except} && $hook->{except}->{$action}); if (ref($hook->{code}) eq 'CODE') { - $hook->{code}->($self); + $hook->{code}->($self, $action); } else { my $sub = $hook->{code}; - $self->$sub; + $self->$sub($action); } } } @@ -172,6 +181,10 @@ sub get_auth_level { return 'user'; } +sub keep_auth_vars_in_form { + return 0; +} + # # private functions -- for use in Base only # @@ -191,7 +204,7 @@ sub _run_action { } sub _controller_name { - return (split(/::/, ref($_[0])))[-1]; + return (split(/::/, ref($_[0]) || $_[0]))[-1]; } sub _dispatch { @@ -315,6 +328,10 @@ hooks themselves are run as instance methods. Hooks are run in the order they're added. +The hooks receive a single parameter: the name of the action that is +about to be called (for C hooks) / was called (for C +hooks). + The return value of the hooks is discarded. Hooks can be defined to run for all actions, for only specific actions @@ -517,6 +534,13 @@ C (authentication as a normal user suffices) with a possible future value C (which would require no authentication but is not yet implemented). +=item C + +May be overridden by a controller. If falsish (the default) all form +variables whose name starts with C<{AUTH}> are removed before the +request is routed. Only controllers that handle login requests +themselves should return trueish for this function. + =back =head2 PRIVATE FUNCTIONS