diff --git a/AndroidStudioProjects/QuicaR/app/src/androidTest/java/com/example/quicar/UpdateAccountTest.java b/AndroidStudioProjects/QuicaR/app/src/androidTest/java/com/example/quicar/UpdateAccountTest.java new file mode 100644 index 0000000..9b2b438 --- /dev/null +++ b/AndroidStudioProjects/QuicaR/app/src/androidTest/java/com/example/quicar/UpdateAccountTest.java @@ -0,0 +1,60 @@ +package com.example.quicar; + +import android.widget.EditText; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; + +import com.google.android.material.textfield.TextInputLayout; +import com.robotium.solo.Solo; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class UpdateAccountTest { + private Solo solo; + @Rule + public ActivityTestRule rule = new ActivityTestRule<>(UpdateAccountActivity.class, true, true); + + @Before + public void setUp() throws Exception { + solo = new Solo(InstrumentationRegistry.getInstrumentation(), rule.getActivity()); + } + + @Test + public void updateEmail() { + solo.clickInList(1); + solo.assertCurrentActivity("wrong activity", UpdateAccountActivity.class); + final EditText emailInput = (EditText) solo.getView(R.id.email_update); + final EditText passwordCheck = (EditText) solo.getView(R.id.password_check); + solo.enterText(emailInput, "newUser1@gmail.com"); + solo.enterText(passwordCheck, "123123"); + solo.clickOnText("OK"); + assertTrue(solo.waitForText("email updated successful")); + } + + @Test + public void checkDuplicateUpdateEmail() { + solo.clickInList(1); + solo.assertCurrentActivity("wrong activity", UpdateAccountActivity.class); + solo.enterText((EditText) solo.getView(R.id.email_update), "newUser1@gmail.com"); + solo.enterText((EditText) solo.getView(R.id.password_check), "123123"); + solo.clickOnText("OK"); + assertTrue(solo.waitForText("This email is already in use")); + } + + @Test + public void updatePwd() { + solo.clickInList(2); + solo.assertCurrentActivity("wrong activity", UpdateAccountActivity.class); + solo.enterText((EditText) solo.getView(R.id.origin_pwd), "123123"); + solo.enterText((EditText) solo.getView(R.id.pwd_dialog_change), "123456"); + solo.enterText((EditText) solo.getView(R.id.pwd_confirm_dialog), "123456"); + solo.clickOnText("OK"); + assertTrue(solo.waitForText("password updated")); + } +} diff --git a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Login.java b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Login.java index 347e7df..50442cb 100644 --- a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Login.java +++ b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Login.java @@ -110,6 +110,8 @@ public void onClick(View v) { return; } if (!checkUserNameOrEmail(myID)) { + // If user signs in my username + // retrieve that user's email DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference(); Query query = databaseReference.child("User").orderByChild("accountInfo/userName").equalTo(myID); query.addListenerForSingleValueEvent(new ValueEventListener() { @@ -123,6 +125,7 @@ public void onDataChange(DataSnapshot dataSnapshot) { User myUser = dataSnapshot1.getValue(User.class); String getEmail = myUser.getAccountInfo().getEmail(); + // get user's email mAuth.signInWithEmailAndPassword(getEmail, mypwd) .addOnCompleteListener(new OnCompleteListener() { @Override @@ -153,6 +156,7 @@ public void onCancelled(@NonNull DatabaseError databaseError) { } }); } else { + // if user signs in by email mAuth.signInWithEmailAndPassword(myID, mypwd).addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { @@ -294,6 +298,9 @@ public void onSuccess(User user, String tag) { } } + /** + * save user's login information + * */ public void getPrefData() { SharedPreferences sp = getSharedPreferences(PREF, MODE_PRIVATE); if (sp.contains("mpref_name")) { diff --git a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Register.java b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Register.java index 332ba8d..a04a237 100644 --- a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Register.java +++ b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/Register.java @@ -99,6 +99,7 @@ public void onComplete(@NonNull Task task) { user.setBasic(mUserName, mEmail, mPwd); UserDataHelper.getInstance().addNewUser(user, listener); DatabaseHelper.getInstance().setCurrentUser(user); + // signs in with realtime database database.getInstance().getReference("User").child(auth.getInstance().getCurrentUser().getUid()) .setValue(user).addOnCompleteListener(new OnCompleteListener() { @Override diff --git a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/UpdateAccountActivity.java b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/UpdateAccountActivity.java index f6f187b..cf860e7 100644 --- a/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/UpdateAccountActivity.java +++ b/AndroidStudioProjects/QuicaR/app/src/main/java/com/example/quicar/UpdateAccountActivity.java @@ -66,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (position == 0) { + // if user clicks "change email" AlertDialog.Builder builder = new AlertDialog.Builder(UpdateAccountActivity.this); LayoutInflater inflater = LayoutInflater.from(UpdateAccountActivity.this); View viewDialog = inflater.inflate(R.layout.username_update_dialog, null); @@ -154,6 +155,7 @@ public void onComplete(@NonNull Task task) { } if (position == 1) { + // if user clicks "change password" AlertDialog.Builder builderPwd = new AlertDialog.Builder(UpdateAccountActivity.this); LayoutInflater inflaterPwd = LayoutInflater.from(UpdateAccountActivity.this); View viewDialogPwd = inflaterPwd.inflate(R.layout.password_update_dialog, null); @@ -199,9 +201,11 @@ public void onClick(DialogInterface dialog, int which) { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { + // re auth successful Log.d(TAG, "User re-authenticated."); Toast.makeText(getApplicationContext(), "re-authenticated", Toast.LENGTH_SHORT).show(); if (!pwdReset.equals(pwdResetConfirm)) { + // if user confirms the password incorrectly Toast.makeText(getApplicationContext(), "new passwords didn't match", Toast.LENGTH_SHORT).show(); } else { mUser.updatePassword(pwdReset) @@ -240,6 +244,10 @@ public void onComplete(@NonNull Task task) { public static boolean isValidEmail(String email) { + /** + * validate the correct form of the email + * @param email: user enters the email + */ String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\."+ "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z" + diff --git a/doc/readme.txt b/doc/readme.txt deleted file mode 100644 index ca054f9..0000000 --- a/doc/readme.txt +++ /dev/null @@ -1,49 +0,0 @@ - -README - -Database Part - -BUGS - -1. notification goto intent is always MainActivity for now - -2. The check notification method is not very accurate as the rider can have multiple requests where we need to decide whether or not notify the rider or just the currently active request. There is a problem that rider can have multiple active requests but it is now not supported by the app. - -3. not able to return to the previous activity if the user quit the app and open it again. - -4. there is an extra attribute that is not used - - -TO BE IMPROVED - -1. store every user’s current location, only updated when using the app, and can be retrieved both as a rider or driver to achieve real-time locating of rider and driver in a request - -2. add time attribute to request so that a request can be set for future ride - -3. open request not accepted after a certain duration from the specified request time will be canceled automatically - -4. driver/user details on request cannot be updated yet. - -5.functionality of rating for drivers still hasn’t implemented. - -6. After picked rider up, it will jump back to driver register activity. - -Login page -Bugs: -When multiple users login/sign up at the same time, users may wait for database responses for a long time. -When the user uses email as a username to log in/sign up, it might result in an error when login. -Sometimes maybe login timeout -To be improved: - 1. Improve the design of the login/register page - 2. Let the user chooses to remember the password so that the user doesn't need to fill all the information again. - 3. (If the time available) sign in by using the fingerprint. - -Profile&Wallet -Bugs: -In the Wallet transfer page, after confirmed, maybe some problem with activity swap(For all users) -Driver need to re-login to see update balance -Sometimes the new user may have the null wallet to crash program - -Improved: -1.update profile and wallet still need to be better limited for user input. -2. Unit Tests and Activities Tests need to be more specific