Closed Stadly closed 5 years ago
I cannot think of any way that Kimai would create such a URL. In the theoretical case that a language is missing, an exception is thrown as there is no route existing within the app for //timesheet/ Can you reproduce it? The only way I see is if you use a new user, that did not set a language and that has no language in the URL (again, I don't see how that should be possible). Are you sure that your webserver is not intercepting some URLs?
Edit: I tried it with "Accept-Lanague: ab,en-US;q=0.5" and it still works.
Managed to reproduce it!
Setting kimai2_user_preferences.language
to NULL
or the empty string for my user directly in the database causes a redirect to //timesheet/
.
In our case, kimai2_user_preferences.language
is the empty string for several users, after importing data from Kimai v1.
Setting kimai2_user_preferences.language
to ab
leads to a redirect to /ab/timesheet/
, which yields a 500 server error.
It would probably be a good idea to sanitize the language, and not just blindly trust the database value.
Hm, the error is in the importer then. I am not aware that you can manage to get invalid languages into the database otherwise. Thanks for that hint!
Can you try to replace the function within the file src/Controller/HomepageController.php
:
public function indexAction(Request $request): RedirectResponse
{
/** @var User $user */
$user = $this->getUser();
$userRoute = $user->getPreferenceValue('login.initial_view', InitialViewType::DEFAULT_VIEW);
$userLanguage = $user->getLocale();
$requestLanguage = $request->getLocale();
$routes = [
[$userRoute, $userLanguage],
[$userRoute, $requestLanguage],
[$userRoute, User::DEFAULT_LANGUAGE],
[InitialViewType::DEFAULT_VIEW, $userLanguage],
[InitialViewType::DEFAULT_VIEW, $requestLanguage],
];
foreach ($routes as $routeSettings) {
$route = $routeSettings[0];
$language = $routeSettings[1];
try {
return $this->redirectToRoute($route, ['_locale' => $language]);
} catch (\Exception $exception) {
// something is wrong with the url parameters ...
}
}
return $this->redirectToRoute(InitialViewType::DEFAULT_VIEW, ['_locale' => User::DEFAULT_LANGUAGE]);
}
Afterwards run bin/console cache:clear --env=prod
and bin/console cache:warmup --env=prod
and see if the error still happens.
When looking at the Kimai v1 database, there are several users with kimai_preferences.ui.lang
set to the empty string. So it seems the importer have just copied the values from Kimai v1 to Kimai v2 without any validation or sanitization.
With the changes from your comment, I am redirected to /en/homepage
and get a 500 error.
With the changes in #1054, I am redirected to /en/timesheet/
, so that works :)
Hooray & thanks for testing!
But I am not sure, that Kimai will work properly with an empty language. This might be fixed for future imports - but please update the preferences for your users, so that they don't have an empty language string.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. If you use Kimai on a daily basis, please consider donating to support further development of Kimai.
Our Kimai installation is available on a url like this:
https://kimai.mysite.com
. When I open that url, I am redirected tohttps://kimai.mysite.com/en/timesheet/
. Some users, however, are redirected tohttps://timesheet/
. I have gotten three reports of this behavior so far, and I installed the system two days ago. If they enter the the full urlhttps://kimai.mysite.com/en/timesheet/
, they are able to use Kimai.I logged the redirects that happen, and they go like this:
https://kimai.mysite.com/
/en/homepage
//timesheet/
When I open the url, these are the redirects:
https://kimai.mysite.com/
/en/homepage
/en/timesheet/
Could it have something to do with the locale? The locale seems to be missing from the erroneous redirect, and as you can see from the more extensive logs below,
Accept-Language
does not start withen
in the case where the redirect fails. I am not sure whether this is the case for everybody who has reported the problem.More extensive logs of the redirects:
Erroneous redirects:
Working redirects:
Desktop/Smartphone Please complete the following information if this seems to be a frontend issue:
Additional context Add any other context about the problem here.