Commit 9cda9714 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Disconnection

Add disconnection management
Add unregistering
parent 54d95874
......@@ -63,8 +63,8 @@ public class MainActivity extends NFCActivity {
public boolean onLongClick(View v) {
if (!nemopaySession.isRegistered())
addKeyDialog();
else // A supprimer = embêtant si les clés sont réinitialisées
delKey();
else
unregister();
return false;
}
......@@ -84,10 +84,25 @@ public class MainActivity extends NFCActivity {
badgeDialog(idBadge);
}
protected void disconnect() {
nemopaySession.disconnect();
casConnexion.disconnect();
}
protected void unregister() {
nemopaySession.unregister();
disconnect();
((TextView) findViewById(R.id.text_app_registered)).setText(R.string.app_not_registred);
dialog.errorDialog(getResources().getString(R.string.key_registration), getResources().getString(R.string.key_remove_temp));
}
protected void delKey() {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.remove("key");
edit.apply();
unregister();
}
protected void setKey(final String key) {
......@@ -399,7 +414,8 @@ public class MainActivity extends NFCActivity {
public void onClick(DialogInterface dialogInterface, int id) {
setKey(keyInput.getText().toString());
}
});
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
......
......@@ -59,6 +59,12 @@ public class CASConnexion {
throw new RuntimeException("Not Connected");
}
public void disconnect() {
this.username = "";
this.location = "";
this.ticket = "";
}
public Boolean isConnected() { return !this.location.isEmpty(); }
public void addService(final String service) throws Exception {
......
......@@ -50,8 +50,21 @@ public class NemopaySession {
public Boolean isConnected() { return !this.session.isEmpty() && !this.username.isEmpty(); }
public Boolean isRegistered() { return !this.name.isEmpty() && !this.key.isEmpty() && !this.session.isEmpty(); }
public void disconnect() {
this.session = "";
this.username = "";
}
public void unregister() {
this.name = "";
this.key = "";
disconnect();
}
public String getName() { return this.name; }
public String getKey() { return this.key; }
public HTTPRequest getRequest() { return this.request; }
public void getCasUrl() throws IOException {
request("POSS3", "getCasUrl");
......@@ -119,8 +132,6 @@ public class NemopaySession {
throw new Exception("Not connected");
}
public HTTPRequest getRequest() { return this.request; }
protected void request(final String method, final String service) throws IOException { request(method, service, new HashMap<String, String>()); }
protected void request(final String method, final String service, final Map<String, String> postArgs) throws IOException {
HTTPRequest request = new HTTPRequest(url + method + "/" + service);
......
......@@ -50,5 +50,6 @@
<string name="key_description">Description</string>
<string name="key_name_required">Nom requis !</string>
<string name="key_add_explication">Il est possible d\'ajouter directement une clé d\'application si celle-ci est connue</string>
<string name="key_remove_temp">L\'application a été désauthentifiée temporairement. Il suffit de relancer l\'application pour qu\'elle soit de nouveau connectée</string>
<string name="already_connected">Déjà connecté !</string>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment