diff --git a/TODO b/TODO index feebcfc12302cf9693df0830df22973f414e6279..5966e7f04f8b90fef08370c50196fc1bc19521e2 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -- custom url -- 302 nebo informacni stranka - statistika -- smazani +- editace/smazani +- loop detect +- 302 nebo informacni stranka diff --git a/VERSION b/VERSION index d917d3e26adc9854b4569871e20111c38de2606f..0ea3a944b399d25f7e1b8fe684d754eb8da9fe7f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 +0.2.0 diff --git a/lib/PZ/Controller/Shortcut.pm b/lib/PZ/Controller/Shortcut.pm index c453e662a5008061b3b74ab52d8a8b1f98eda496..792af3694f6bc74ab5f3c9cf20a2c2b507a655f9 100644 --- a/lib/PZ/Controller/Shortcut.pm +++ b/lib/PZ/Controller/Shortcut.pm @@ -8,11 +8,31 @@ use Image::PNG::QRCode 'qrpng'; sub create ($c) { my $url = $c->param('url'); - if( ! is_uri($url) ){ - $c->render('shortcut/invalid'); + if( ! is_uri($url) ) { + $c->render('shortcut/invalid', error => 'Chybná URL adresa!'); return; } + my $custom = lc($c->param('shortcut')); + + if ( ! $custom =~ /^[a..z0..9]{1,8}$/i ) { + $c->render('shortcut/invalid', error => 'Neplatná zkratka'); + return; + } + + if ( $custom ) { + my $exists = $c->schema->resultset('Shortcut')->search({ + is_active => 1, + deleted => undef, + shortcut => $custom, + })->count; + + if( $exists ) { + $c->render('shortcut/invalid', error => "Zkratka $custom už je použitá"); + return; + } + } + my %data = ( user_id => $c->current_user->{id}, deleted => undef, @@ -23,7 +43,7 @@ sub create ($c) { $shortcut ||= $c->schema->resultset('Shortcut')->create({ %data, - shortcut => $c->schema->resultset('Shortcut')->generate(), + shortcut => $custom // $c->schema->resultset('Shortcut')->generate(), }); $url = 'https://' . $c->config->{domain} . '/' . $shortcut->shortcut; diff --git a/templates/includes/form.html.ep b/templates/includes/form.html.ep index 2135824303e0efa84d56a244917c0b915630d25e..cd97686ee620766cc68580829f971e912697b957 100644 --- a/templates/includes/form.html.ep +++ b/templates/includes/form.html.ep @@ -1,23 +1,32 @@ -<p> -<div class="card elevation-4"> - <div class="card__body"> <form hx-post="/" hx-target="#response" hx-params="*"> -<div class="form-field"> - <label class="form-field__label" for="field">URL</label> +<div class="card elevation-4 space-y-4"> + <div class="card__body"> + <div class="grid grid-cols-12 gap-4 row-gap-6"> + +<div class="form-field col-span-9"> + <label class="form-field__label" for="url">URL</label> <div class="form-field__wrapper form-field__wrapper--shadowed"> <input type="text" name="url" class="text-input form-field__control" value="" placeholder="https://www.pirati.cz/program/dlouhodoby/psychotropni-latky/" required="required" /> - <button class="btn btn--grey-125 btn--hoveractive"> + </div> +</div> + +<div class="form-field col-span-3"> + <label class="form-field__label" for="shortcut">Zkratka</label> + <div class="form-field__wrapper form-field__wrapper--shadowed"> + <input type="text" name="shortcut" class="text-input form-field__control w-40" size="8" maxlength="8" value="" placeholder="thc" /> + + <button class="btn btn--grey-125 btn--hoveractive ml-4"> <div class="btn__body">Zkrátit</div> </button> - </div> </div> -</form> - </div> </div> -</p> +</div> +</div> + +</form> <div id="response"></div> diff --git a/templates/shortcut/invalid.html.ep b/templates/shortcut/invalid.html.ep index 2802bc6503be5d607d569d567aea89c7b4e7f090..d21bf2be1c5bcbb33afbdc9ed0211b38aea73ba1 100644 --- a/templates/shortcut/invalid.html.ep +++ b/templates/shortcut/invalid.html.ep @@ -1,4 +1,4 @@ <span class="alert alert--red-600 alert--faded"> - <span>Chybná URL adresa!</span> + <span><%= $error %></span> </span>