diff --git a/lib/Mojolicious/Plugin/Yancy.pm b/lib/Mojolicious/Plugin/Yancy.pm index 3cb46c67..0f5e37d9 100644 --- a/lib/Mojolicious/Plugin/Yancy.pm +++ b/lib/Mojolicious/Plugin/Yancy.pm @@ -83,12 +83,12 @@ By default, the L form plugin is loaded. You can override this with your own form plugin. See L for more information. -=head2 yancy.file +=head2 File storage -By default, the L 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 for more information. +By default, the editor stores uploaded files in a L +rooted at C<$MOJO_HOME/public/uploads>. You can override this with +C<< editor => { storage => ... } >>. See L for more +information. =head2 yancy.plugin @@ -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 ); @@ -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} // {} }, } ); } diff --git a/lib/Yancy/Auth.pm b/lib/Yancy/Auth.pm index 02f5636d..88403b0b 100644 --- a/lib/Yancy/Auth.pm +++ b/lib/Yancy/Auth.pm @@ -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 ); diff --git a/lib/Yancy/Auth/templates/auth/password.html.ep b/lib/Yancy/Auth/templates/auth/password.html.ep index 9e1539b8..0b3beb51 100644 --- a/lib/Yancy/Auth/templates/auth/password.html.ep +++ b/lib/Yancy/Auth/templates/auth/password.html.ep @@ -1,14 +1,14 @@
- +
- +
- +
diff --git a/t/controller/model.t b/t/controller/model.t index dc6cdb99..8c9d09ff 100644 --- a/t/controller/model.t +++ b/t/controller/model.t @@ -6,7 +6,7 @@ API =head1 SEE ALSO -L +L =cut @@ -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; diff --git a/t/i18n.t b/t/i18n.t index e84d1037..663884cc 100644 --- a/t/i18n.t +++ b/t/i18n.t @@ -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'; @@ -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();