How to create custom API Endpoints

I think it is possible but it won’t be that easy I guess.

For example this method can be used to check a user and password combination against the user DB of an cockpit installation:

public static function checkAuth($user, $pass){
    $url = self::$_COCKPIT_BACKEND_URL . '/auth/check';
    $fields = [
        'auth' => [
            'user' => $user,
            'password' => $pass,
        ]
    ];
    $data_string = json_encode($fields);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
    );
    return json_decode(curl_exec($ch), true);
}

So if a user tries to log in with his credentials and this function returns a success. You could set a session variable in order to store the “logged in” state. In order to log the user out, you would then just delete the session. But this won’t come up with any solution in enabling users to register with your cockpit installation. I guess cockpit is not ment to be used this way buy indeed this should be able to do with some workarounds however.

collection entries? I’m not completely sure about that; don’t think you can get this straight the easy way - but I guess you could do this by putting PHP code to the “read” ACL as I mentioned before within your other support request (where you attached the screenshot). But in general term collection entries are considered to be treated as one group of data - so without building workarounds you should not be able to restrict dedicated entries for one and the same user.

1 Like