Changeset 1377


Ignore:
Timestamp:
May 2, 2012, 7:24:58 PM (10 years ago)
Author:
kake
Message:

Made the prefs page return the user to the place they came from (fixes #94). Still need to move this from preferences.cgi into OpenGuides.pm and write some tests for it.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r1372 r1377  
    3131          (you can still tweak this by setting website_link_max_chars in
    3232          your wiki.conf).
     33        The preferences page now remembers what page the user got to it from,
     34          and sends them back there.
    3335
    34360.66    12 April 2012
  • trunk/lib/OpenGuides.pm

    r1376 r1377  
    653653    my $wiki = $self->wiki;
    654654
     655    my $from = $ENV{HTTP_REFERER} || "";
     656    my $url_base = $config->script_url . $config->script_name;
     657    if ( $from !~ /^$url_base/ ) {
     658        $from = "";
     659    }
     660
     661    my %tt_vars = (
     662                    not_editable  => 1,
     663                    show_form     => 1,
     664                    not_deletable => 1,
     665                    return_to_url => $from,
     666    );
     667    return %tt_vars if $args{return_tt_vars};
     668
    655669    my $output = OpenGuides::Template->output(
    656670        wiki      => $wiki,
    657671        config    => $config,
    658672        template  => "preferences.tt",
    659         vars      => {
    660                        not_editable  => 1,
    661                        show_form     => 1,
    662                        not_deletable => 1,
    663                      },
     673        vars      => \%tt_vars,
    664674        noheaders => $args{noheaders},
    665675    );
  • trunk/preferences.cgi

    r1376 r1377  
    5858                      not_deletable => 1,
    5959                      username => $prefs{username},
     60                      return_to_url => $cgi->param( "return_to_url" ) || "",
    6061                    }
    6162    );
  • trunk/t/59_preferences.t

    r1376 r1377  
    1818}
    1919
    20 plan tests => 12;
     20plan tests => 17;
    2121
    2222OpenGuides::Test::refresh_db();
     
    2525my $guide = OpenGuides->new( config => $config );
    2626my $wiki = $guide->wiki;
     27
     28# Make sure "return_to" TT var is set iff referrer domain is correct.
     29$config->script_url( "http://example.com/" );
     30$config->script_name( "wiki.cgi" );
     31my $good_return_to = "http://example.com/wiki.cgi?Test_Page";
     32my $evil_return_to = "http://example.org/naughty-script";
     33
     34$ENV{HTTP_REFERER} = $good_return_to;
     35my %tt_vars = $guide->display_prefs_form( return_tt_vars => 1 );
     36is( $tt_vars{return_to_url}, $good_return_to,
     37    "Return URL set when referrer matches script URL/name" );
     38my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
     39Test::HTML::Content::tag_ok( $output,
     40  "input", { type => "hidden", name => "return_to_url" },
     41    "...corresponding hidden input is there in the form" );
     42Test::HTML::Content::tag_ok( $output,
     43  "input", { type => "hidden", name => "return_to_url",
     44             value => $good_return_to },
     45    "...with correct value" );
     46
     47$ENV{HTTP_REFERER} = $evil_return_to;
     48%tt_vars = $guide->display_prefs_form( return_tt_vars => 1 );
     49ok( !$tt_vars{return_to_url},
     50    "Return URL not set when referrer doesn't match script URL/name" );
     51$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
     52Test::HTML::Content::no_tag( $output,
     53  "input", { type => "hidden", name => "return_to_url" },
     54    "...and no corresponding hidden input in form" );
    2755
    2856# If we have a google API key and node maps are enabled, we should see the
     
    3664                                               );
    3765$ENV{HTTP_COOKIE} = $cookie;
    38 my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
     66$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
    3967Test::HTML::Content::tag_ok( $output,
    4068  "input", { type => "checkbox", name => "display_google_maps" },
  • trunk/templates/preferences.tt

    r1336 r1377  
    122122    <input type="submit" value="Set it" class="form_button" />
    123123    <input type="hidden" name="action" value="set_preferences">
     124    [% IF return_to_url %]
     125      <input type="hidden" name="return_to_url"
     126             value="[% return_to_url | html %]" />
     127    [% END %]
    124128  </form>
    125129
     
    193197
    194198<ul>
    195   <li><a href="[% full_cgi_url %]">Return to [% site_name %]</a></li>
     199  <li><a href="[% IF return_to_url %][% return_to_url | html %][% ELSE %][% full_cgi_url %][% END %]">Return to [% site_name %]</a></li>
    196200  <li><a href="preferences.cgi">Change preferences</a></li>
    197201</ul>
Note: See TracChangeset for help on using the changeset viewer.