User administration example, how to deal with password fields

User administration example, how to deal with password fields

alewinealewine Posts: 2Questions: 1Answers: 0

Using Editor, I'm pulling a few "user related" fields from a table in which the password is encrypted on the PHP site before being entered into the database.

When Editor table is initialized, the password field is pulled and populated with the hashed password. This is an awkward behavior. Ideally, I'd like to NOT pull that field when drawing (reading from the database) the table, but still allow the field to up updated with inline (or standard) editing.

Any idea how that would be accomplished?

users_editor = new $.fn.dataTable.Editor( {
            ajax: "/users/api/",
            table: "#tblUsers",
            fields: [
                {
                    label: "Firstname",
                    name: "firstname"
                }, {
                    label: "Last Name",
                    name: "lastname"
                }, {
                    label: "Username",
                    name: "username"
                }, {
                    label: "Password",
                    name: "password",
                    type: "password"
                }
            ]
        } );

        // Activate an inline edit on click of a table cell
        $('#tblUsers').on( 'click', 'tbody td:not(:first-child)', function (e) {
            users_editor.inline( this );
        } );

        $('#tblUsers').DataTable( {
            dom: "Tfrtip",
            ajax: "/users/api/",
            columns: [
                { data: null, defaultContent: '', orderable: false },
                { data: "firstname" },
                { data: "lastname" },
                { data: "username" },
                { data: "password" }
            ],
            order: [ 1, 'desc' ],
            lengthMenu: [20, 50],
            "bAutoWidth": false,
            tableTools: {
                sRowSelect: "os",
                sRowSelector: 'td:first-child',
                aButtons: [
                    { sExtends: "editor_create", editor: users_editor },
                    { sExtends: "editor_edit",   editor: users_editor },
                    { sExtends: "editor_remove", editor: users_editor }
                ]
            }
        } );

This question has an accepted answers - jump to answer

Answers

  • alewinealewine Posts: 2Questions: 1Answers: 0

    I was able to solve this by using a custom getFormatter:

    ->fields(
                    Field::inst( 'firstname' ),
                    Field::inst( 'lastname' ),
                    Field::inst( 'username' ),
                    Field::inst( 'password' )->getFormatter( 'Format::blank', 'key' )
    

    Format.php:

    public static function blank ( $val ) {
            return '';
        }
    
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    You should also be able to use the get() method for the field and set it to false.

    But your method is a nice way of doing it as well!

    Allan

This discussion has been closed.