ZF-Commons/ZfcUser

Routes defined in UserController as constants ROUTE_ should be configurable

MadCat34 opened this issue · 2 comments

Some routes are defined as constants in UserController

const ROUTE_CHANGEPASSWD = 'zfcuser/changepassword';
const ROUTE_LOGIN        = 'zfcuser/login';
const ROUTE_REGISTER     = 'zfcuser/register';
const ROUTE_CHANGEEMAIL  = 'zfcuser/changeemail';

In order to change these routes, we should extend UserController.

It should be configurable with the moduleOptions.

I have overwrited routes to use
dashboard/user
dashboard/user/login
[...]
using UserController and action from ZfcUser.

If I go to /dashboard/user, and if I'm not logged, UserController redirect me to ROUTE_LOGIN (/user/login) instead of /dashboard/user/login

IMO, Configurable options is easier than extend UserController

What is your opinion about this ?

If I'm not mistaken you should be able to overwrite the path of those routes in configuration without changing the name of the routes.
For example:

return [
  'router' => [
    'zfcuser' => [
      'path' => 'dashboard/user',
    ],
  ],
];

I'm not at my computer right now to test it, but I think that should work.

This is what I have done.
But going to dashboard/user with unregistered user redirect to user/login.

The problem is the use of constants (see UserController::indexAction)

public function indexAction()
{
    if (!$this->zfcUserAuthentication()->hasIdentity()) {
        return $this->redirect()->toRoute(static::ROUTE_LOGIN);
    }
    return new ViewModel();
}

If you want to redirect to a custom route, actually you have to extends UserController...