Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf-web-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KS Pardubický kraj
cf-web-api
Commits
3998e6e8
Verified
Commit
3998e6e8
authored
3 years ago
by
Andrej Ramašeuski
Browse files
Options
Downloads
Patches
Plain Diff
nahravani fotek pres piratar
parent
b45a79bf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#6076
passed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
lib/CF2022/Controller/Orders.pm
+59
-17
59 additions, 17 deletions
lib/CF2022/Controller/Orders.pm
with
60 additions
and
18 deletions
.gitlab-ci.yml
+
1
−
1
View file @
3998e6e8
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
lib/CF2022/Controller/Orders.pm
+
59
−
17
View file @
3998e6e8
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_PR
U
DUCTS
=>
qr/^(58)$/
;
# prispevkove polozky
use
constant
SUBSIDY_PR
O
DUCTS
=>
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_PR
U
DUCTS
&&
!
$product
->
{
price
};
next
PRODUCT
if
$product
->
{
id
}
=~
SUBSIDY_PR
O
DUCTS
&&
!
$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
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment