I’m following the Restricting access coockbook but I would like the page to be a virtual one. I converted the .txt
files (It’s multi-language site) to a virtual page following the example of simple virtual page guide for multilingual site and deleted the page from the content folder
The page shows up but when I login it sends me to the error page. I did not modified any other files.
It works if I comment out the routes and use the txt files on the content folder. Here are the txt files and the virtual page:
login.es.txt
Title: Iniciar sesión
----
Alert: Correo o contraseña inválidos.
----
Email: Correo electrónico
----
Password: Contraseña
----
Button: Iniciar sesión
login.en.txt
Title: Login
----
Alert: Invalid user or password
----
Email: Email
----
Password: Password
----
Button: Log in
my config.php
<?php
return [
'debug' => true,
'languages' => true,
'date.handler' => 'strftime',
'languages.detect' => true,
'routes' => [
[
'pattern' => '(es|en)/login',
'action' => function ($lang) {
$data = [
'slug' => 'login',
'template' => 'login',
'translations' => [
'es' => [
'code' => 'es',
'content' => [
'title' => 'Iniciar sesión',
'alert' => 'Correo o contraseña no válidos.',
'email' => 'Correo electrónico',
'password' => 'Contraseña',
'button' => 'Iniciar sesion'
]
],
'en' => [
'code' => 'en',
'content' => [
'title' => 'Login',
'alert' => 'Invalid user or password.',
'email' => 'Email',
'password' => 'Password',
'button' => 'Log in'
]
]
],
];
$page = Page::factory($data);
site()->visit($page, $lang);
return $page;
}
],
[
'pattern' => '(es|en)/logout',
'action' => function() {
if ($user = kirby()->user()) {
$user->logout();
}
go(kirby()->languageCode() . '/login');
}
]
]
];