Skip to content

Commit

Permalink
[#1035] Convert extacct_auth endpoint
Browse files Browse the repository at this point in the history
Also converts the general endpoint handler to use DW::RPC->err/out
  • Loading branch information
afuna committed Nov 6, 2014
1 parent 92d4be1 commit d5ba888
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 68 deletions.
55 changes: 41 additions & 14 deletions cgi-bin/DW/Controller/RPC/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,57 @@ use LJ::JSON;
use DW::Routing;
use LJ::JSON;

DW::Routing->register_rpc( "extacct_auth", \&extacct_auth_handler, format => 'json' );
DW::Routing->register_rpc( "general", \&general_handler, format => 'json' );
sub general_handler {

sub extacct_auth_handler {
my $r = DW::Request->get;
my $get = $r->get_args;

my $u = LJ::get_remote();
return DW::RPC->err( LJ::Lang::ml( '/tools/endpoints/extacct_auth.bml.error.nouser' ) )
unless $u;

# get the account
my $acctid = LJ::ehtml( $get->{acctid} );
my $account = DW::External::Account->get_external_account( $u, $acctid );
return DW::RPC->err( LJ::Lang::ml( '/tools/endpoints/extacct_auth.bml.error.nosuchaccount',
{
acctid => $acctid,
username => $u->username
}
) ) unless $account;

# make sure this account supports challenge/response authentication
return DW::RPC->err( LJ::Lang::ml( '/tools/endpoints/extacct_auth.bml.error.nochallenge',
{
account => LJ::ehtml( $account->displayname )
}
) ) unless $account->supports_challenge;

my $err = sub {
$r->print( to_json( {
alert => $_[0],
error => 1,
} ) );
return $r->OK;
};
# get the auth challenge
my $challenge = $account->challenge;
return DW::RPC->err( LJ::Lang::ml( '/tools/endpoints/extacct_auth.bml.error.authfailed',
{
account => LJ::ehtml( $account->displayname )
}
) ) unless $challenge;

return DW::RPC->out( challenge => $challenge, success => 1 );
}

sub general_handler {
my $r = DW::Request->get;
my $args = $r->get_args;

# make sure we have a user of some sort
my $remote = LJ::get_remote();
my $u = LJ::load_user( $args->{user} || $remote->user )
or return $err->( 'Unable to load user for call.' );
or return DW::RPC->alert( 'Unable to load user for call.' );

# in theory, they're passing a mode in the args-> arguments
my $mode = $args->{mode}
or return $err->( 'No mode passed.' );
or return DW::RPC->alert( 'No mode passed.' );

my %ret;

Expand Down Expand Up @@ -78,12 +106,11 @@ sub general_handler {

# problems
} else {
return $err->( 'Unknown mode.' );
return DW::RPC->alert( 'Unknown mode.' );

}

$r->print( to_json( \%ret ) );
return $r->OK;
return DW::RPC->out( %ret );
}

1;
1 change: 0 additions & 1 deletion cgi-bin/LJ/Global/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ no strict "vars";
dirsearch => "tools/endpoints/directorysearch.bml",
jobstatus => "tools/endpoints/jobstatus.bml",
multisearch => "tools/endpoints/multisearch.bml",
extacct_auth => "tools/endpoints/extacct_auth.bml",
contentfilters => "tools/endpoints/contentfilters.bml",
);

Expand Down
53 changes: 0 additions & 53 deletions htdocs/tools/endpoints/extacct_auth.bml

This file was deleted.

1 change: 1 addition & 0 deletions htdocs/tools/endpoints/extacct_auth.bml.text
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
;; -*- coding: utf-8 -*-
# used in cgi-bin/DW/Controller/RPC/Misc
.error.authfailed=Failed to connect to [[account]]

.error.nochallenge=[[account]] does not support challenge/response authentication.
Expand Down

0 comments on commit d5ba888

Please sign in to comment.