Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/Mojolicious/Plugin/Yancy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ By default, the L<Yancy::Plugin::Form::Bootstrap4> form plugin is
loaded. You can override this with your own form plugin. See
L<Yancy::Plugin::Form> for more information.

=head2 yancy.file
=head2 File storage

By default, the L<Yancy::Plugin::File> plugin is loaded to handle file
uploading and file management. The default path for file uploads is
C<$MOJO_HOME/public/uploads>. You can override this with your own file
plugin. See L<Yancy::Plugin::File> for more information.
By default, the editor stores uploaded files in a L<Yancy::Storage>
rooted at C<$MOJO_HOME/public/uploads>. You can override this with
C<< editor => { storage => ... } >>. See L<Yancy::Storage> for more
information.

=head2 yancy.plugin

Expand Down Expand Up @@ -165,6 +165,7 @@ use Mojo::File qw( path );
use Mojo::Loader qw( load_class );
use Yancy::Util qw( load_backend curry copy_inline_refs is_type json_validator );
use Yancy::Model;
use Yancy::Storage;
use Storable qw( dclone );
use Scalar::Util qw( blessed );

Expand Down Expand Up @@ -215,13 +216,11 @@ sub register {
# override this one
# XXX: Form and File should both be part of the content plugin
$app->plugin( 'Yancy::Plugin::Form::Bootstrap4' );
$app->plugin( 'Yancy::Plugin::File' => {
path => $app->home->child( 'public/uploads' ),
} );

# Add the default editor unless the user explicitly disables it
if ( !exists $config->{editor} || defined $config->{editor} ) {
$app->plugin( 'Yancy::Plugin::Editor' => {
storage => Yancy::Storage->new( $app->home->child( 'public/uploads' ) ),
%{ $config->{editor} // {} },
} );
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Yancy/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ sub new($class, $app, @args) {
push @{$app->renderer->paths}, "$templates";
}

# Auth templates use the `l` helper for translated strings
if (!$app->renderer->get_helper('l')) {
$app->plugin('I18N', { namespace => 'Yancy::I18N' });
}

# TODO: Auth sets up routes in $app

$self->model->add_auth( $self );
Expand Down
6 changes: 3 additions & 3 deletions lib/Yancy/Auth/templates/auth/password.html.ep
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<form action="<%= $auth->url_for($c) %>" method="POST">
<input type="hidden" name="return_to" value="<%= stash 'return_to' %>" />
<div class="form-group">
<label for="yancy-login">Login</label>
<label for="yancy-login"><%= l 'Login' %></label>
<input class="form-control" id="yancy-login" name="login"
placeholder="Login" value="<%= stash 'login' %>"
>
</div>
<div class="form-group">
<label for="yancy-password">Password</label>
<label for="yancy-password"><%= l 'Password' %></label>
<input type="password" class="form-control" id="yancy-password" name="password" placeholder="Password">
</div>
<button class="btn btn-primary">Login</button>
<button class="btn btn-primary"><%= l 'Login' %></button>
</form>
4 changes: 2 additions & 2 deletions t/controller/model.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ API

=head1 SEE ALSO

L<Yancy::Controller::Yancy>
L<Yancy::Controller::Model>

=cut

Expand All @@ -19,7 +19,7 @@ use Mojo::File qw( path );
use Scalar::Util qw( blessed );
use lib "".path( $Bin, '..', 'lib' );
use Local::Test qw( init_backend load_fixtures );
use Yancy::Controller::Yancy;
use Yancy::Controller::Model;

my $schema = \%Local::Test::SCHEMA;

Expand Down
51 changes: 29 additions & 22 deletions t/i18n.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use FindBin qw( $Bin );
use Mojo::File qw( path );
use lib "".path( $Bin, 'lib' );
use Local::Test qw( init_backend );
use Digest;
use Data::Dumper;
use Yancy::User;
use Yancy::Auth::Password;

package MyApp::I18N;
use base 'Locale::Maketext';
Expand All @@ -18,43 +18,50 @@ our %Lexicon = ( 'Username' => 'Логин', 'Password' => 'Пароль', 'Logi

package main;

my ( $backend_url, $backend, %items ) = init_backend(
\%Local::Test::SCHEMA,
user => [
{
username => 'pavelsr',
password => Digest->new( 'SHA-1' )->add( '123qwe' )->b64digest . '$SHA-1',
email => 'pavel@example.com',
}
],
);
my ( $backend_url, $backend, %items ) = init_backend( \%Local::Test::SCHEMA );

$backend->{schema}{users} = {
'x-id-field' => 'user_id',
properties => {
user_id => { type => 'integer' },
login => { type => 'string' },
},
};
$backend->{schema}{auth_attributes} = {
'x-id-field' => 'auth_attribute_id',
properties => {
auth_attribute_id => { type => 'integer' },
user_id => { type => 'integer' },
provider_name => { type => 'string' },
attribute => { type => 'string' },
value => { type => 'string' },
},
};

my $t = Test::Mojo->new( 'Mojolicious' );
$t->app->plugin( 'Yancy', {
backend => $backend_url,
schema => \%Local::Test::SCHEMA,
} );
$t->app->plugin( 'Yancy::Plugin::Auth::Password', {
schema => 'user',
username_field => 'username',
password_field => 'password',
password_digest => { type => 'SHA-1' },
allow_register => 1,
} );
my $auth = Yancy::Auth::Password->new( $t->app,
model => Yancy::User->new( backend => $backend ),
digest => { type => 'SHA-1' },
);

subtest 'Yancy && Mojolicious::Plugin::I18N integration' => sub {
my $c = $t->app->build_controller;
is 'Hello', $c->helpers->l('Hello'), 'Helper l is available';
};

subtest 'login_form with russian language' => sub {
subtest 'login form with russian language' => sub {
$t->app->plugin('Mojolicious::Plugin::I18N', { namespace => 'MyApp::I18N' } );
my $c = $t->app->build_controller;
$c->languages('ru');
ok my $html = $c->yancy->auth->login_form, 'login form is returned';
ok my $html = $auth->form_for( $c ), 'login form is returned';
my $dom = Mojo::DOM->new( $html );
is $dom->at( 'label[for=yancy-username]' )->text, 'Логин', 'username ru ok';
is $dom->at( 'label[for=yancy-login]' )->text, 'Вход', 'login ru ok';
is $dom->at( 'label[for=yancy-password]' )->text, 'Пароль', 'password ru ok';
is $dom->at( 'button' )->text, 'Вход', 'button ru ok';
};

done_testing();
Loading