Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix#1250 passcode verification implemented #1251

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@
android:exported="false"
android:name="org.mifos.mobile.utils.fcm.RegistrationIntentService">
</service>

<activity android:name="org.mifos.mobile.ui.activities.SettingsActivity"/>
<activity android:name="com.mifos.mobile.passcode.TransferVerificationActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.mifos.mobile.passcode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import android.widget.ImageView;
import android.widget.TextView;

import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper;
import com.mifos.mobile.passcode.utils.EncryptionUtil;

import org.mifos.mobile.utils.Toaster;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;


public class TransferVerificationActivity extends
AppCompatActivity implements
MifosPassCodeView.
PassCodeListener {

NestedScrollView clRootview;
AppCompatButton btnForgotPasscode;
MifosPassCodeView mifosPassCodeView;
AppCompatButton btnSkip;
AppCompatButton btnSave;
TextView tvPasscodeIntro;
ImageView ivVisibility;
ImageView ivLogo;

private PasscodePreferencesHelper passcodePreferencesHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_code);

clRootview = findViewById(R.id.cl_rootview);
btnForgotPasscode = findViewById(R.id.btn_forgot_passcode);
mifosPassCodeView = findViewById(R.id.pv_passcode);
btnSkip = findViewById(R.id.btn_skip);
btnSkip.setText(getString(org.mifos.mobile.R.string.cancel_transaction));
btnSave = findViewById(R.id.btn_save);
btnSave.setText(getString(org.mifos.mobile.R.string.transfer));
tvPasscodeIntro = findViewById(R.id.tv_passcode);
tvPasscodeIntro.setText(getString(org.mifos.mobile.R.string.transfer_verify_passcode));
ivVisibility = findViewById(R.id.iv_visibility);
ivLogo = findViewById(R.id.iv_logo);
ivLogo.setImageResource(org.mifos.mobile.R.drawable.mifos_logo);

passcodePreferencesHelper = new PasscodePreferencesHelper(this);

}

private String encryptPassCode(String passCode) {
String encryptedPassCode = EncryptionUtil.getMobileBankingHash(passCode);
return encryptedPassCode;
}


public void savePassCode(View view) {
if (isPassCodeLengthCorrect()) {
if (encryptPassCode(mifosPassCodeView.getPasscode())
.equals(passcodePreferencesHelper
.getPassCode())
) {
Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();
} else {
Toaster.show(view, org.mifos.mobile.R.string.incorrect_passcode);
}
} else {
Toaster.show(view, org.mifos.mobile.R.string.incorrect_passcode);
}
}

@Override
public void passCodeEntered(String passcode) { }

public void clickedOne(View v) {
mifosPassCodeView.enterCode(getString(R.string.one));
}

public void clickedTwo(View v) {
mifosPassCodeView.enterCode(getString(R.string.two));
}

public void clickedThree(View v) {
mifosPassCodeView.enterCode(getString(R.string.three));
}

public void clickedFour(View v) {
mifosPassCodeView.enterCode(getString(R.string.four));
}

public void clickedFive(View v) {
mifosPassCodeView.enterCode(getString(R.string.five));
}

public void clickedSix(View v) {
mifosPassCodeView.enterCode(getString(R.string.six));
}

public void clickedSeven(View v) {
mifosPassCodeView.enterCode(getString(R.string.seven));
}

public void clickedEight(View v) {
mifosPassCodeView.enterCode(getString(R.string.eight));
}

public void clickedNine(View v) {
mifosPassCodeView.enterCode(getString(R.string.nine));
}

public void clickedZero(View v) {
mifosPassCodeView.enterCode(getString(R.string.zero));
}

public void clickedBackSpace(View v) {
mifosPassCodeView.backSpace();
}

public void skip(View v) {
finish();
}

/**
* @param view PasscodeView that changes to text if it was hidden and vice a versa
*/
public void visibilityChange(View view) {
mifosPassCodeView.revertPassCodeVisibility();
if (!mifosPassCodeView.passcodeVisible()) {
ivVisibility.setColorFilter(
ContextCompat.getColor(
TransferVerificationActivity.this,
R.color.light_grey));
} else {
ivVisibility.setColorFilter(
ContextCompat.getColor(
TransferVerificationActivity.this,
R.color.gray_dark));
}
}

/**
* Checks whether passcode entered is of correct length
*
* @return Returns true if passcode lenght is 4 else shows message
*/
private boolean isPassCodeLengthCorrect() {
if (mifosPassCodeView.getPasscode().length() == 4) {
return true;
}
return false;
}

@Override
public void onBackPressed() { }

@Override
protected void onResume() {
super.onResume();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mifos.mobile.ui.fragments;

import android.content.Intent;
import android.graphics.drawable.Animatable;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand All @@ -10,6 +11,7 @@
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;
import com.mifos.mobile.passcode.TransferVerificationActivity;

import org.mifos.mobile.R;
import org.mifos.mobile.models.payload.TransferPayload;
Expand Down Expand Up @@ -124,11 +126,8 @@ public void startTransfer() {
Toaster.show(rootView, getString(R.string.internet_not_connected));
return;
}
if (transferType == TransferType.SELF) {
presenter.makeSavingsTransfer(payload);
} else if (transferType == TransferType.TPT) {
presenter.makeTPTTransfer(payload);
}
Intent i = new Intent(getActivity(), TransferVerificationActivity.class);
startActivityForResult(i, Constants.VERIFICATION_REQUEST);
}

/**
Expand Down Expand Up @@ -193,4 +192,17 @@ public void onDestroyView() {
super.onDestroyView();
presenter.detachView();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.VERIFICATION_REQUEST &&
resultCode == getActivity().RESULT_OK) {
if (transferType == TransferType.SELF) {
presenter.makeSavingsTransfer(payload);
} else if (transferType == TransferType.TPT) {
presenter.makeTPTTransfer(payload);
}
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/mifos/mobile/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@ public class Constants {
public static final String OUTSTANDING_BALANCE = "outstanding_balance";

public static final String LOAN_REPAYMENT = "loan_repayment";

public static final int VERIFICATION_REQUEST = 299;
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@
<string name="savings_account_transaction">Savings Account Transaction</string>
<string name="transaction_period">Transaction Period</string>
<string name="transaction_type">Transaction Type</string>
<string name="transfer_verify_passcode">Enter your passcode</string>
<string name="cancel_transaction">Cancel</string>
<string name="transfer_type">TransferType</string>

<string-array name="languages" translatable="false">
<item>English</item>
Expand Down