open confirm dialog in elgg

Hello community,

I would like to open a confirm dialog manually in elgg without pressing a button, but after execution of a php function in one of my plugins (the function checks if a user has authorizations for a machine). Does elgg provide an option for this? Or do I have to implement this by myself with javascript and when yes, how? (I am pretty new to javascript)

I am exposing a function with elgg web services:

elgg_ws_expose_function("machine.authenticate",
    "process_authentication_request",...
function process_authentication_request()
{

    $encodedRequest = file_get_contents("php://input");
    $request = json_decode($encodedRequest);
    $userID = $request->userId;
    $machineID = $request->machineId;

    if (verify_authentication($userID, $machineID)) {
// after execution of verify_authentication() before sending the http_response_code I would like to open a confirm dialog in my // elgg site and when pressing 'ok' the http response code should be sended
        http_response_code(202);
        return http_response_code();
    } else {
...
    }
}

 

  • You cannot pause PHP execution to wait on a client-side interaction.

    You'll have to send multiple requests. E.g. process_authentication_request() could return the output of verify_authentication(). Your client code could then send an ajax request to check this and if true, show the confirm. If clicked, send a 2nd ajax request (again with the the authentication data) to a different method that verifies auth again and does something...

    Your API, if called correctly, should almost always return a 200 response.

    More info about what you're trying to build would help.

  • Hello Steve,

    first of all, thank you for your response.

    I am still trying to solve this problem. How should the client code look like?

  • Hello Steve,

    is there an option to trigger an action inside of an API method? Something like:

    elgg_ws_expose_function("machine.authenticate",
        "process_authentication_request",...
    function process_authentication_request()
    {
    
        $encodedRequest = file_get_contents("php://input");
        $request = json_decode($encodedRequest);
        $userID = $request->userId;
        $machineID = $request->machineId;
    
        if (verify_authentication($userID, $machineID)) {
            action('example_action');
        } else {
    ...
        }
    }

    When I'm trying to trigger the example_action it doesn't work. Why?

  • There's no reason it shouldn't work - however conditions for the action need to be met.

    eg. If it's registered for logged in users it will fail if you're not logged in.  If it can't find valid action tokens in the request it will fail.