From e08177035e65ea35249310bb963143a122a17ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 8 May 2014 10:37:14 +0200 Subject: Error messages fetched directly from api message. This has the problem of localized messages. irc log questioning: May 8th 2014 08:12 <@parmegv> mm, I was thinking... I was rephrasing the error messages given by our api during authentication 08:13 <@parmegv> I thought why should I rephrase it and think twice 08:13 <@parmegv> so now I'm just "pretty printing" the error message given by the api 08:13 <@parmegv> but that has a problem: they aren't localized 08:14 <@parmegv> would implementing a localized version of our error messages be useful? --- .../java/se/leap/bitmaskclient/ProviderAPI.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 8481bf08..dc5b3876 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -218,16 +218,9 @@ public class ProviderAPI extends IntentService { BigInteger password_verifier = client.calculateV(username, password, salt); /* Send to the server */ JSONObject result = sendNewUserDataToSRPServer(authentication_server, username, new BigInteger(1, salt).toString(16), password_verifier.toString(16)); - if(result.has(ERRORS)) { - session_id_bundle.putBoolean(RESULT_KEY, false); - try { - // {"errors":{"login":["has already been taken","has already been taken"]}} - session_id_bundle.putString(getResources().getString(R.string.user_message), result.getJSONObject(ERRORS).toString()); - session_id_bundle.putString(LogInDialog.USERNAME, username); - } catch(JSONException e) { - e.printStackTrace(); - } - } + if(result.has(ERRORS)) + session_id_bundle = authFailedNotification(result, username); + Log.d(TAG, result.toString()); broadcast_progress(progress++); } else { @@ -318,11 +311,14 @@ public class ProviderAPI extends IntentService { } private Bundle authFailedNotification(JSONObject result, String username) { - Log.d(TAG, "authFailedNotification("+ result +")"); Bundle user_notification_bundle = new Bundle(); try{ - user_notification_bundle.putString(getResources().getString(R.string.user_message), result.getJSONObject(ERRORS).toString()); + JSONObject error_message = result.getJSONObject(ERRORS); + String error_type = error_message.keys().next().toString(); + String message = error_message.get(error_type).toString(); + user_notification_bundle.putString(getResources().getString(R.string.user_message), message); } catch(JSONException e) {} + if(!username.isEmpty()) user_notification_bundle.putString(LogInDialog.USERNAME, username); user_notification_bundle.putBoolean(RESULT_KEY, false); -- cgit v1.2.3