Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hello.

I managed to add a new custom field to a user called "Poste".
Here's what I did :

1 - Opened the "auth/user.php" file, and under the "KUser" class, I have added a new variable named "$poste", being equal to ''. So it looks like this :

Code: Select all
class KUser{
        var $id = -1;
        var $name = '';
        var $title = '';
        var $password = '';
        var $email = '';
        var $poste = '';
...


2 - In that same file, I went to the "populate_fields" function at line 94, then added a line in the "$fields" array, so it looks like this:

Code: Select all
           $fields = array(
                        'name'=>$FUNCS->t('user_name'),
                        'title'=>$FUNCS->t('display_name'),
                        'email'=>$FUNCS->t('email'),
                        'poste'=>$FUNCS->t('poste'),
                        'access_level'=>$FUNCS->t('role'),
                        'disabled'=>$FUNCS->t('disabled')
                        );


3 - Went to line 108, in that "foreach( $fields as $k=>$v )" loop, and at around line 130, I have added a condition for the "poste" variable/field. It looks like this:

Code: Select all
                if( $k=='name' ){
                    $field_info['k_desc'] = $FUNCS->t('user_name_restrictions');
                    $field_info['validator'] = 'title_ready|min_len=4|max_len=255';
                }
                elseif( $k=='email' ){
                    $field_info['validator'] = 'email';
                }
                elseif( $k=='poste' ){
                    $field_info['validator'] = 'min_len=1|max_len=10';
                }
...


4 - Went to line 283, in the "if( $this->id == -1 )" condition, and added my "poste" variable there too, inside the array at line 284:
Code: Select all
               $rs = $DB->insert( K_TBL_USERS, array(
                                              'name'=>$name,
                                              'password'=>$hash,
                                              'registration_date'=>$FUNCS->get_current_desktop_time(),
                                              'email'=>$email
                                              'poste'=>$poste
                                              )
...


5 - Then, I went in phpMyAdmin, in the "couch_users" table, clicked on the "Structure" tab, and added 1 column named "poste", with a type of "varchar(255)", collation of "utf8_general_ci, null of "yes", default of "NULL". It looks like this:
Image

6 - When that was done, a "k_poste" field was added to the Users edit page, and I was able to enter whatever I want, click save to save it, and display this information anywhere on the site.

My issue, is that I cannot edit passwords for a user, or create new users and saving the password now.
When I fill the form to create a new user, I will receive the success message, but when I try to log in using the username and password, it doesn't work. I had some trouble at first when doing this, and I think that what it does is that there is a mis-alignment with the fields in Couch, and the database table. Not sure though.

Anyone knows what is causing my issue? Maybe I forgot to add something, or I entered the wrong data somewhere.
I was pretty proud of being able to add that field to each users, since I'm not a PHP coder. But now I need some help.

Thanks a lot!
Hi,

Instead of making direct changes to the core files, the recommended method of adding new fields to users is through the 'extended-users' module.
Please see
viewtopic.php?f=5&t=8581
https://www.couchcms.com/docs/extended- ... s/post.htm

Hope it helps.
Thanks KK, but this is to make front-end users right?
I need to add a custom field to admin users. The ones that logs in the admin panel.
Will it work with what you have linked?
It will work with all kinds of users (including super-admin).

The limitation that you probably have in mind is that any user created from the front-end (i.e. using the 'registration' feature) are automatically placed in a group that does not have access to the admin-panel.

There is no such limitation on an account created from within the admin panel by admin/super-admin (which is how I think you plan to create the accounts).
I'm not sure I understand what you mean.
I can create users that have backend access using that registration feature? With different roles?
My first step is to add that custom field, and next up, I will need to display different data in the admin panel, depending on who's logged in. Is that also something that would work fine using your suggested feature?

Thanks
I suggest you please try the extended-users feature first-hand on a test installation.
See for yourself if it suits your use-case or not.
6 posts Page 1 of 1