Is it possible to extend the routes of the core in the app routes.php file?
So that the route is not “domain/apps/appname/route”.
The route should be “domain/route”
It is very dangerous and fragile to do this.
It also limits you in the development of your app quite a bit.
So unless really necessary, try to avoid it.
What would you need it for?
I’ve tried to implement a Controller that extends the AuthPublicShareController.
The getRoutes function of the AuthPublicShareController returns as route:
$app = strtolower($this->appName);
$class = strtolower((new \ReflectionClass($this))->getShortName());
return $app . '.' . $class . '.' . $function;
So the route is with the name of the class with the word controller.
I’ve only made it running when I extended the core/routes.php in this file its possible to declare the route with the word ‘controller’ at the end.
In the app routes.php I didn’t find a way to declare the routes with the word ‘controller’ at the end.
You should define your routes in your own app, similar to this:
I’ve already defined that way, but if I do that an Exception is thrown:
Symfony\Component\Routing\Exception\RouteNotFoundException : Unable to generate a URL for the named route “<my_namespace.authsecretsharecontroller.showAuthenticate” as such route does not exist.
Because the AuthPublicShareController returns the class name.
The right route that should be returned from the function should be:
“<my_namespace.authsecretshare.showAuthenticate”
or did I configure something wrong?
The code above is a working example. In your apps own appinfo/routes.php
you don’t define a namespace nor mention the word controller. That is all down automatically afterswards
I know my code looks like this:
/appinfo/routes.php:
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'auth_secret_share#showShare', 'url' => '/secret/{token}', 'verb' => 'GET'],
['name' => 'auth_secret_share#showAuthenticate', 'url' => '/secret/{token}/authenticate/{redirect}', 'verb' => 'GET'],
['name' => 'auth_secret_share#authenticate', 'url' => '/secret/{token}/authenticate/{redirect}', 'verb' => 'POST'],
]
];
/lib/Controller/AuthSecretShareController.php:
class AuthSecretShareController extends AuthPublicShareController{
public function __construct(string $appName, IRequest $request, ISession $session, IURLGenerator $urlGenerator, Defaults $defaults, SecretMapper $mapper)
{
parent::__construct($appName, $request, $session, $urlGenerator);
$this->urlGenerator = $urlGenerator;
$this->defaults = $defaults;
$this->secret = new Secret();
$this->mapper = $mapper;
}
/**
* @inheritDoc
*/
protected function verifyPassword(string $password): bool
{
return $password == '123';// TODO: Implement verifyPassword() method.
}
/**
* @PublicPage
* @NoCSRFRequired
*
* Show the authentication page
* The form has to submit to the authenticate method route
*/
public function showAuthenticate(): TemplateResponse {
parent::showAuthenticate();
}
/**
* @inheritDoc
* @NoCSRFRequired
* @PublicPage
*/
public function showShare(): \OCP\AppFramework\Http\TemplateResponse
{
// TODO: Implement showShare() method.
return new \OCP\AppFramework\Http\TemplateResponse('wcoOneTimeSecret', 'secret/show', ['share' => $this->secret], 'guest');
}
/**
* @inheritDoc
*/
protected function getPasswordHash(): string
{
return md5(123);
// TODO: Implement getPasswordHash() method.
}
/**
* @inheritDoc
*/
public function isValidToken(): bool
{
return true;
// TODO: Implement isValidToken() method.
}
/**
* @inheritDoc
* @NoCSRFRequired
*/
protected function isPasswordProtected(): bool
{
return true;
// TODO: Implement isPasswordProtected() method.
}
}
The other controller I implemented works totally fine but I have just trouble to implement one that extends the AuthPublicShareController.
If I change this function that the variable $class is ‘auth_secret_share’ it’s working:
But if it’s not modified it loggs an error that the route was not found.
Follow up discussion in