ZF-Commons / ZfcUser

A generic user registration and authentication module for ZF2. Supports Zend\Db and Doctrine2. (Formerly EdpUser)
BSD 3-Clause "New" or "Revised" License
497 stars 343 forks source link

Routes defined in UserController as constants ROUTE_ should be configurable #684

Open MadCat34 opened 5 years ago

MadCat34 commented 5 years ago

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 ?

jroedel commented 5 years ago

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.

MadCat34 commented 5 years ago

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...