I'm making a system that uses authorization through an external API (VK). When the user clicks on "authorize via VK", they get a popup window where they can choose whether to grant permissions or cancel. Whatever they choose, the API just redirects them to my php script in the same popup window, and when that script is done, they are ending up with an empty popup window still open.
I need to do 2 things:
1) Close the popup window after the script is done.
2) Depending on what the function in the script returns, display the appropriate message for the user, not in that popup window, but in the initial window that initiated the popup (somewhere between the lines of the already existing text), after the popup has already closed.
Now, I don't know how to do this. There must me some javascript (preferrably jquery) that inserts a message to the initial window depending on the response obtained from the function that was called in a popup window that has already closed.
Here are some excerpts from the system:
http://example.com/vkcode?error=access_denied&error_reason=user_denied&error_description=User+denied+your+request&state=secret_state_code
- this is the page the user gets redirected to (inside the popup) if they choose "cancel". And they keep staying on the blank page with that string in their address bar.
Here is some PHP code that handles the response from VK API:
public function vkAuthHandler() {
if (isset($_GET['error'])) {
if ($_GET['error_reason'] == 'user_denied' {
return 'user_denied';
}
else return 'error';
}
else {
// ... haven't written other logic yet, it's irrelevant anyway
}
return new Response();
}
Now, if I receive 'user_denied'
response, I need to display a message telling the user that they refused the permissions. But not in that popup window where that function was called (it should already be closed by the time), but on the initial page, without reloading it.