Skip to content

Commit

Permalink
(bug 4408) Partial work on automatic form auth checking.
Browse files Browse the repository at this point in the history
Add automatic form auth checking when requested,
with future plans to make the automatic check the default.
  • Loading branch information
anall committed Dec 4, 2012
1 parent 5f94be1 commit 99dabe2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cgi-bin/DW/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ sub success_ml {
# login cookie
# - skip_domsess => 0 -- (for user domains) do redirect for the user domain
# cookie (default)
# - form_auth => 0 -- Do not automatically check form auth ( current default )
# - form_auth => 1 -- Automatically check form auth ( planned to be future default )
# On any new controller, please try and pass "form_auth => 0" if you are checking
# the form auth yourself, or if the automatic check will cause problems.
# Thank you.
#
# Returns one of:
# - 0, $error_text (if there's an error)
Expand All @@ -97,6 +102,8 @@ sub controller {
( $args{authas} && $args{anonymous} ) ||
( $args{privcheck} && $args{anonymous} );

$args{form_auth} //= 0;

# 'anonymous' pages must declare themselves, else we assume that a remote is
# necessary as most pages require a user
$vars->{u} = $vars->{remote} = LJ::get_remote();
Expand Down Expand Up @@ -169,6 +176,11 @@ sub controller {
unless $has_one;
}

if ( $r->did_post && $args{form_auth} ) {
my $post_args = $r->post_args || {};
return $fail->( error_ml( 'error.invalidform' ) ) unless LJ::check_form_auth( $post_args->{lj_form_auth} );
}

# everything good... let the caller know they can continue
return $ok->();
}
Expand Down
2 changes: 1 addition & 1 deletion cgi-bin/DW/Controller/Manage/Logins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DW::Routing->register_string( "/manage/logins", \&login_handler, app => 1 );
sub login_handler {
my ( $opts ) = @_;

my ( $ok, $rv ) = controller();
my ( $ok, $rv ) = controller( form_auth => 1 );
return $rv unless $ok;

my $r = DW::Request->get;
Expand Down

0 comments on commit 99dabe2

Please sign in to comment.