How to detect Oauth window close? - java

I'm using Oauth to subscribe to Fitbit. When the user clicks a connect button in my website, he/she is redirected to the Fitbit authentication page, which open as a new tab in the browser, while it shows a loading progress bar in my website.
When user clicks the accept or deny button in the fitbit authentication page, fitbit pings my back end and everything works fine. But, if the user closes the window not opting to click neither accept nor deny, I'm stuck with the progress bar in my website. How can I get around this?
This is the how actually the progress bar closes. I use a column in my database called is_connected which returns the status of the connection
is_connected=0 // not connected
is_connected=1 // connected
is_connected=2 // connecting
so while the progress bar is showing(is_connected=2), the frontend keeps on pinging the backend requesting the status of is_connected field. When it detects a change, the progress bar closes.

Related

Install4J: give feedback to user after successful JDBC connection check

I'm trying to build the following form in Install4J 6.1.6:
After entering the host and a port number the user can check if these MySQL settings are correct by pressing the Test connection button.
The Host's variable is called mysqlHost
and the Port's variable is mysqlPort
I initially had a problem that the user entered input only gets saved to the variables when the Next > button is pressed, but I could solve this by adding
formEnvironment.saveFormComponents() to the Key listener script for both input fields.
I set up the following "Check JDBC connection" action for the Test Connection button:
And it works fine, when the host and port are set incorrectly the user will see a pop up with the error message.
However I'm not able to display a Success message or label when the JDBC connection works.
I tried adding a green Success label (as seen on the first picture) with the following visibility script:
String errorMessage = (String)context.getVariable("mysqlTestError");
return errorMessage.length() == 0;
So I'm trying to check if the mysqlTestError variable is empty or not.
But it's not working, the Success label is NEVER displayed.
How can it be only displayed when the connection check was successful?
The visibility script of the label form component is only evaluated when the screen is shown, so it will not update the visibility after the JDBC connection check.
You can update the label programmatically by adding a "Run script" action to the "Action list" of the button form component:
String errorMessage = (String)context.getVariable("mysqlTestError");
FormComponent formComponent = formEnvironment.getFormComponentById("ID of label");
formComponent.setVisible(!errorMessage.isEmpty());
((JLabel)formComponent.getConfigurationObject()).setText(errorMessage);
return true;
In install4j 6, the "formEnvironment" parameter is not available in action lists and you would have to get it via
FormEnvironment formEnvironment = ((FormPanelContainer)context.getScreenById("ID of screen")).getFormEnvironment();

How to dismiss an alert in JavaFX?

I need to have a sort of "blocked alert" that can't be dismissed by the user until some event occurs. So, I created the alert and removed all the buttons from it:
Alert waitingAlert = new Alert(Alert.AlertType.INFORMATION);
waitingAlert.setTitle("Proposta Inviata");
waitingAlert.getButtonTypes().setAll();
waitingAlert.setHeaderText("La proposta รจ stata inviata a " + trade.getPlayer2Name());
waitingAlert.showAndWait();
Then, I need to dismiss it when a particular event occurs. I just tried doing it this way:
waitingAlert.close();
But it doesn't work.
Edit
The panel is shown when an user wants to send a request to another user in the network that needs to be accepted or refused. The principle is that the UI gets blocked until the other user says if he has accepted or refused the request. The request is send through a remote method invokation through a ring network. When I receive the response I want to close dismiss the panel.
To have a dialog that can't be dismissed by the user, but wait on a process, you will need to use dialog.show() as noted by James_D.
However, without buttons, the dialog actually will not close and you need to force it.
//for example
dialog.getButtonTypes().add(ButtonType.CANCEL);
dialog.hide();
dialog.getButtonTypes().remove(ButtonType.CANCEL);
This will allow you to close a dialog which has no buttons.

How to show error message when internet/server/vpn is not available

I have a code something goes like this;
<a4j:commandLink
actionListener="#{controller.validate}"
onclick="showFadeLoadingImg();"
oncomplete="confirmOperation();}"
value="#{actionItem.actionDisplayName}"
reRender="text1,text2">
</a4j:commandLink>
Here, when my VPN is down, my oncomplete event has jscript function confirmOperation(), which gets executed and undesired output from that function is being displayed. But, what I ultimately want is, when I click the button, I want to check whether I can able to connect to the server(VPN/internet enabled or not), and if not I have to show some error message like 'Unable to reach server' or else, can I redirect the page to login page?
You can connect to the server on validate() method,If you can't connect to the server, you can record the information,and then you can user you jscript function confirmOperation() to display this infomation.

