Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<UpdateAccountActivity> 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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<AuthResult>() {
@Override
Expand Down Expand Up @@ -153,6 +156,7 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
} else {
// if user signs in by email
mAuth.signInWithEmailAndPassword(myID, mypwd).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Expand Down Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void onComplete(@NonNull Task<AuthResult> 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<Void>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -154,6 +155,7 @@ public void onComplete(@NonNull Task<Void> 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);
Expand Down Expand Up @@ -199,9 +201,11 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public void onComplete(@NonNull Task<Void> 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)
Expand Down Expand Up @@ -240,6 +244,10 @@ public void onComplete(@NonNull Task<Void> 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" +
Expand Down
49 changes: 0 additions & 49 deletions doc/readme.txt

This file was deleted.