Skip to content
Snippets Groups Projects
Commit 345d1260 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

factorisation

parent 815a59dd
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ use English qw(-no_match_vars); ...@@ -6,6 +6,7 @@ use English qw(-no_match_vars);
use Syntax::Keyword::Try; use Syntax::Keyword::Try;
use AccountManager::DB; use AccountManager::DB;
use AccountManager::Entity;
use AccountManager::L10N; use AccountManager::L10N;
use AccountManager::Token; use AccountManager::Token;
...@@ -116,6 +117,46 @@ sub check_token { ...@@ -116,6 +117,46 @@ sub check_token {
return 1; return 1;
} }
sub get_sp {
my ($self, %args) = @_;
my $entityid = $args{entityid};
return $self->abort(
log_message => "Missing parameter: entityid",
user_message => "missing_entityid"
) if !$entityid;
my $pattern = qr{
^
(?:
https?://[\w.:/-]+
|
urn:[\w.:-]+
)
$
}x;
return $self->abort(
log_message => "Incorrect parameter format: entityid",
user_message => "format_entityid"
) if $entityid !~ $pattern;
my $db = $self->stash('db');
my $sp = AccountManager::Entity->new(
db => $db,
entityid => $entityid
);
return $self->abort(
log_message => sprintf("No such SP '%s' in database", $entityid),
user_message => "no_such_entity"
) if !$sp->load(speculative => 1);
return $sp;
}
sub abort { sub abort {
my $self = shift; my $self = shift;
my %args = @_; my %args = @_;
......
...@@ -5,8 +5,6 @@ use Mojo::Base qw(AccountManager::App::Controller); ...@@ -5,8 +5,6 @@ use Mojo::Base qw(AccountManager::App::Controller);
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Syntax::Keyword::Try; use Syntax::Keyword::Try;
use AccountManager::Entity;
sub run { sub run {
my $self = shift; my $self = shift;
...@@ -21,16 +19,8 @@ sub run { ...@@ -21,16 +19,8 @@ sub run {
} }
my $entityid = $self->param('entityid'); my $entityid = $self->param('entityid');
my $db = $self->stash('db'); my $sp = $self->get_sp(entityid => $entityid);
return if !$sp;
my $sp = AccountManager::Entity->new(
db => $db,
entityid => $entityid
);
return $self->abort(
log_message => sprintf("No such SP '%s' in database", $entityid),
user_message => "no_such_entity"
) if !$sp->load(speculative => 1);
# override metadata contacts if needed # override metadata contacts if needed
my $contacts = my $contacts =
......
...@@ -9,7 +9,6 @@ use English qw(-no_match_vars); ...@@ -9,7 +9,6 @@ use English qw(-no_match_vars);
use Syntax::Keyword::Try; use Syntax::Keyword::Try;
use Template::Constants qw(:chomp); use Template::Constants qw(:chomp);
use AccountManager::Entity;
use AccountManager::Token; use AccountManager::Token;
use AccountManager::Tools; use AccountManager::Tools;
...@@ -31,14 +30,8 @@ sub run { ...@@ -31,14 +30,8 @@ sub run {
my $db = $self->stash('db'); my $db = $self->stash('db');
my $l10n = $self->stash('l10n'); my $l10n = $self->stash('l10n');
my $sp = AccountManager::Entity->new( my $sp = $self->get_sp(entityid => $entityid);
db => $db, return if !$sp;
entityid => $entityid
);
return $self->abort(
log_message => sprintf("No such SP '%s' in database", $entityid),
user_message => "no_such_entity"
) if !$sp->load(speculative => 1);
# override metadata contacts if needed # override metadata contacts if needed
my $contacts = my $contacts =
......
...@@ -10,7 +10,6 @@ use Syntax::Keyword::Try; ...@@ -10,7 +10,6 @@ use Syntax::Keyword::Try;
use Template::Constants qw(:chomp); use Template::Constants qw(:chomp);
use AccountManager::Account; use AccountManager::Account;
use AccountManager::Entity;
use AccountManager::Token; use AccountManager::Token;
use AccountManager::Tools; use AccountManager::Tools;
...@@ -35,16 +34,10 @@ sub run { ...@@ -35,16 +34,10 @@ sub run {
my $db = $self->stash('db'); my $db = $self->stash('db');
my $l10n = $self->stash('l10n'); my $l10n = $self->stash('l10n');
return if !$self->check_token(token => $token, entityid => $entityid); my $sp = $self->get_sp(entityid => $entityid);
return if !$sp;
my $sp = AccountManager::Entity->new( return if !$self->check_token(token => $token, entityid => $entityid);
db => $db,
entityid => $entityid,
);
return $self->abort(
log_message => sprintf("No such SP '%s' in database", $entityid),
user_message => "no_such_entity"
) if !$sp->load(speculative => 1);
## create test accounts ## create test accounts
my @accounts; my @accounts;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment