Try to write own app to extend /login with register button and app

Try to develop on a brandnew Hetzner nextcloud install.
Tried to set up a new app but whatever I do I never get access to it. Either β€˜not found’ or CSFR errors. I spent hours of debugging but can’t find any solution by myself.
The setup is like this:

root@wartungs:/var/www/html# tree apps/registrationapp/
apps/registrationapp/
β”œβ”€β”€ appinfo
β”‚   β”œβ”€β”€ bootstrap.php
β”‚   β”œβ”€β”€ info.xml
β”‚   └── routes.php
β”œβ”€β”€ lib
β”‚   └── Controller
β”‚       └── RegistrationController.php
└── templates
    └── register.php

5 directories, 5 files

bootstrap:

<?php

declare(strict_types=1);

namespace OCA\RegistrationApp\AppInfo;

use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Services\IRouterService;
use OCA\RegistrationApp\Controller\RegistrationController;

class Application implements IBootstrap {

    public function register(IRegistrationContext $context): void {
        $context->registerController(RegistrationController::class);
    }

    public function boot(IBootContext $context): void {
        $routerService = $context->getAppContainer()->get(IRouterService::class);

        // ⚑ Route PUBLIC !!!
        $routerService->registerPublicRoute('registrationapp', 'registration#showForm');
    }
}

info.xml:

<?xml version="1.0"?>
<info>
    <id>registrationapp</id>
    <name>Wartungsapp Registration</name>
    <description>Benutzerregistrierung fΓΌr nextcloud.wartungs.app</description>
    <licence>agpl</licence>
    <author>Steffen Mutter</author>
    <version>0.2.0</version>
    <namespace>RegistrationApp</namespace>
    <category>tools</category>
    <types>
       <type>authentication</type>
    </types>
    <dependencies>
        <nextcloud min-version="27" max-version="30" />
    </dependencies>
    <routes>appinfo/routes.php</routes>
    <bootstrap>appinfo/bootstrap.php</bootstrap>
</info>

routes.php:

<?php

declare(strict_types=1);

return [
    'routes' => [
        [
            'name' => 'registrationapp#registration.showForm',
            'url' => '/registrieren',  // <-- NO Apps dir mentioned: otherwise CSFR!
            'verb' => 'GET',
            'defaults' => [
                '_public' => true,
            ],
        ],
    ]
];

RegistrationController.php:

<?php

declare(strict_types=1);

namespace OCA\RegistrationApp\Controller;

use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;

/**
 * @PublicPage
 * @NoCSRFRequired
 */
class RegistrationController extends Controller {
    public function __construct(IRequest $request) {
        parent::__construct('registrationapp', $request);
    }

    public function showForm(): TemplateResponse {
        return new TemplateResponse('registrationapp', 'register');
    }
}

register.php:

<div style="text-align: center; margin-top: 20px;">
    <h1>Registrier</h1>
    <p>content 2 come</p>
</div>

This app MUST be accessible always. But it is either never found, nextcloud crashes, or claims to be a CSFR. WTF?!?

Can’t be so difficult to create an public accessible php script. Nextcloud seems to be closed like Fort Knox.
Help highly appreciated!

Kind regards,
Steffen

Ok, I am surprised this does even work somehow. Where did you get this code from?

What exactly do you want to achieve? Does the URL really must be without /apps (you will fail then)? What is the use case?

In general, you can do quite some stuff but you need to be aware what you need.

Chris

This seems to be something like GitHub - nextcloud/registration: User registration app for Nextcloud ?

The question is: does he really need root-based routes or are rooted prefixed with /apps/registrationapp okay? Is it necessary index based routes or might OCS be a solution?

But yeah, you seem to be on the right track…