Commit 0cead7cd authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'feature/rights' into develop

parents 343c9894 95db0f58
......@@ -41,7 +41,7 @@ public class MainActivity extends NFCActivity {
setContentView(R.layout.activity_main);
dialog = new Dialog(MainActivity.this);
nemopaySession = new NemopaySession();
nemopaySession = new NemopaySession(MainActivity.this);
casConnexion = new CASConnexion(nemopaySession);
sharedPreferences = getSharedPreferences("payutc", Activity.MODE_PRIVATE);
......@@ -89,7 +89,7 @@ public class MainActivity extends NFCActivity {
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));
dialog.errorDialog(getString(R.string.key_registration), getString(R.string.key_remove_temp));
}
protected void delKey() {
......@@ -102,11 +102,11 @@ public class MainActivity extends NFCActivity {
protected void setKey(final String key) {
if (nemopaySession.isRegistered()) {
dialog.errorDialog(getResources().getString(R.string.nemopay_connection), getResources().getString(R.string.nemopay_already_registered));
dialog.errorDialog(getString(R.string.nemopay_connection), getString(R.string.nemopay_already_registered));
return;
}
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.nemopay_connection), getResources().getString(R.string.nemopay_authentification), true);
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification), true);
loading.setCancelable(false);
new Thread() {
......@@ -132,7 +132,7 @@ public class MainActivity extends NFCActivity {
((TextView) findViewById(R.id.text_app_registered)).setText(nemopaySession.getName().substring(0, nemopaySession.getName().length() - (nemopaySession.getName().matches("^.* - ([0-9]{4})([/-])([0-9]{2})\\2([0-9]{2})$") ? 13 : 0)));
}
else
dialog.errorDialog(getResources().getString(R.string.nemopay_connection), getResources().getString(R.string.nemopay_error_registering));
dialog.errorDialog(getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
}
});
}
......@@ -142,7 +142,7 @@ public class MainActivity extends NFCActivity {
protected void connectWithCAS(final String username, final String password) throws InterruptedException {
dialog.dismiss();
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.cas_connection), getResources().getString(R.string.cas_in_url), true);
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getString(R.string.cas_connection), getString(R.string.cas_in_url), true);
loading.setCancelable(false);
new Thread() {
@Override
......@@ -166,10 +166,10 @@ public class MainActivity extends NFCActivity {
public void run() {
if (casConnexion.getUrl().equals("")) {
loading.dismiss();
dialog.errorDialog(getResources().getString(R.string.cas_connection), getResources().getString(R.string.cas_error_url));
dialog.errorDialog(getString(R.string.cas_connection), getString(R.string.cas_error_url));
}
else
loading.setMessage(getResources().getString(R.string.cas_in_connection));
loading.setMessage(getString(R.string.cas_in_connection));
}
});
......@@ -187,10 +187,10 @@ public class MainActivity extends NFCActivity {
@Override
public void run() {
if (casConnexion.isConnected())
loading.setMessage(getResources().getString(R.string.cas_in_service_adding));
loading.setMessage(getString(R.string.cas_in_service_adding));
else {
loading.dismiss();
dialog.errorDialog(getResources().getString(R.string.cas_connection), getResources().getString(R.string.cas_error_connection));
dialog.errorDialog(getString(R.string.cas_connection), getString(R.string.cas_error_connection));
}
}
});
......@@ -210,10 +210,10 @@ public class MainActivity extends NFCActivity {
public void run() {
if (casConnexion.isServiceAdded())
loading.setMessage(getResources().getString(R.string.nemopay_connection));
loading.setMessage(getString(R.string.nemopay_connection));
else {
loading.dismiss();
dialog.errorDialog(getResources().getString(R.string.cas_connection), getResources().getString(R.string.cas_error_service_adding));
dialog.errorDialog(getString(R.string.cas_connection), getString(R.string.cas_error_service_adding));
}
}
});
......@@ -234,7 +234,7 @@ public class MainActivity extends NFCActivity {
loading.dismiss();
if (!nemopaySession.isConnected())
dialog.errorDialog(getResources().getString(R.string.cas_connection), getResources().getString(R.string.cas_error_service_linking));
dialog.errorDialog(getString(R.string.cas_connection), getString(R.string.cas_error_service_linking));
else if (!nemopaySession.isRegistered())
keyDialog();
else
......@@ -251,7 +251,7 @@ public class MainActivity extends NFCActivity {
if (!nemopaySession.isRegistered() || nemopaySession.isConnected())
return;
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.badge_dialog), getResources().getString(R.string.badge_recognization), true);
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getString(R.string.badge_dialog), getString(R.string.badge_recognization), true);
loading.setCancelable(false);
new Thread(new Runnable() {
@Override
......@@ -272,9 +272,9 @@ public class MainActivity extends NFCActivity {
if (nemopaySession.isConnected())
Toast.makeText(MainActivity.this, "Tout est bon !", Toast.LENGTH_SHORT).show();
else if (nemopaySession.getRequest().getResponseCode() == 400)
dialog.errorDialog(getResources().getString(R.string.badge_dialog), getResources().getString(R.string.badge_pin_error_not_recognized));
dialog.errorDialog(getString(R.string.badge_dialog), getString(R.string.badge_pin_error_not_recognized));
else
dialog.errorDialog(getResources().getString(R.string.badge_dialog), getResources().getString(R.string.badge_error_no_rights));
dialog.errorDialog(getString(R.string.badge_dialog), getString(R.string.badge_error_no_rights) + ".\n" + nemopaySession.needRights(MainActivity.this));
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
......@@ -286,12 +286,12 @@ public class MainActivity extends NFCActivity {
protected void badgeDialog(final String idBadge) {
if (!nemopaySession.isRegistered()) {
dialog.errorDialog(getResources().getString(R.string.badge_connection), getResources().getString(R.string.badge_app_not_registered));
dialog.errorDialog(getString(R.string.badge_connection), getString(R.string.badge_app_not_registered));
return;
}
if (nemopaySession.isConnected()) {
dialog.errorDialog(getResources().getString(R.string.badge_connection), getResources().getString(R.string.already_connected) + " " + nemopaySession.getUsername());
dialog.errorDialog(getString(R.string.badge_connection), getString(R.string.already_connected) + " " + nemopaySession.getUsername());
return;
}
......@@ -328,7 +328,7 @@ public class MainActivity extends NFCActivity {
protected void casDialog() {
if (nemopaySession.isConnected()) {
dialog.errorDialog(getResources().getString(R.string.cas_connection), getResources().getString(R.string.already_connected) + " " + nemopaySession.getUsername());
dialog.errorDialog(getString(R.string.cas_connection), getString(R.string.already_connected) + " " + nemopaySession.getUsername());
return;
}
......@@ -395,7 +395,7 @@ public class MainActivity extends NFCActivity {
else {
dialogInterface.cancel();
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.nemopay_connection), getResources().getString(R.string.nemopay_registering), true);
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_registering), true);
loading.setCancelable(false);
new Thread() {
@Override
......@@ -413,7 +413,7 @@ public class MainActivity extends NFCActivity {
loading.dismiss();
if (nemopaySession.getKey().isEmpty())
dialog.errorDialog(getResources().getString(R.string.nemopay_connection), getResources().getString(R.string.nemopay_error_registering));
dialog.errorDialog(getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
else
setKey(nemopaySession.getKey());
}
......
......@@ -46,6 +46,9 @@ public class CASConnexion {
this.username = "";
this.location = "";
this.ticket = "";
HTTPRequest request = new HTTPRequest(this.url + "logout");
request.post();
}
public Boolean isConnected() { return !this.location.isEmpty(); }
......
package fr.utc.simde.payutc.tools;
import android.app.Activity;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import fr.utc.simde.payutc.R;
import static java.lang.System.in;
/**
* Created by Samy on 24/10/2017.
*/
......@@ -16,23 +27,30 @@ import java.util.Map;
public class NemopaySession {
private static final String LOG_TAG = "_NemopaySession";
private static final String url = "https://api.nemopay.net/services/";
private static Map<String, String> allRights = new HashMap<String, String>();
private String name;
private String key;
private String session;
private String username;
private HTTPRequest request;
private Map<String, String> cookies = new HashMap<String, String>();
private String[] rightsNeeded;
private Map<String, String> cookies = new HashMap<String, String>();
private final Map<String, String> getArgs = new HashMap<String, String>() {{
put("system_id", "payutc");
}};
public NemopaySession() {
public NemopaySession(Activity activity) {
this.name = "";
this.key = "";
this.session = "";
this.username = "";
String[] keys = activity.getResources().getStringArray(R.array.rights_keys);
String[] values = activity.getResources().getStringArray(R.array.rights_values);
for (int i = 0; i < Math.min(keys.length, values.length); ++i)
this.allRights.put(keys[i], values[i]);
}
public Boolean isConnected() { return !this.session.isEmpty() && !this.username.isEmpty(); }
......@@ -109,7 +127,9 @@ public class NemopaySession {
int reponseCode = request("POSS3", "loginBadge2", new HashMap<String, String>() {{
put("badge_id", idBadge);
put("pin", pin);
}});
}}, new String[]{
"sale"
});
JSONObject response;
if (reponseCode == 200 && this.request.isJsonResponse())
......@@ -149,8 +169,31 @@ public class NemopaySession {
return reponseCode;
}
protected int request(final String method, final String service) throws IOException { return request(method, service, new HashMap<String, String>()); }
protected int request(final String method, final String service, final Map<String, String> postArgs) throws IOException {
public String needRights(Activity activity) {
String result;
if (this.rightsNeeded.length == 0)
return activity.getString(R.string.no_need_rights);
else if (this.rightsNeeded.length == 1)
result = activity.getString(R.string.no_right);
else
result = activity.getString(R.string.no_rights);
for (String right : this.rightsNeeded) {
if (allRights.containsKey(right))
result += " " + allRights.get(right) + ",";
else {
result += " " + right + ",";
Log.e(LOG_TAG, "\"" + right + "\" does not exist");
}
}
return result.substring(0, result.length() - 1) + ".";
}
protected int request(final String method, final String service) throws IOException { return request(method, service, new HashMap<String, String>(), new String[]{}); }
protected int request(final String method, final String service, final String[] rightsNeeded) throws IOException { return request(method, service, new HashMap<String, String>(), rightsNeeded); }
protected int request(final String method, final String service, final Map<String, String> postArgs) throws IOException { return request(method, service, postArgs, new String[]{}); }
protected int request(final String method, final String service, final Map<String, String> postArgs, final String[] rightsNeeded) throws IOException {
Log.d(LOG_TAG, "url: " + url + method + "/" + service);
this.request = new HTTPRequest(url + method + "/" + service);
this.request.setGet(getArgs);
......@@ -159,6 +202,7 @@ public class NemopaySession {
int reponseCode = this.request.post();
this.cookies = request.getCookies();
this.rightsNeeded = rightsNeeded;
return reponseCode;
}
......
......@@ -38,7 +38,7 @@
<string name="badge_connection">Connexion via badge</string>
<string name="badge_app_not_registered">Il est nécessaire que l\'application soit enregistrée pour permettre la connexion via badge</string>
<string name="badge_recognization">Authentification du badge...</string>
<string name="badge_error_no_rights">Impossible de vérifier le badge, l\'application n\'a pas les droits nécessaires</string>
<string name="badge_error_no_rights">Impossible de vérifier le badge</string>
<string name="badge_pin_error_not_recognized">Badge ou code PIN non reconnu</string>
<string name="nemopay_connection">Connexion à Nemopay</string>
<string name="nemopay_authentification">Authentification de l\'application</string>
......@@ -54,4 +54,155 @@
<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é sous</string>
<string name="no_right">Il est nécessaire d\'avoir au moins le droit suivant:</string>
<string name="no_rights">Il est nécessaire d\'avoir au moins les droits suivants:</string>
<string name="no_need_rights">Aucun droit spécifique n\'est nécessaire</string>
<string-array name="rights_keys"><item>Accès en lecture seule sur les paramètres</item>
<item>add_free</item>
<item>offline_app</item>
<item>delegated_auth</item>
<item>social_network_auth</item>
<item>auto_topup</item>
<item>keyboard</item>
<item>widget_code</item>
<item>event_config</item>
<item>sys_config</item>
<item>transfer_consulting</item>
<item>access_control</item>
<item>offline_app_creation</item>
<item>user_creation</item>
<item>live_dashboard</item>
<item>transfert_ask</item>
<item>bill_ask</item>
<item>CB_transfert_ask</item>
<item>IBAN_transfert_ask</item>
<item>app_rights</item>
<item>user_rights</item>
<item>online_cashing</item>
<item>user_account_management</item>
<item>sync_management</item>
<item>accreditation_management</item>
<item>activity_management</item>
<item>app_management</item>
<item>article_management</item>
<item>blocking_management</item>
<item>blocked_card_management</item>
<item>place_config_management</item>
<item>group_management</item>
<item>delivry_management</item>
<item>prize_management</item>
<item>perso_message_management</item>
<item>currency_management</item>
<item>payment_method_management</item>
<item>partner_management</item>
<item>recharge_refund_period_management</item>
<item>refund_management</item>
<item>sys_refund_management</item>
<item>barcode_rule_management</item>
<item>wifi_management</item>
<item>mail_template_management</item>
<item>user_management</item>
<item>suitcase_management</item>
<item>sale_management</item>
<item>event_management</item>
<item>export_generation</item>
<item>file_importation</item>
<item>case_log</item>
<item>house_rental</item>
<item>external_login</item>
<item>staff_member</item>
<item>user_account_update</item>
<item>direct_recharge</item>
<item>ajax_recharg</item>
<item>recharge</item>
<item>username_recharge</item>
<item>inventories</item>
<item>catering_resume</item>
<item>stats</item>
<item>stocks</item>
<item>all_rights</item>
<item>treasury</item>
<item>online_payment_validation</item>
<item>sale</item>
<item>self_sale</item>
<item>transfer</item>
<item>access_control_history_visualisation</item>
<item>recharge_visualisation</item>
<item>sale_visualisation</item>
</string-array>
<string-array name="rights_values"><item>Accès en lecture seule sur les paramètres</item>
<item>Ajout de gratuités</item>
<item>Application hors ligne</item>
<item>Authentification déléguée</item>
<item>Authentification par réseau social</item>
<item>Auto Topup</item>
<item>Clavier de caisse</item>
<item>Code du widget</item>
<item>Configuration des évènements</item>
<item>Configuration du système</item>
<item>Consultation des reversements système</item>
<item>Contrôle des accès</item>
<item>Création d\'application Offline.</item>
<item>Création de compte utilisateur</item>
<item>Dashboard Live</item>
<item>Demande de remboursement</item>
<item>Demander des factures</item>
<item>Demander des remboursements CB</item>
<item>Demander des remboursements IBAN</item>
<item>Droits des applications</item>
<item>Droits des utilisateurs</item>
<item>Encaissement en ligne</item>
<item>Gestion de compte utilisateur</item>
<item>Gestion de la synchro Weezevent</item>
<item>Gestion des accréditations</item>
<item>Gestion des activités</item>
<item>Gestion des applications</item>
<item>Gestion des articles</item>
<item>Gestion des blocages</item>
<item>Gestion des cartes bloquées</item>
<item>Gestion des configurations de lieux</item>
<item>Gestion des groupes</item>
<item>Gestion des livraisons</item>
<item>Gestion des Lots à gagner</item>
<item>Gestion des messages personalisés</item>
<item>Gestion des monnaies</item>
<item>Gestion des moyens de paiement</item>
<item>Gestion des partenaires</item>
<item>Gestion des périodes de recharge/remboursement</item>
<item>Gestion des reversements</item>
<item>Gestion des reversements système</item>
<item>Gestion des règles pour les barcodes</item>
<item>Gestion des réseaux wifi</item>
<item>Gestion des template de mail</item>
<item>Gestion des utilisateurs</item>
<item>Gestion des Valises de Nemopay</item>
<item>Gestion des ventes</item>
<item>Gestion des événements</item>
<item>Génération d\'exports</item>
<item>Import de fichiers</item>
<item>Journal de caisse</item>
<item>Location de foyer</item>
<item>Login exterieur via login+pin</item>
<item>Membre du staff</item>
<item>Mise à jour des utilisateurs par une appli</item>
<item>Recharge en direct</item>
<item>Recharge via ajax</item>
<item>Rechargement</item>
<item>Rechargement direct via username</item>
<item>Réaliser des inventaires</item>
<item>Résumé du catering</item>
<item>Statistiques</item>
<item>Stocks et entrepôts</item>
<item>Tous les droits</item>
<item>Trésorerie</item>
<item>Validation des paiements en ligne</item>
<item>Vente physique</item>
<item>Vente physique self-service</item>
<item>Virement</item>
<item>Visualisation de l\'historique des contrôles d\'accès</item>
<item>Visualisation des sessions de recharge</item>
<item>Visualisation des sessions de vente</item>
</string-array>
</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