I am trying to restrict access to administering users in the CakeDC Users plugin. As far as I can tell that requires extending the UsersController, but I can't seem to get that right: something is broken no matter what I do (I've spent a couple days on this).
I've been following the instructions in the Users plugin readme: https://github.com/CakeDC/users. I copied the render method from the readme to use the plugin's views. I overrode _setupAuth
with an empty function but then copied most of the original _setupAuth
to my beforeFilter
:
AppUsersController.php:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('login');
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'),
'userModel' => 'Users.User',
'scope' => array(
'User.active' => 1,
'User.email_verified' => 1)
)
);
$this->Auth->loginRedirect = '/';
$this->Auth->logoutRedirect = array('plugin' => null, 'controller' => 'app_users', 'action' => 'login');
$this->Auth->loginAction = array('admin' => false, 'plugin' => null, 'controller' => 'app_users', 'action' => 'login');
}
I entered the routes changing them for my extended controller like the readme says with only a couple changes. First I added admin routes, because the admin side was still using the original plugin's controller. Second, I switched users/users/:action
route with users/:action
because I kept getting missing method errors (i.e. '/users/users/login' was trying to find users action in a users controller in my app, not in the plugin).
routes.php:
Router::connect('/admin/users', array('plugin' => null, 'controller' => 'app_users', 'prefix' => 'admin', 'admin' => true));
Router::connect('/admin/users/index/*', array('plugin' => null, 'controller' => 'app_users', 'prefix' => 'admin', 'admin' => true));
Router::connect('/admin/users/:action/*', array('plugin' => null, 'controller' => 'app_users', 'prefix' => 'admin', 'admin' => true));
Router::connect('/admin/users/users/:action/*', array('plugin' => null, 'controller' => 'app_users', 'prefix' => 'admin', 'admin' => true));
Router::connect('/users', array('plugin' => null, 'controller' => 'app_users'));
Router::connect('/users/index/*', array('plugin' => null, 'controller' => 'app_users'));
Router::connect('/users/:action/*', array('plugin' => null, 'controller' => 'app_users'));
Router::connect('/users/users/:action/*', array('plugin' => null, 'controller' => 'app_users'));
Router::connect('/login/*', array('plugin' => null, 'controller' => 'app_users', 'action' => 'login'));
Router::connect('/logout/*', array('plugin' => null, 'controller' => 'app_users', 'action' => 'logout'));
Router::connect('/register/*', array('plugin' => null, 'controller' => 'app_users', 'action' => 'add'));
Now it sort of works. the admin_edit
, and view
actions give SQL errors. They seem to depend on some behavior that isn't being loaded for some reason when using my AppUsersController. They call User->edit
and User->view
respectively on the User Model. No loaded behaviors implement those methods, so the User Model tries to pass it to the DataSource, hence the SQL errors. Also the edit
action errors out on User->UserDetails
not being set to an instance of an object. Is the User Model not being initialized somehow?
Any help is appreciated.