Skip to content

Commit

Permalink
Merge pull request #909 from afuna/redirect-renamed-users-bug-690
Browse files Browse the repository at this point in the history
[#690] Redirect a renamed (and redirecting)  user automatically
  • Loading branch information
zorkian committed Aug 9, 2014
2 parents fd41cac + f3d5e74 commit 99e7672
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
9 changes: 0 additions & 9 deletions cgi-bin/DW/Controller/Edges.pm
Expand Up @@ -56,15 +56,6 @@ sub edges_handler {
return $error_out->( 403, 'suspended' ) if $u->is_suspended;
return $error_out->( 404, 'deleted' ) if $u->is_deleted;

# deal with renamed accounts
my $renamed_u = $u->get_renamed_user;
unless ( $renamed_u && $u->equals( $renamed_u ) ) {
$r->header_out("Location", $renamed_u->journal_base . "/data/edges");
$r->status( $r->REDIRECT );
$r->print( to_json( { error => 'moved', moved_to => $renamed_u->journal_base . "/data/edges" } ) );
return $r->OK;
}

# Load appropriate usernames for different accounts
my $us;

Expand Down
9 changes: 0 additions & 9 deletions cgi-bin/DW/Controller/Interests.pm
Expand Up @@ -52,15 +52,6 @@ sub interests_handler {
return $error_out->( $r->FORBIDDEN, 'suspended' ) if $u->is_suspended;
return $error_out->( $r->NOT_FOUND, 'deleted' ) if $u->is_deleted;

# deal with renamed accounts
my $renamed_u = $u->get_renamed_user;
unless ( $renamed_u && $u->equals( $renamed_u ) ) {
$r->header_out( "Location", $renamed_u->journal_base . "/data/interests" );
$r->status( $r->REDIRECT );
$r->print( to_json( { error => 'moved', moved_to => $renamed_u->journal_base . "/data/interests" } ) );
return $r->OK;
}

# Load the interests
my $interests = $u->get_interests || [];
my $output = {};
Expand Down
12 changes: 12 additions & 0 deletions cgi-bin/DW/Routing.pm
Expand Up @@ -200,6 +200,18 @@ sub _call_hash {
if $opts->prefer_ssl && $LJ::USE_SSL && $opts->role eq 'app' &&
! $opts->ssl && ( $r->method eq 'GET' || $r->method eq 'HEAD' );

# if renamed with redirect in place, then do the redirect
if ( $opts->role eq 'user' && ( my $orig_u = LJ::load_user( $opts->username ) ) ) {
my $renamed_u = $orig_u->get_renamed_user;

unless ( $renamed_u && $orig_u->equals( $renamed_u ) ) {
my $journal_host = $renamed_u->journal_base;
$journal_host =~ s!http://!!;

return $r->redirect( LJ::create_url( $r->uri, host => $journal_host, keep_args => 1 ) );
}
}

# apply default content type if it exists
my $format = $opts->format;
$r->content_type( $default_content_types->{$format} )
Expand Down

0 comments on commit 99e7672

Please sign in to comment.