summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-08-14 12:15:42 +0200
committerSean Leonard <meanderingcode@aetherislands.net>2013-10-03 16:50:04 -0700
commit37bb23c5549ffe690f65b1c04cf432bd3153bf04 (patch)
treecb221b9304905e25695c59be60f0eeb62fe25a36 /src/se/leap
parent697e7da6e1379ac23cd8dbb47a1246547abafda6 (diff)
Login dialog requires username.
I've also changed the way we notify that the password should have 8 characters at least, to make it consistent to the way we notify username is required.
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/leapclient/Dashboard.java7
-rw-r--r--src/se/leap/leapclient/LogInDialog.java26
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java24
3 files changed, 43 insertions, 14 deletions
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 371663b7..19d33a12 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -279,12 +279,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
DialogFragment newFragment = LogInDialog.newInstance();
if(resultData != null && !resultData.isEmpty()) {
- Bundle user_message_bundle = new Bundle();
- String user_message = resultData.getString(getResources().getString(R.string.user_message));
- String username = resultData.getString(LogInDialog.USERNAME);
- user_message_bundle.putString(getResources().getString(R.string.user_message), user_message);
- user_message_bundle.putString(LogInDialog.USERNAME, username);
- newFragment.setArguments(user_message_bundle);
+ newFragment.setArguments(resultData);
}
newFragment.show(fragment_transaction, LogInDialog.TAG);
}
diff --git a/src/se/leap/leapclient/LogInDialog.java b/src/se/leap/leapclient/LogInDialog.java
index 73833a13..7dd1c732 100644
--- a/src/se/leap/leapclient/LogInDialog.java
+++ b/src/se/leap/leapclient/LogInDialog.java
@@ -17,13 +17,18 @@
package se.leap.leapclient;
import se.leap.leapclient.R;
+import android.R.color;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
+import android.content.res.ColorStateList;
import android.os.Bundle;
+import android.provider.CalendarContract.Colors;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.BounceInterpolator;
import android.widget.EditText;
import android.widget.TextView;
@@ -44,6 +49,8 @@ public class LogInDialog extends DialogFragment {
final public static String VERB = "log in";
final public static String USERNAME = "username";
final public static String PASSWORD = "password";
+ final public static String USERNAME_MISSING = "username missing";
+ final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length";
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
@@ -54,23 +61,34 @@ public class LogInDialog extends DialogFragment {
final TextView user_message = (TextView)log_in_dialog_view.findViewById(R.id.user_message);
if(getArguments() != null && getArguments().containsKey(getResources().getString(R.string.user_message))) {
user_message.setText(getArguments().getString(getResources().getString(R.string.user_message)));
- } else user_message.setVisibility(View.GONE);
+ } else {
+ user_message.setVisibility(View.GONE);
+ }
final EditText username_field = (EditText)log_in_dialog_view.findViewById(R.id.username_entered);
- if(getArguments() != null && getArguments().containsKey(getResources().getString(R.string.user_message))) {
+ if(getArguments() != null && getArguments().containsKey(USERNAME)) {
String username = getArguments().getString(USERNAME);
username_field.setText(username);
- username_field.setHint("");
}
+ if (getArguments() != null && getArguments().containsKey(USERNAME_MISSING)) {
+ username_field.setError(getResources().getString(R.string.username_ask));
+ }
+
final EditText password_field = (EditText)log_in_dialog_view.findViewById(R.id.password_entered);
- if(!username_field.getText().toString().isEmpty() && password_field.isFocusable())
+ if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) {
password_field.requestFocus();
+ }
+ if (getArguments() != null && getArguments().containsKey(PASSWORD_INVALID_LENGTH)) {
+ password_field.setError(getResources().getString(R.string.error_not_valid_password_user_message));
+ }
+
builder.setView(log_in_dialog_view)
.setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String username = username_field.getText().toString().trim();
String password = password_field.getText().toString().trim();
+ dialog.dismiss();
interface_with_Dashboard.authenticate(username, password);
}
})
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index e7d329f8..2170478b 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -225,7 +225,7 @@ public class ProviderAPI extends IntentService {
String username = (String) task.get(LogInDialog.USERNAME);
String password = (String) task.get(LogInDialog.PASSWORD);
- if(wellFormedPassword(password)) {
+ if(validUserLoginData(username, password)) {
String authentication_server = (String) task.get(Provider.API_URL);
SRPParameters params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256");
@@ -277,15 +277,31 @@ public class ProviderAPI extends IntentService {
e.printStackTrace();
}
} else {
- session_id_bundle.putBoolean(RESULT_KEY, false);
- session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_not_valid_password_user_message));
- session_id_bundle.putString(LogInDialog.USERNAME, username);
+ if(!wellFormedPassword(password)) {
+ session_id_bundle.putBoolean(RESULT_KEY, false);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
+ session_id_bundle.putBoolean(LogInDialog.PASSWORD_INVALID_LENGTH, true);
+ }
+ if(username.isEmpty()) {
+ session_id_bundle.putBoolean(RESULT_KEY, false);
+ session_id_bundle.putBoolean(LogInDialog.USERNAME_MISSING, true);
+ }
}
return session_id_bundle;
}
/**
+ * Validates parameters entered by the user to log in
+ * @param entered_username
+ * @param entered_password
+ * @return true if both parameters are present and the entered password length is greater or equal to eight (8).
+ */
+ private boolean validUserLoginData(String entered_username, String entered_password) {
+ return !(entered_username.isEmpty()) && wellFormedPassword(entered_password);
+ }
+
+ /**
* Validates a password
* @param entered_password
* @return true if the entered password length is greater or equal to eight (8).