summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Leonard <meanderingcode@aetherislands.net>2013-10-03 16:54:00 -0700
committerSean Leonard <meanderingcode@aetherislands.net>2013-10-03 16:54:00 -0700
commit04fedee9f6be1e3e46a8c91c9a39343513cc6fe1 (patch)
treecb221b9304905e25695c59be60f0eeb62fe25a36
parent697e7da6e1379ac23cd8dbb47a1246547abafda6 (diff)
parent37bb23c5549ffe690f65b1c04cf432bd3153bf04 (diff)
Merge branch 'bug/login_dialog_should_require_username' into develop
-rw-r--r--res/layout/log_in_dialog.xml4
-rwxr-xr-xres/values/strings.xml7
-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
5 files changed, 49 insertions, 19 deletions
diff --git a/res/layout/log_in_dialog.xml b/res/layout/log_in_dialog.xml
index 4c9fdbad..3a9eebb8 100644
--- a/res/layout/log_in_dialog.xml
+++ b/res/layout/log_in_dialog.xml
@@ -22,7 +22,7 @@
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:ems="10"
- android:hint="@string/username_ask"
+ android:hint="@string/username_hint"
android:inputType="textUri" >
<requestFocus />
@@ -33,7 +33,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
- android:hint="@string/password_ask"
+ android:hint="@string/password_hint"
android:inputType="textPassword" />
</LinearLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 532d2379..a6afb71d 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -274,11 +274,12 @@
<string name="name">Name</string>
<string name="description">Description</string>
<string name="use_anonymously_button">Use anonymously</string>
- <string name="username_ask">Introduce your username</string>
- <string name="password_ask">Enter your password</string>
+ <string name="username_hint">username</string>
+ <string name="username_ask">Please enter your username</string>
+ <string name="password_hint">password</string>
<string name="user_message">User message</string>
<string name="error_bad_user_password_user_message">Not valid username and/or password.</string>
- <string name="error_not_valid_password_user_message">Your password is not well-formed: it should have at least 8 characters.</string>
+ <string name="error_not_valid_password_user_message">It should have at least 8 characters.</string>
<string name="error_client_http_user_message">Try again: Client HTTP error</string>
<string name="error_io_exception_user_message">Try again: I/O error</string>
<string name="error_json_exception_user_message">Try again: Bad response from the server</string>
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).