1

I want to extend users plugin so that i can remove username field and customize my table according to needs. I have seen the github documentation for extending plugin but that doesn't help me much. I tried to extend UserTable.php but it gives me error Unknown method "register". Please suggest best way or simple code.

Amit Dangwal
  • 421
  • 1
  • 4
  • 10

1 Answers1

2

Check this cloud9 environment created specifically to show how to extend the model and table as an example: https://ide.c9.io/steinkel/users-example-custom-table

  • The example uses a custom table my_users
  • The example uses a custom Table class MyUsersTable extending the CakeDC/Users.Users table
  • Keep in mind the field 'username' is used in SocialLogin and other features by default, if you are going to remove it ensure you configure the app to rely on another field.

Basically changes done to use a custom table are:

  • Create a new database table, matching the original fields and add/remove fields based on your needs
  • Create a new Table class in your app, extending the CakeDC/Users.Users table
  • Override required methods, like validation or finders in your table class
  • Set your table in configuration key 'Users.table' like we did in 'config/users.php'

    $config = [
        'Users' => [
            //Table used to manage users
            'table' => 'MyUsers',
        ] 
    ]; 
    return $config;
    

And you are done :)

steinkel
  • 1,156
  • 9
  • 15
  • Thank you for explaining in details but i am not able able to open clound9 because it need credit card. Kindly show the example with any other way – Amit Dangwal Mar 03 '17 at 10:38
  • 1
    Here's the full source code > https://dl.dropboxusercontent.com/u/142951/cakedc-users-custom-table.gz – steinkel Mar 03 '17 at 13:28
  • Thankyou it works, is it possible to do not store password in users table, store username and password in another table and other details remain in users table except password field – Amit Dangwal Mar 04 '17 at 05:50
  • Yes it is possible. The easiest way is to use users table to hold username and password and then configure Auth to contain the extra profile data. – steinkel Mar 06 '17 at 09:19
  • 1
    I think both links are expired (cloud9/dropbox) unfortunately. And out of curiosity, are there any current plans to accommodate the forthcoming Cake authorization/authentication plugins since Auth will be deprecated soon? – meder omuraliev Apr 05 '18 at 21:33
  • Yes, we are working on integrating the new authenticate and authorize plugins right now, thanks! – steinkel Apr 06 '18 at 23:01