Detect user login/logout xmpp google app engine

I am using Google App Engine in Java to send XMPP messages.
I would like to know if there is a way to check if a user is logged in to the system or logged out. So, when the user signs in, I would like to send him a welcome chat message and when he signs out I would like to notify my server code of the same.
I have tried the presence API but no luck so far.
Assuming you're referring to querying a user's presence via XMPP, keep in mind that this will only work if your App Engine account is authorized by that user. If you have already got that far, querying for presence (user logged in/logged out) is quite simple (source).
If a Google talk user has subscribed to an app (has accepted an invitation or has invited the app to chat), the app can discover the user's availability by looking for a POST to /_ah/xmpp/presence/available. If the user is subscribed and available, you can send them your application's presence and status:
// In the handler for _ah/xmpp/presence/available
XMPPService xmppService = XMPPServiceFactory.getXMPPService();
Presence presence = xmppService.parsePresence(req);
// Split the XMPP address (e.g., user#gmail.com)
// from the resource (e.g., gmail.CD6EBC4A)
String from = presence.getFromJid().getId().split("/")[0];
// Mirror the contact's presence back to them
xmppService.sendPresence(from, PresenceType.AVAILABLE, presence.getPresenceShow(), presence.getStatus());
To further clarify, your app receives automatic presence notifications via the following POST URL paths:
POSTs to /_ah/xmpp/presence/available/ signal that the user is available and provide the user's chat status.
POSTs to /_ah/xmpp/presence/unavailable/ signal that the user is unavailable.
POSTs to /_ah/xmpp/presence/probe/ request a user's current presence.
As an example, when user sally logs in, you'll get a POST request to /_ah/xmpp/presence/available/ which your server will then have to process. Then when sally logs out, you'll get a separate POST request to /_ah/xmpp/presence/unavailable/.

GWT: Problem with application's architecture

I'm in little trouble with designing GWT application. I am trying to develope RIA app (with just one main widget, lets call it Main). First, user must be logged. Here's my way to do that, but it does have a problem, you'll see.
Show login components on root panel
If login was successfull (checks database), show Main widget
Widget is added to root panel
Everything works, but when you press Refresh it shows again login components ... It all happens in onModuleLoad method.
How should I redesign this logic? I'd like to let user logged (that means RootPanel will hold Main widget) for certain amount of time.
http://code.google.com/p/google-web-toolkit-incubator/wiki/LoginSecurityFAQ
How to remember logins
Our login
system so far misses a useful feature:
For now it requires users to log in
again every time.
We can use Cookies to allow the user's
web browser to 'remember' the login.
In GWT, to set the cookie (which you'd
do right after your GWT code receives
the response as we did in the previous
code fragment):
String sessionID = /*(Get sessionID from server's response to your login request.)*/;
final long DURATION = 1000 * 60 * 60 * 24 * 14; //duration remembering login. 2 weeks in this example.
Date expires = new Date(System.currentTimeMillis() + DURATION);
Cookies.setCookie("sid", sessionID, expires, null, "/", false);
Now you can run the following code
right after your !EntryPoint begins
execution:
String sessionID = Cookies.getCookie("sid");
if ( sessionID != null ) checkWithServerIfSessionIdIsStillLegal();
else displayLoginBox();
Remember - you must never rely on the sessionID
sent to your server in the cookie
header ; look only at the sessionID
that your GWT app sends explicitly in
the payload of messages to your
server.
I'm not sure what how your GWT app implemented communication with the login service, but if you want to see another example, I followed the example here:
http://code.google.com/webtoolkit/doc/latest/tutorial/appengine.html#user
While it uses the Google App Engine as the backend authentication service, I think it's generic enough to be adapted to any server that supports the GWT RPC server side and has authentication services.
You need some kind of server-side support to do it.
For example, when user logs in, mark it in the server-side session. In onModuleLoad(), call the server to check whether user is logged in before showing the login form.
Other problems related to pressing Refresh can be solved with history tokens.

Categories

Resources