Skip to content
Snippets Groups Projects
Verified Commit 3998e6e8 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

nahravani fotek pres piratar

parent b45a79bf
No related branches found
No related tags found
No related merge requests found
Pipeline #6076 passed
......@@ -2,7 +2,7 @@ image: docker:20.10.9
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.8.0
IMAGE_VER: 0.9.0
services:
- docker:20.10.9-dind
......
package CF2022::Controller::Orders;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use Mojo::Asset::File;
use constant MAIN_PRODUCTS => qr/^(1|2|3)$/; # typy akreditace
use constant NONFREE_PRODUCTS => qr/^(1)$/; # akreditace vyzadujici token
use constant SUBSIDY_PRUDUCTS => qr/^(58)$/; # prispevkove polozky
use constant SUBSIDY_PRODUCTS => qr/^(58)$/; # prispevkove polozky
use constant FALLBACK_PRODUCT => 2; # fallback akreditace
use feature 'signatures';
......@@ -66,12 +67,26 @@ sub create ($c ) {
}
}
# korekce akreditace
# kontrola duplicity
my $exists = $c->schema->resultset('Order')->search({
deleted => undef,
email => $args->{email},
api => $url,
})->count;
$exists ||= $c->schema->resultset('Order')->search({
deleted => undef,
sso_uuid => $claims->{sub},
api => $url,
})->count if $claims;
return $c->error(400, 'Duplicity' ) if $exists;
# korekce akreditace
PRODUCT:
foreach my $product ( @{ $args->{products} } ) {
next PRODUCT if $product->{id} =~ SUBSIDY_PRUDUCTS && ! $product->{price};
next PRODUCT if $product->{id} =~ SUBSIDY_PRODUCTS && ! $product->{price};
if ( $product->{id} =~ MAIN_PRODUCTS ) {
next PRODUCT if $accredited++; # neumoznit dvoji akreditace
......@@ -100,6 +115,19 @@ sub create ($c ) {
fees => [],
};
# nahrani fotky
if ( $group->{role} eq 'member' ) {
my $photo_id = $c->_upload_photo($claims->{preferred_username});
if ( $photo_id ) {
push @answers, (
{
question => 28,
answer => $photo_id,
},
);
}
}
PRODUCT:
foreach my $product ( @products ) {
......@@ -116,22 +144,8 @@ sub create ($c ) {
push @{ $order->{positions} }, $item;
}
# kontrola duplicity
my $exists = $c->schema->resultset('Order')->search({
email => $order->{email},
api => $url,
})->count;
$exists ||= $c->schema->resultset('Order')->search({
sso_uuid => $claims->{sub},
api => $url,
})->count if $claims;
return $c->error(400, 'Duplicity' ) if $exists;
# odeslani do pretixu
my $ua = Mojo::UserAgent->new;
my $rc = $ua->post( $url,
{ Authorization => 'Token ' . $c->config->{pretix_token} },
......@@ -206,4 +220,32 @@ sub get ($c ) {
);
}
sub _upload_photo ($c, $username ) {
my $ua = Mojo::UserAgent->new;
my $rc = $ua->get(
$c->config->{piratar_url} . $username . '.jpg'
)->result;
return if ! $rc->is_success;
my $photo = "/tmp/$username.jpg";
$rc->save_to($photo);
my $tx = $ua->build_tx(POST => $c->config->{pretix_api} . '/upload', {
Authorization => 'Token ' . $c->config->{pretix_token},
'Content-type' => 'image/jpeg',
'Content-Disposition' => qq{attachment; filename="$username.jpg"},
});
$tx->req->content->asset(Mojo::Asset::File->new(path => $photo));
$rc = $ua->start($tx)->result;
return if ! $rc->is_success;
return $rc->json->{id};
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment