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

Nova logika registrace

parent dc1984eb
No related branches found
No related tags found
No related merge requests found
Pipeline #20456 passed
......@@ -2,7 +2,7 @@ image: docker:latest
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.21.5
IMAGE_VER: 0.22.0
services:
- docker:dind
......
......@@ -17,18 +17,7 @@ sub create ($c ) {
my $claims;
my $group;
my @products = ();
my $accredited = 0;
my $accreditation = 0;
# clasifikator typu
my $pt = {};
CLASS:
foreach my $class ( qw(main nonfree subsidy) ) {
foreach my $id ( split /\D+/, $c->config->{"products_$class"} ) {
$pt->{$class}{$id} = 1;
}
}
my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
$c->config->{pretix_api},
$c->config->{pretix_organizer},
......@@ -42,7 +31,6 @@ sub create ($c ) {
# processing tokenu
if ( $args->{token} ) {
$c->oauth_token($args->{token});
$claims = $c->oauth_claims;
......@@ -73,16 +61,9 @@ sub create ($c ) {
else {
$args->{email} = $claims->{email};
}
}
# 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,
......@@ -98,26 +79,10 @@ sub create ($c ) {
$product->{id} = $c->mapped_product_id($product->{id});
next PRODUCT if $pt->{subsidy}{$product->{id}} && ! $product->{price};
if ( $pt->{main}{ $product->{id} } ) {
next PRODUCT if $accredited++; # neumoznit dvoji akreditace
if ( $accreditation ) {
$product->{id} = $accreditation;
}
elsif ( $pt->{nonfree}{ $product->{id} } ) {
$product->{id} = $c->config->{products_fallback};
}
}
push @products, $product;
}
# fallback akreditace
@products = ( { id => $c->config->{products_fallback} }, @products ) if ! $accredited;
my $order = {
email => $args->{email},
locale => 'en',
......@@ -156,6 +121,12 @@ sub create ($c ) {
},
);
@{ $order->{positions} } = ({
item => $accreditation,
attendee_name => $args->{name},
answers => \@answers,
});
PRODUCT:
foreach my $product ( @products ) {
......@@ -167,8 +138,6 @@ sub create ($c ) {
company => $args->{company},
};
$item->{answers} = \@answers if $pt->{main}{$product->{id}};
push @{ $order->{positions} }, $item;
}
......
......@@ -9,6 +9,7 @@ no warnings qw{ experimental::signatures };
use constant KEY_FORMAT => "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----";
use constant REGIONS => qr{^(jhc|jhm|kvk|lbk|msk|olk|pak|pha|plk|stc|ulk|vys|zlk|khk):(f|regp)$};
use constant NOREG => qr(^cen:(regp|f)$);
sub register ( $class, $self, $conf) {
......@@ -29,8 +30,9 @@ sub register ( $class, $self, $conf) {
eval { $res = $ua->get( $self->cfg->{oauth_url} )->result; };
if (! $@ && $res->is_success) {
my $key = join "\n", unpack("(A64)*", $res->json->{public_key});
$jwt = Mojo::JWT->new(
public => sprintf( KEY_FORMAT, $res->json->{public_key} )
public => sprintf( KEY_FORMAT, $key )
);
}
}
......@@ -76,7 +78,10 @@ sub register ( $class, $self, $conf) {
$self->helper( oauth_main_group => sub ( $c ) {
my $claims = $c->oauth_claims // return;
my $cen_regp;
my $default = {
region => '',
role => 'guest',
};
GROUP:
foreach my $group ( sort @{ $claims->{groups} } ) {
......@@ -85,23 +90,20 @@ sub register ( $class, $self, $conf) {
my $region = $c->oauth_groups->{ $group };
$region =~ s/^K[SF]\s+//i;
$region =~ s/^RegP\s+//i;
return {
region => $region,
role => $role,
};
}
if ( $group =~ /cen:regp/ ) {
$cen_regp = 1;
if ( $group =~ NOREG ) {
$default->{role} = ( $1 eq 'f') ? 'member':'regp';
}
}
if ( $cen_regp ) {
return {
region => 'Praha',
role => 'regp',
};
}
return $default;
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment