- fixed validation for null users
This commit is contained in:
parent
c68dd0fad4
commit
394a32dac4
3 changed files with 12 additions and 8 deletions
|
@ -5,7 +5,7 @@
|
|||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<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">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
|
|
@ -187,6 +187,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
|
|||
if (mAuthTask != null) {
|
||||
return;
|
||||
}
|
||||
showProgress(true);
|
||||
|
||||
// Reset errors.
|
||||
// mEmailView.setError(null);
|
||||
|
@ -198,12 +199,12 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
|
|||
// String email = mEmailView.getText().toString();
|
||||
|
||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
||||
|
||||
String username = mUsernameView.getText().toString();
|
||||
String password = mPasswordView.getText().toString();
|
||||
|
||||
boolean cancel = false;
|
||||
View focusView = null;
|
||||
showProgress(true);
|
||||
// mAuthTask = new UserLoginTask(username, password); // TODO: RETRIEVE ?
|
||||
// mAuthTask.execute((Void) null); // TODO: RETRIEVE ?
|
||||
|
||||
|
@ -235,7 +236,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
|
|||
// }
|
||||
} else {
|
||||
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
|
||||
|
@ -254,13 +255,17 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
|
|||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
if(response.get("user") != null) {
|
||||
// if(response.get("user") != null) {
|
||||
if(!response.isNull("user")) {
|
||||
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
|
||||
Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class);
|
||||
Bundle loginUserBundle = new Bundle();
|
||||
loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id"));
|
||||
personalSpaceActivity.putExtras(loginUserBundle);
|
||||
startActivity(personalSpaceActivity);
|
||||
} else {
|
||||
showProgress(false);
|
||||
Log.d(TAG, "No such user, " + response.get("user"));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
Log.e(TAG, "onLoginSuccess:" + e.getMessage());
|
||||
|
@ -271,19 +276,18 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
|
|||
Response.ErrorListener onLoginError = new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
showProgress(false);
|
||||
Log.d(TAG, "onLoginError: msg: " + error.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private boolean isUsernameValid(String username) {
|
||||
//TODO: Replace this with your own logic
|
||||
return username.length() > 0;
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
//TODO: Replace this with your own logic
|
||||
return password.length() > 4;
|
||||
return password.length() > 3;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<!-- Strings related to login -->
|
||||
<string name="prompt_email">Email</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_register">Register</string>
|
||||
<string name="action_sign_in_short">Sign in</string>
|
||||
|
|
Loading…
Reference in a new issue