- fixed validation for null users

This commit is contained in:
Matan Bar Yosef 2016-07-02 21:21:16 +03:00
parent c68dd0fad4
commit 394a32dac4
3 changed files with 12 additions and 8 deletions

View file

@ -5,7 +5,7 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="LOCAL" /> <option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.10" /> <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View file

@ -187,6 +187,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
if (mAuthTask != null) { if (mAuthTask != null) {
return; return;
} }
showProgress(true);
// Reset errors. // Reset errors.
// mEmailView.setError(null); // mEmailView.setError(null);
@ -198,12 +199,12 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
// String email = mEmailView.getText().toString(); // String email = mEmailView.getText().toString();
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) { if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
String username = mUsernameView.getText().toString(); String username = mUsernameView.getText().toString();
String password = mPasswordView.getText().toString(); String password = mPasswordView.getText().toString();
boolean cancel = false; boolean cancel = false;
View focusView = null; View focusView = null;
showProgress(true);
// mAuthTask = new UserLoginTask(username, password); // TODO: RETRIEVE ? // mAuthTask = new UserLoginTask(username, password); // TODO: RETRIEVE ?
// mAuthTask.execute((Void) null); // TODO: RETRIEVE ? // mAuthTask.execute((Void) null); // TODO: RETRIEVE ?
@ -235,7 +236,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
// } // }
} else { } else {
showProgress(false); showProgress(false);
Log.d(TAG, "Invalid params - make sure username exist & password is greater than 4"); Log.d(TAG, "Invalid params - make sure username exist & password is 4 characters or more");
} }
// Check for a valid username // Check for a valid username
@ -254,13 +255,17 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
@Override @Override
public void onResponse(JSONObject response) { public void onResponse(JSONObject response) {
try { try {
if(response.get("user") != null) { // if(response.get("user") != null) {
if(!response.isNull("user")) {
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class); Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class);
Bundle loginUserBundle = new Bundle(); Bundle loginUserBundle = new Bundle();
loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id")); loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id"));
personalSpaceActivity.putExtras(loginUserBundle); personalSpaceActivity.putExtras(loginUserBundle);
startActivity(personalSpaceActivity); startActivity(personalSpaceActivity);
} else {
showProgress(false);
Log.d(TAG, "No such user, " + response.get("user"));
} }
}catch (Exception e) { }catch (Exception e) {
Log.e(TAG, "onLoginSuccess:" + e.getMessage()); Log.e(TAG, "onLoginSuccess:" + e.getMessage());
@ -271,19 +276,18 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
Response.ErrorListener onLoginError = new Response.ErrorListener() { Response.ErrorListener onLoginError = new Response.ErrorListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
showProgress(false);
Log.d(TAG, "onLoginError: msg: " + error.getMessage()); Log.d(TAG, "onLoginError: msg: " + error.getMessage());
} }
}; };
private boolean isUsernameValid(String username) { private boolean isUsernameValid(String username) {
//TODO: Replace this with your own logic
return username.length() > 0; return username.length() > 0;
} }
private boolean isPasswordValid(String password) { private boolean isPasswordValid(String password) {
//TODO: Replace this with your own logic return password.length() > 3;
return password.length() > 4;
} }
/** /**

View file

@ -4,7 +4,7 @@
<!-- Strings related to login --> <!-- Strings related to login -->
<string name="prompt_email">Email</string> <string name="prompt_email">Email</string>
<string name="prompt_username">Username</string> <string name="prompt_username">Username</string>
<string name="prompt_password">Password (optional)</string> <string name="prompt_password">Password</string>
<string name="action_login">Login</string> <string name="action_login">Login</string>
<string name="action_register">Register</string> <string name="action_register">Register</string>
<string name="action_sign_in_short">Sign in</string> <string name="action_sign_in_short">Sign in</string>