- validation for login

This commit is contained in:
Matan Bar Yosef 2016-07-02 20:21:29 +03:00
parent a7af642aa1
commit ba606f6ca8

View file

@ -177,7 +177,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
Log.d(TAG, "user: " + username); Log.d(TAG, "user: " + username);
Log.d(TAG, "pwd: " + password); Log.d(TAG, "pwd: " + password);
if(TextUtils.isEmpty(username) || !isPasswordValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) { if(TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
return false; return false;
} else{ } else{
return true; return true;
@ -203,38 +203,39 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
boolean cancel = false; boolean cancel = false;
View focusView = null; View focusView = null;
showProgress(true);
// Check for a valid password, if the user entered one.
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
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 ?
// http request register // http request register
JSONObject tempJson = new JSONObject(); JSONObject tempJson = new JSONObject();
try { try {
tempJson.put("username", username); tempJson.put("username", username);
tempJson.put("password", password); tempJson.put("password", password);
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, e.toString()); Log.d(TAG, e.toString());
}
VolleyUtilSingleton.getInstance(LoginActivity.this).post(BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError);
} }
VolleyUtilSingleton.getInstance(LoginActivity.this).post(BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError);
// Check for a valid password, if the user entered one.
// if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
// mPasswordView.setError(getString(R.string.error_invalid_password));
// focusView = mPasswordView;
// cancel = true;
// }
// if (cancel) {
// // There was an error; don't attempt login and focus the first
// // form field with an error.
// focusView.requestFocus();
// } else {
// // Show a progress spinner, and kick off a background task to
// // perform the user login attempt.
//
// }
} else { } else {
showProgress(false); showProgress(false);
Log.d(TAG, "Invalid params"); Log.d(TAG, "Invalid params - make sure username exist & password is greater than 4");
} }
// Check for a valid username // Check for a valid username
@ -256,9 +257,9 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
if(response.get("user") != null) { if(response.get("user") != null) {
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 b = new Bundle(); Bundle loginUserBundle = new Bundle();
b.putString("user_id", response.getJSONObject("user").getString("id")); loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id"));
personalSpaceActivity.putExtras(b); personalSpaceActivity.putExtras(loginUserBundle);
startActivity(personalSpaceActivity); startActivity(personalSpaceActivity);
} }
}catch (Exception e) { }catch (Exception e) {
@ -275,9 +276,9 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
}; };
private boolean isEmailValid(String email) { private boolean isUsernameValid(String username) {
//TODO: Replace this with your own logic //TODO: Replace this with your own logic
return email.contains("@") && email.contains("."); return username.length() > 0;
} }
private boolean isPasswordValid(String password) { private boolean isPasswordValid(String password) {