view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Args.pm view on Meta::CPAN
$args{__args}->{ $_ } = $args{ $_ } for @args; # save to __priv
$args{__json}->{ $_ } = $json->{ $_ } for @json; # for specific access
} if $want_detail;
$args{ $_ } = $json->{ $_ } for @json;
}
%args = ( %args, %save ); # this allows interception and override from route conditions that want to validate/modify and/or hooks
$stash->{args} = \%args;
return wantarray ? %{ $stash->{args} } : $stash->{args};
} ) unless $app->renderer->helpers->{args};
}
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
sub register {
my ($self, $app, $args) = @_;
$args = { %{ $args || {} } }; # copy as mutating
for my $cb_name (qw(load_user validate_user)) {
my $p_name = $cb_name."_p";
die __PACKAGE__, ": missing '$cb_name' subroutine ref in parameters\n"
unless grep ref eq 'CODE', @$args{$cb_name, $p_name};
$args->{$p_name} = sub {
my @r = eval { $args->{$cb_name}->(@_) };
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
my $autoload_user = $args->{autoload_user} // 0;
my $session_key = $args->{session_key} || 'auth_data';
my $our_stash_key = $args->{stash_key} || '__authentication__';
my $current_user_fn = $args->{current_user_fn} || 'current_user';
my $load_user_cb = $args->{load_user};
my $validate_user_cb = $args->{validate_user};
my $load_user_cb_p = $args->{load_user_p};
my $validate_user_cb_p= $args->{validate_user_p};
my $fail_render = ref $args->{fail_render} eq 'CODE'
? $args->{fail_render} : sub { $args->{fail_render} };
my $user_loader_sub = user_loader_closure(
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
my $current_user_p = user_stash_extractor_closure_p(
$our_stash_key, $user_loader_sub_p,
);
$app->helper(authenticate => authenticate_closure(
$our_stash_key, $session_key, $validate_user_cb, $current_user,
));
$app->helper(authenticate_p => authenticate_closure_p(
$our_stash_key, $session_key, $validate_user_cb_p, $current_user_p,
));
$app->hook(before_dispatch => $user_loader_sub_p) if $autoload_user;
$app->routes->add_condition(authenticated => sub {
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
});
};
}
sub authenticate_closure {
my ($our_stash_key, $session_key, $validate_user_cb, $current_user) = @_;
sub {
my ($c, $user, $pass, $extradata) = @_;
# if extradata contains "auto_validate", assume the passed username
# is in fact valid, and auto_validate contains the uid; used for
# OAuth and other stuff that does not work with usernames and
# passwords; use this with extreme care if you must
$extradata ||= {};
my $uid = $extradata->{auto_validate} //
$validate_user_cb->($c, $user, $pass, $extradata);
return undef if !defined $uid;
$c->session($session_key => $uid);
# Clear stash to force reload of any already loaded user object
delete $c->stash->{$our_stash_key};
return 1 if defined $current_user->($c);
return undef;
};
}
sub authenticate_closure_p {
my ($our_stash_key, $session_key, $validate_user_cb_p, $current_user_p) = @_;
sub {
my ($c, $user, $pass, $extradata) = @_;
$extradata ||= {};
my $promise = defined($extradata->{auto_validate})
? Mojo::Promise->resolve($extradata->{auto_validate})
: $validate_user_cb_p->($c, $user, $pass, $extradata);
$promise->then(sub {
my ($uid) = @_;
return undef if !defined $uid;
$c->session($session_key => $uid);
# Clear stash to force reload of any already loaded user object
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
$self->plugin('Authentication' => {
autoload_user => 1,
session_key => 'wickedapp',
load_user_p => sub { ... },
validate_user_p => sub { ... },
});
# ...
$self->authenticate_p(
'username', 'password',
{ optional => 'extra data stuff' },
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
# or, synchronous style
$self->plugin('Authentication' => {
autoload_user => 1,
session_key => 'wickedapp',
load_user => sub { ... },
validate_user => sub { ... },
current_user_fn => 'user', # compatibility with old code
});
my $authenticated = $self->authenticate(
'username', 'password',
{ optional => 'extra data stuff' },
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
any trouble, but be aware that if you define methods with the same names as
those below, you'll likely run into unexpected results.
=head2 authenticate($username, $password, $extra_data_hashref)
Authenticate will use the supplied C<load_user> and C<validate_user>
subroutine refs to see whether a user exists with the given username and
password, and will set up the session accordingly. Returns true when the user
has been successfully authenticated, false otherwise. You can pass additional
data along in the C<extra_data> hashref, it will be passed to your
C<validate_user> subroutine as-is. If the extra data hash contains a key
C<auto_validate>, the value of that key will be used as the UID, and
authenticate will not call your C<validate_user> callback; this can be used
when working with OAuth tokens or other authentication mechanisms that do not
use a local username and password form.
=head2 authenticate_p($username, $password, $extra_data_hashref)
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
=item load_user (REQUIRED)
A coderef for user loading (see L</"USER LOADING">)
=item validate_user (REQUIRED)
A coderef for user validation (see L</"USER VALIDATION">)
=item session_key (optional)
lib/Mojolicious/Plugin/Authentication.pm view on Meta::CPAN
my ($app, $uid) = @_;
...
return $user;
}
The uid is the value that was originally returned from the C<validate_user>
coderef. You must return either a user object (it can be a hashref, arrayref,
or a blessed object) or undef.
=head1 USER VALIDATION
User validation is what happens when we need to authenticate someone. The
coderef you pass to the C<validate_user> configuration key has the following
signature:
sub {
my ($c, $username, $password, $extradata) = @_;
...
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/AutoReload.pm view on Meta::CPAN
|| $c->req->is_handshake;
# Prevent Mojolicious from doing anything else with this
# request.
$c->stash( 'mojo.finished', 1 );
$c->render_later;
# Client is just looking for a response, but validate their
# nonce first.
if ( !$c->param( 'nonce' ) || $c->param( 'nonce' ) ne $nonce ) {
return $c->rendered( 205 );
}
return $c->rendered( 204 );
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Bcrypt.pm view on Meta::CPAN
return bcrypt( $password, $settings );
}
);
$app->helper(
bcrypt_validate => sub {
my $c = shift;
my ( $plain, $crypted ) = @_;
return $c->bcrypt( $plain, $crypted ) eq $crypted;
}
);
lib/Mojolicious/Plugin/Bcrypt.pm view on Meta::CPAN
my $self = shift;
my $crypted_pass = $self->bcrypt( $self->param('password') );
...
}
=head2 bcrypt_validate
Validates a password against a crypted copy (for example from your database).
sub login {
my $self = shift;
my $entered_pass = $self->param('password');
my $crypted_pass = $self->get_password_from_db();
if ( $self->bcrypt_validate( $entered_pass, $crypted_pass ) ) {
# Authenticated
...;
}
else {
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/BcryptSecure.pm view on Meta::CPAN
$_[1],
$_[2] // $settings_without_salt . '$' . Crypt::Eksblowfish::Bcrypt::en_base64(Crypt::URandom::urandom(16)),
);
});
$app->helper(bcrypt_validate => sub {
return Mojo::Util::secure_compare Crypt::Eksblowfish::Bcrypt::bcrypt($_[1], $_[2]), $_[2];
});
}
1;
lib/Mojolicious/Plugin/BcryptSecure.pm view on Meta::CPAN
=encoding utf-8
=head1 NAME
Mojolicious::Plugin::BcryptSecure - Securely bcrypt and validate your passwords.
=head1 STATUS
=for html <a href="https://travis-ci.org/srchulo/Mojolicious-Plugin-BcryptSecure"><img src="https://travis-ci.org/srchulo/Mojolicious-Plugin-BcryptSecure.svg?branch=master"></a>
lib/Mojolicious/Plugin/BcryptSecure.pm view on Meta::CPAN
L<Crypt::URandom> is used to generate the salt used in L</bcrypt> with strongest available source of non-blocking randomness on the current platform.
=item
L<Mojo::Util/secure_compare> is used in L</bcrypt_validate> when comparing the crypted passwords to
help prevent timing attacks.
=back
You also may want to look at L<Mojolicious::Command::bcrypt> to help easily generate crypted passwords
lib/Mojolicious/Plugin/BcryptSecure.pm view on Meta::CPAN
# optionally pass your own settings
my $crypted_password = $c->bcrypt($plaintext_password, $settings);
C<$settings> is an optional string which encodes the algorithm parameters, as described in L<Crypt::Eksblowfish::Bcrypt>.
=head2 bcrypt_validate
Validates a password against a crypted password (from your database, for example):
if ($c->bcrypt_validate($plaintext_password, $crypted_password)) {
# Authenticated
} else {
# Uh oh...
}
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/CSRFDefender.pm view on Meta::CPAN
}
# input check
$app->hook(before_dispatch => sub {
my ($c) = @_;
unless ($self->_validate_csrf($c)) {
my $content;
if ($self->error_template) {
my $file = file($self->error_template);
$content = $file->slurp;
}
lib/Mojolicious/Plugin/CSRFDefender.pm view on Meta::CPAN
});
return $self;
}
sub _validate_csrf {
my ($self, $c) = @_;
my $p_name = $self->parameter_name;
my $s_name = $self->session_key;
my $request_token = $c->req->param($p_name);
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/CanonicalURL.pm view on Meta::CPAN
$should_not_canonicalize_request_config,
$inline_code,
$end_with_slash,
$canonicalize_before_render,
%captures
) = _parse_and_validate_config($config);
my $sub_string = '';
my ($path_declared, $path_with_no_slashes_at_the_end_declared);
if (defined $should_canonicalize_request_config) {
($path_declared, $path_with_no_slashes_at_the_end_declared, $sub_string) = _create_should_canonicalize_request_sub_string(
lib/Mojolicious/Plugin/CanonicalURL.pm view on Meta::CPAN
sub _quote_sub {
my ($sub_string, $captures) = @_;
return Sub::Quote::quote_sub $sub_string, $captures, {no_install => 1, no_defer => 1};
}
sub _parse_and_validate_config {
my ($config) = @_;
my (
$should_canonicalize_request,
$should_not_canonicalize_request,
lib/Mojolicious/Plugin/CanonicalURL.pm view on Meta::CPAN
if (%$config) {
my $captures_allowed;
if (exists $config->{should_canonicalize_request}) {
($should_canonicalize_request, $captures_allowed) =
_validate_should_canonicalize_request_config(delete $config->{should_canonicalize_request}, 1);
}
if (exists $config->{should_not_canonicalize_request}) {
($should_not_canonicalize_request, $captures_allowed) = _validate_should_canonicalize_request_config(
delete $config->{should_not_canonicalize_request},
undef,
);
}
lib/Mojolicious/Plugin/CanonicalURL.pm view on Meta::CPAN
$canonicalize_before_render,
%captures
);
}
sub _validate_should_canonicalize_request_config {
my ($config, $should_canonicalize_request) = @_;
my $captures_allowed;
my $config_name = _get_should_canonicalize_request_config_name($should_canonicalize_request);
my $config_reftype = Scalar::Util::reftype $config || '';
lib/Mojolicious/Plugin/CanonicalURL.pm view on Meta::CPAN
if (defined $reftype and $reftype eq 'SCALAR') {
$captures_allowed = 1;
}
if (defined $reftype and $reftype eq 'HASH') {
_validate_starts_with_hash($config_name, $_);
}
}
} elsif (defined $config_reftype and $config_reftype eq 'HASH') {
_validate_starts_with_hash($config_name, $config);
}
return ($config, $captures_allowed);
}
sub _validate_starts_with_hash {
my ($config_name, $hash) = @_;
my %copy = %$hash;
Carp::confess "must provide key 'starts_with' to hash in $config_name" unless exists $copy{starts_with};
Carp::confess 'value for starts_with must not be undef' unless defined $copy{starts_with};
Carp::confess 'value for starts_with must be a scalar'
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Captcha/reCAPTCHA.pm view on Meta::CPAN
$self->recaptcha->get_html( $self->app->recaptcha_public_key, $err, $use_ssl, $options )
);
}
);
$app->helper(
validate_recaptcha => sub {
my ( $self, $params ) = @_;
my $result = $self->recaptcha->check_answer( $self->app->recaptcha_private_key,
$self->tx->remote_address,
$params->{recaptcha_challenge_field},
lib/Mojolicious/Plugin/Captcha/reCAPTCHA.pm view on Meta::CPAN
This helper works like C<use_recaptcha> but returns the HTML instead of setting a stash
value. Also accepts the same params as C<use_recaptcha()>.
Intended to be used in templates.
=head2 validate_recaptcha
Handles the validation of the recaptcha. If an error occurs, the stash variable
"recaptcha_error" is set.
$self->validate_recaptcha( $params );
C<$params> is a hashref with parameters of the HTTP request.
Returns "true" (1) if validation was successful and "false" (0) otherwise.
=head1 AUTHORS
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Captcha.pm view on Meta::CPAN
return $image_data;
}
);
$app->helper(
validate_captcha => sub {
my ( $self, $string, $case_sens ) = @_;
return $case_sens
? $string eq &{$captcha_string}
: uc($string) eq uc(&{$captcha_string})
;
lib/Mojolicious/Plugin/Captcha.pm view on Meta::CPAN
1;
=head1 NAME
Mojolicious::Plugin::Captcha - create and validate captcha for Mojolicious framework
=head1 VERSION
0.02
lib/Mojolicious/Plugin/Captcha.pm view on Meta::CPAN
$self->render( data => $self->create_captcha );
}
sub some_post : Local {
my ($self, $c) = @_;
if ($self->validate_captcha($c->req->param('captcha')){
..
} else {
..
}
}
=head1 DESCRIPTION
This plugin create and validate Captcha, using L<GD::SecurityImage>
=head1 METHODS
=head2 create_captcha
Create Captcha image and output it.
=head2 validate_captcha
Validate captcha string
Accept optional second parameter to switch comparator case sensitivity (default is off, i.e. comparator make case insensivity comparing)
# case sensitivity comparing
$self->validate_captcha($self->param('captcha'), 1);
=head1 CONFIGURATION
=over 4
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/basic.t
t/config_override.t
t/lib/MojoliciousTest.pm
t/modes_passed_in.t
t/modes_passed_in_required.t
t/modes_validate.t
t/myapp.conf
t/myapp.dev.conf
t/myapp.development.conf
t/myapp.prod.conf
t/myapp.stage.conf
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/ClientIP/Pluggable.pm view on Meta::CPAN
=head1 METHODS
=head2 client_ip
Find a client IP address from the specified headers, with optional fallbacks. The address is
validated that it is publicly available (aka routable) IP address. Empty string is returned
if no valid address can be found.
=head1 OPTIONS
=head2 analyzed_headers
lib/Mojolicious/Plugin/ClientIP/Pluggable.pm view on Meta::CPAN
next unless $f;
my @pairs = map { split $comma_re, $_ } split ';', $f;
my @ips = map {
my $ipv4_mask = qr/\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/;
# it is not completely valid ipv6 mask, but enough
# to extract address. It will be validated later
my $ipv6_mask = qr/[\w:]+/;
if (/for=($ipv4_mask)|(?:"?\[($ipv6_mask)\].*"?)/i) {
($1 // $2);
} else {
();
lib/Mojolicious/Plugin/ClientIP/Pluggable.pm view on Meta::CPAN
next unless $address_family;
# possibly limit to acceptable address family
next if $restrict_family && $restrict_family ne $address_family;
# validate by family
my $validator = $validator_for{$address_family};
next unless $validator->($ip);
# address seems valid, return its textual representation
return $ip;
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
]
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
my $tables = $command->show_tables($database);
return $self->render(
database => $database,
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
],
table => {default => ''} => [
'safety_name'
]
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
my $table = $vresult->data->{table};
my $table_def = $command->show_create_table($database, $table);
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
]
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
my $tables = $command->show_tables($database);
# Get create tables
my $create_tables = {};
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
]
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
my $tables = $command->show_tables($database);
$self->render(
database => $database,
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
],
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
# Get primary keys
my $primary_keys = $command->show_primary_keys($database);
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
],
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
# Get null allowed columns
my $null_allowed_columns = $command->show_null_allowed_columns($database);
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
],
v1 => [
'not_blank'
]
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
my $table = $vresult->data->{table};
# Where
my $column = $vresult->data->{c1};
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
],
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
# Get primary keys
my $database_engines = $command->show_database_engines($database);
lib/Mojolicious/Plugin/DBViewer/MySQL.pm view on Meta::CPAN
my $rule = [
database => {default => ''} => [
'safety_name'
],
];
my $vresult = $plugin->validator->validate($params, $rule);
my $database = $vresult->data->{database};
# Get primary keys
my $charsets = $command->show_charsets($database);
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
package Mojolicious::Plugin::Data::Validate::WithYAML;
# ABSTRACT: validate form input with Data::Validate::WithYAML
use strict;
use warnings;
use parent 'Mojolicious::Plugin';
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
my ($self, $app, $config) = @_;
$config->{conf_path} = $app->home if !$config->{conf_path};
$config->{no_steps} = 1 if !defined $config->{no_steps};
$app->helper( 'validate' => sub {
my ($c, $file, $step) = @_;
my $validator = _validator( $file, $config );
my %params = %{ $c->req->params->to_hash };
my @args = $step ? $step : ();
my %errors = $validator->validate( @args, %params );
my $prefix = exists $config->{error_prefix} ?
$config->{error_prefix} :
'ERROR_';
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
=encoding UTF-8
=head1 NAME
Mojolicious::Plugin::Data::Validate::WithYAML - validate form input with Data::Validate::WithYAML
=head1 VERSION
version 0.06
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
sub register {
my $self = shift;
# might be (age => 'You are too young', name => 'name is required')
# or with error_prefix (ERROR_age => 'You are too young', ERROR_name => 'name is required')
my %errors = $self->validate( 'registration' );
if ( %errors ) {
$self->stash( %errors );
$self->render;
return;
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
type: optional
plugin: URL
=head1 HELPERS
=head2 validate
my %errors = $controller->validate( $yaml_name );
Validates the parameters. Optional parameter is I<$yaml_name>. If I<$yaml_name> is ommitted, the subroutine name (e.g. "register") is used.
=head1 AUTHOR
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/samples/perlmonks.html view on Meta::CPAN
any other options ?
</i>
<br />
<br />
Do we have some perl code checker available for us to validate scripts / modules ?
<br />Thanks
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-1052035">
<i>Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats</i>
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/FormFields.pm view on Meta::CPAN
if($eq) {
$field->{$eq} = $self->{c}->param($eq);
push @{$rules->{fields}}, $eq;
}
$result = Validate::Tiny::validate($field, $rules);
$self->{c}->param($name, $result->{data}->{$name}) if @{$self->{filters}};
$self->{result} = $result;
$result->{success};
}
lib/Mojolicious/Plugin/FormFields.pm view on Meta::CPAN
<% } %>
=head1 VALIDATING & FILTERING
Validation rules are created by calling validation and/or filter methods
on the field to be validated
# In your controller
my $self = shift;
$self->field('user.name')->is_required;
$self->field('user.name')->filter('trim');
lib/Mojolicious/Plugin/FormFields.pm view on Meta::CPAN
$field = $self->field('user.name');
$field->is_required;
$field->valid;
$field->error;
This will only validate and return the error for the C<user.name> field. To validate all fields and retrieve all error messages call the controller's C<valid> and C<errors> methods
$self->field('user.name')->is_required;
$self->field('user.age')->is_like(qr/^\d+$/);
$self->valid;
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/FormFieldsFromJSON.pm view on Meta::CPAN
return @fields;
}
);
$app->helper(
'validate_form_fields' => sub {
my ( $c, $file ) = @_;
return '' if !$file;
if ( !$configs{$file} ) {
lib/Mojolicious/Plugin/FormFieldsFromJSON.pm view on Meta::CPAN
]
);
This way, you can build your forms dynamically (e.g. based on database entries).
=head2 validate_form_fields
This helper validates the input. It uses the L<Mojolicious::Validator::Validation> and it
validates all fields defined in the configuration file.
For more details see L<Validation|Mojolicious::Plugin::FormFieldsFromJSON/Validation>.
=head2 forms
lib/Mojolicious/Plugin/FormFieldsFromJSON.pm view on Meta::CPAN
=back
=head1 Validation
You can define some validation rules in your config file. And when you call C<validate_form_fields>, the
fields defined in the configuration file are validated.
L<Mojolicious::Validator::Validation> is shipped with some basic validation checks:
=over 4
lib/Mojolicious/Plugin/FormFieldsFromJSON.pm view on Meta::CPAN
},
"name" : "name"
}
]
Then you can call C<validate_form_fields>:
my %errors = $c->validate_form_fields( $config_name );
In the returned hash, you get the fieldnames as keys where a validation check fails.
=head2 A mandatory string
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
use Mojo::JSON;
use Mojo::Util qw{decode};
use Mojo::Parameters;
use Scalar::Util qw(blessed);
our @EXPORT_OK = qw(extract validate),
our $TERM_PROPERTIES = 'properties';
our $TERM_REQUIRED = 'required';
our $TERM_MAXLENGTH = 'maxLength';
our $TERM_MIN_LENGTH = 'minLength';
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
$TERM_PROPERTIES => $props,
$TERM_ADD_PROPS => Mojo::JSON->false,
};
}
sub validate {
my ($schema, $params, $charset) = @_;
if (! (blessed($params) && $params->isa('Mojo::Parameters'))) {
my $wrapper = Mojo::Parameters->new;
$wrapper->charset($charset);
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
my $schema = extract($form_in_mojo_dom)
Generates a schema out of form string or Mojo::DOM instance. It returns
schema in hashref consists of JSON-schema-like properties.
=head3 validate
Validates form data against given schema.
my $error = validate($params_in_string, $schema, $charset);
my $error = validate($params_in_mojo_params, $schema);
=head1 AUTHOR
Sugama Keita, E<lt>sugama@jamadam.comE<gt>
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
use Mojo::JSON;
use Mojo::Util qw{decode};
use Mojo::Parameters;
use Scalar::Util qw(blessed);
our @EXPORT_OK = qw(extract validate),
our $TERM_PROPERTIES = 'properties';
our $TERM_REQUIRED = 'required';
our $TERM_MAXLENGTH = 'maxLength';
our $TERM_MIN_LENGTH = 'minLength';
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
$TERM_PROPERTIES => $props,
$TERM_ADD_PROPS => Mojo::JSON->false,
};
}
sub validate {
my ($schema, $params, $charset) = @_;
if (! (blessed($params) && $params->isa('Mojo::Parameters'))) {
my $wrapper = Mojo::Parameters->new;
$wrapper->charset($charset);
lib/HTML/ValidationRules/Legacy.pm view on Meta::CPAN
my $schema = extract($form_in_mojo_dom)
Generates a schema out of form string or Mojo::DOM instance. It returns
schema in hashref consists of JSON-schema-like properties.
=head3 validate
Validates form data against given schema.
my $error = validate($params_in_string, $schema, $charset);
my $error = validate($params_in_mojo_params, $schema);
=head1 AUTHOR
Sugama Keita, E<lt>sugama@jamadam.comE<gt>
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
cpanfile
dist.ini
lib/Mojolicious/Plugin/Gzip.pm
t/author-pod-syntax.t
t/basic.t
t/config_validate.t
t/etag.t
t/min_size.t
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/HTMLLint.pm view on Meta::CPAN
# Mojolicious::Lite
plugin 'HTMLLint';
=head1 DESCRIPTION
L<Mojolicious::Plugin::HTMLLint> - allows you to validate HTML rendered by your application. The plugin uses HTML::Lint for validation. Errors will appear in Mojolicious log.
=head1 CONFIG
Config will be passed to HTML::Lint->new();
For supported options see L<HTML::Lint>
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
- `<prefix>_signout($identify)`: clear session and cookies, remove DB entry.
- `<prefix>_has_auth`: check cookie + CSRF against the backend. Returns `{result => 1}` on success, `{result => 2}` when locked, `{result => 3}` when the CSRF token mismatches, or `{result => 0}` when missing/expired. Stashes backend id, identify, an...
- `<prefix>_auth_update($identify)`: rotate cookie and CSRF token for an active session.
- `<prefix>_lock` / `<prefix>_unlock`: issue or clear the lock cookie when `lock` is enabled.
- `<prefix>_csrf`: ensure a CSRF token exists in the session/response headers.
- `<prefix>_csrf_get`, `<prefix>_csrf_val`, `<prefix>_csrf_regen`: read, validate, or regenerate the CSRF token.
- `<prefix>_backend`: access the underlying backend object (e.g. for inspecting connection status).
### Lock/unlock flow
Call `<prefix>_lock` after `*_has_auth` passes to mark the session locked; a lock cookie is issued and the backend row is marked. Use `<prefix>_unlock` to clear the lock. When locked, `*_has_auth` returns `{result => 2, code => 423, lock_cookie => 0|...
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Host.pm view on Meta::CPAN
our $VERSION = '0.01';
sub register {
my (undef, $app, $config) = @_;
my ($helper, $www) = _parse_and_validate_config($config);
my $sub;
if (not defined $www) {
$sub = sub { $_[0]->req->url->to_abs->host };
} elsif ($www eq 'always') {
$sub = sub {
lib/Mojolicious/Plugin/Host.pm view on Meta::CPAN
}
$app->helper($helper => $sub);
}
sub _parse_and_validate_config {
my ($config) = @_;
my $helper;
if (exists $config->{helper}) {
$helper = delete $config->{helper};
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
push @{ $app->renderer->classes }, __PACKAGE__;
my %defaults = %$user_defaults;
$defaults{realm} //= 'WWW';
$defaults{validate} //= sub {
die('please define a validate callback');
};
$defaults{invalid} //= sub {
my $controller = shift;
return (
json => { json => { error => 'HTTP 401: Unauthorized' } },
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
# No credentials entered
return $plugin->_unauthorized($controller, $options{realm}, $options{invalid}) unless ($auth);
# Verification within callback
return 1 if $options{validate} and $options{validate}->($controller, split(/:/, $auth, 2), $options{realm});
# Not verified
return $plugin->_unauthorized($controller, $options{realm}, $options{invalid});
}
);
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
=head1 SYNOPSIS
# in your startup
$self->plugin(
'http_basic_auth', {
validate => sub {
my $c = shift;
my $loginname = shift;
my $password = shift;
my $realm = shift;
return 1 if($realm eq 'Evergreen Terrace' && $loginname eq 'Homer' && $password eq 'Marge');
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
# or bridged
my $foo = $r->bridge('/bridge')->to(cb => sub {
my $self = shift;
# Authenticated
return unless $self->basic_auth({realm => 'Castle Bridge', validate => sub {return 1;}});
});
$foo->route('/bar')->to(controller => 'foo', action => 'bar');
=head1 DESCRIPTION
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
$self->plugin('http_basic_auth', {realm => 'My Castle!'});
HTTP-Realm, defaults to 'WWW'
=head2 validate
$self->plugin('http_basic_auth', {
validate => sub {
my $c = shift;
my $loginname = shift;
my $password = shift;
my $realm = shift;
return 1 if($realm eq 'Springfield' && $loginname eq 'Homer' && $password eq 'Marge');
lib/Mojolicious/Plugin/HttpBasicAuth.pm view on Meta::CPAN
L<Mojolicious::Plugin> and implements the following new ones.
=head2 register
my $route = $plugin->register(Mojolicious->new);
my $route = $plugin->register(Mojolicious->new, {realm => 'Fort Knox', validate => sub {
return 0;
}});
Register renderer and helper in L<Mojolicious> application.
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/InputValidation.pm view on Meta::CPAN
return 0;
}
if ($self->{of}) {
for (my $i = 0; $i < ($self->{max} // $elems); $i++) {
my $err = Mojolicious::Plugin::InputValidation::_validate_structure($value->[$i], $self->{of}, "$path/$i");
if ($err) {
$self->error($err);
return 0;
}
}
}
elsif ($self->{pattern} && !$self->{min} && !$self->{min}) {
for (my $i = 0; $i < scalar @{$self->{pattern}}; $i++) {
my $err = Mojolicious::Plugin::InputValidation::_validate_structure($value->[$i], $self->{pattern}[$i], "$path/$i");
if ($err) {
$self->error($err);
return 0;
}
lib/Mojolicious/Plugin/InputValidation.pm view on Meta::CPAN
$self->error(sprintf("Missing keys '%s' at path %s", join(',', @missing), $path || '/'));
return 0;
}
for my $key (grep { $have_keys{$_} } @want_keys) {
my $err = Mojolicious::Plugin::InputValidation::_validate_structure($value->{$key}, $self->{pattern}{$key}, "$path/$key");
if ($err) {
$self->error($err);
return 0;
}
lib/Mojolicious/Plugin/InputValidation.pm view on Meta::CPAN
}
sub register {
my ($self, $app, $conf) = @_;
$app->helper(validate_json_request => sub {
my ($c, $pattern) = @_;
return _validate_structure($c->req->json, $pattern);
});
$app->helper(validate_params => sub {
my ($c, $pattern) = @_;
return _validate_structure($c->params, $pattern);
});
$app->helper(validate_structure => sub {
my ($c, $structure, $pattern) = @_;
return _validate_structure($structure, $pattern);
});
}
sub _validate_structure {
my ($input, $pattern, $path) = @_;
if (ref $pattern eq 'HASH') {
$pattern = iv_object($pattern);
}
lib/Mojolicious/Plugin/InputValidation.pm view on Meta::CPAN
post '/books' => sub {
my $c = shift;
# Validate incoming requests against our data model.
if (my $error = $c->validate_json_request({
title => iv_any,
abstract => iv_any(optional => 1, empty => 1),
author => {
firstname => iv_word,
lastname => iv_word,
lib/Mojolicious/Plugin/InputValidation.pm view on Meta::CPAN
=head1 METHODS
L<Mojolicious::Plugin::InputValidation> adds methods to the connection object
in a mojolicous controller. This way input validation becomes easy.
=head2 validate_json_request
my $error = $c->validate_json_request($pattern);
This method try to match the json request payload ($c->req->json) against the
given pattern. If the payload matches, a false value is returned. If the payload
on the other hand does not match the pattern, the first non-matching value is
returned along with a speaking error message. The error message could look like:
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Kinde.pm view on Meta::CPAN
$self->jwt( Mojo::JWT->new( jwks => $jwks_keys ) );
$self->iss( $conf->{iss} || $app->config->{kinde}->{iss} );
$self->audience( $conf->{audience} || $app->config->{kinde}->{audience} );
$app->helper( get_kinde_claims => sub { _validate_auth_header( $self, @_ ) } );
$app->routes->add_condition( kinde_auth => sub { _validate_route( $self, @_ ) } );
} ## end sub register
sub _validate {
my ( $self, $c, $token ) = @_;
if ($token) {
my $token_data = $token ? $self->jwt->decode($token) : undef;
lib/Mojolicious/Plugin/Kinde.pm view on Meta::CPAN
return undef;
} ## end if ($token)
} ## end sub _validate
sub _validate_auth_header {
my ( $self, $c ) = @_;
my $headers = $c->req->headers;
my $auth = $headers->header('Authorization');
my $token = $auth ? ( split( ' ', $auth ) )[1] : undef;
return $self->_validate( $c, $token );
} ## end sub _validate_auth_header
sub _validate_route {
my ( $self, $route, $c, $captures, $arg ) = @_;
my $headers = $c->req->headers;
my $auth = $headers->header('Authorization');
my $token = $auth ? ( split( ' ', $auth ) )[1] : undef;
return $self->_validate( $c, $token ) ? 1 : 0;
} ## end sub _validate_route
1;
=pod
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
share/public/leaflet.js view on Meta::CPAN
/*
Leaflet, a JavaScript library for mobile-friendly interactive maps. http://leafletjs.com
(c) 2010-2013, Vladimir Agafonkin
(c) 2010-2011, CloudMade
*/
!function(t,e,i){var n=t.L,o={};o.version="0.6.4","object"==typeof module&&"object"==typeof module.exports?module.exports=o:"function"==typeof define&&define.amd&&define(o),o.noConflict=function(){return t.L=n,this},t.L=o,o.Util={extend:function(t){v...
},addTo:function(t){return t.addLayer(this),this},onRemove:function(t){this._container.parentNode.removeChild(this._container),t.off({viewreset:this._reset,moveend:this._update},this),this._animated&&t.off({zoomanim:this._animateZoom,zoomend:this._en...
o.DomUtil.addClass(t,"leaflet-vml-shape"),this.options.clickable&&o.DomUtil.addClass(t,"leaflet-clickable"),t.coordsize="1 1",this._path=this._createElement("path"),t.appendChild(this._path),this._map._pathRoot.appendChild(t)},_initStyle:function(){t...
},removeHooks:function(){o.DomEvent.off(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(t.touches){if(o.DomEvent.preventDefault(t),this._fireClick=!0,t.touches.length>1)return this._fireClick=!1,clearTimeout(this._holdTim...
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Materialize/css/materialize.css view on Meta::CPAN
content: attr(data-error);
color: #F44336;
opacity: 1;
}
input:not([type]).validate + label,
input[type=text].validate + label,
input[type=password].validate + label,
input[type=email].validate + label,
input[type=url].validate + label,
input[type=time].validate + label,
input[type=date].validate + label,
input[type=datetime].validate + label,
input[type=datetime-local].validate + label,
input[type=tel].validate + label,
input[type=number].validate + label,
input[type=search].validate + label,
textarea.materialize-textarea.validate + label {
width: 100%;
pointer-events: none;
}
input:not([type]) + label:after,
lib/Mojolicious/Plugin/Materialize/css/materialize.css view on Meta::CPAN
.input-field.col label {
left: 0.75rem;
}
.input-field.col .prefix ~ label,
.input-field.col .prefix ~ .validate ~ label {
width: calc(100% - 3rem - 1.5rem);
}
.input-field label {
color: #9e9e9e;
lib/Mojolicious/Plugin/Materialize/css/materialize.css view on Meta::CPAN
}
.input-field .prefix ~ input,
.input-field .prefix ~ textarea,
.input-field .prefix ~ label,
.input-field .prefix ~ .validate ~ label,
.input-field .prefix ~ .autocomplete-content {
margin-left: 3rem;
width: 92%;
width: calc(100% - 3rem);
}
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Memorize.pm view on Meta::CPAN
= ref $_[0] eq 'HASH' ? (undef, shift) : (shift, shift || {});
# Default name
$name ||= join '', map { $_ || '' } (caller(1))[0 .. 3];
# Return memorized result or invalidate cached
return $mem->{$name}{content} if $self->_check_cached($name);
# Determine new expiration time
my $expires = 0;
if ( my $delta = $args->{duration} ) {
view all matches for this distributionview release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/MoreHelpers.pm view on Meta::CPAN
return is_ip $value ? undef : 1;
});
$app->validator->add_check(email_address => sub {
my ($validate, $name, $value) = @_;
my ($email) = Email::Address->parse($value);
return defined $email && $email->address ? undef : 1;
});
}
view all matches for this distributionview release on metacpan - search on metacpan