Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4ac8c3b
-handled redirection form api calls
pm-dimagi May 28, 2025
ff7cf3a
Merge branch 'master' of https://github.com/dimagi/commcare-android i…
pm-dimagi May 28, 2025
0e6f010
-made api call , refactored code, and handle navigation
pm-dimagi May 28, 2025
3692092
-refactoring of code, removed password fields
pm-dimagi May 28, 2025
6f578a7
refactored code
pm-dimagi May 28, 2025
e65c7d3
-removed secret ke as it not in use
pm-dimagi May 28, 2025
089c00b
-fixed isvalid code and navigation refactor
pm-dimagi May 28, 2025
eb2e8ef
- change userid to personalId,add field of backup code in session
pm-dimagi May 29, 2025
b530fe8
-removed connect user record taken data from session , create user da…
pm-dimagi May 29, 2025
56256ba
- bug fix , and lint issue resolved
pm-dimagi May 29, 2025
65f1502
-implemented new implementation of atempts_left instead of account_or…
pm-dimagi May 29, 2025
d79eef8
-complete profile parser
pm-dimagi May 29, 2025
b3b89ce
Merge branch 'master' of https://github.com/dimagi/commcare-android i…
pm-dimagi May 29, 2025
d33374e
- allow retry on every page , refactor function name , handled the cu…
pm-dimagi May 30, 2025
8ad1045
Merge branch 'pm_ccct_1223_2' of https://github.com/dimagi/commcare-a…
pm-dimagi May 30, 2025
73b0448
-resolved conflicts
pm-dimagi May 30, 2025
cd77c9a
-handled null values
pm-dimagi May 30, 2025
c57d9b4
Merge branch 'master' of https://github.com/dimagi/commcare-android i…
pm-dimagi May 30, 2025
91d24ae
Merge branch 'pm_ccct_1223_2' of https://github.com/dimagi/commcare-a…
pm-dimagi May 30, 2025
63b9399
-handle the null at time odf parsing
pm-dimagi May 30, 2025
18dcde2
-removed extra null check
pm-dimagi May 30, 2025
16bc301
Merge pull request #3139 from dimagi/pm_ccct_1223_3
pm-dimagi May 30, 2025
537b6f5
-refactored the variable names and method
pm-dimagi May 30, 2025
d61750d
-removed unused variable
pm-dimagi May 30, 2025
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/res/layout/fragment_recovery_code.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<TextView
android:textStyle="bold"
android:id="@+id/phone_title"
android:id="@+id/backup_code_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand Down
2 changes: 1 addition & 1 deletion app/res/layout/screen_personalid_phoneno.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:background="@color/connect_light_grey" />

<TextView
android:id="@+id/phone_title"
android:id="@+id/backup_code_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand Down
1 change: 0 additions & 1 deletion app/res/navigation/nav_graph_personalid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
android:label="fragment_personalid_photo_capture">
<argument
android:name="userName"
android:defaultValue=""
app:argType="string" />
<action
android:id="@+id/action_personalid_signup_fragment_self"
Expand Down
4 changes: 4 additions & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -924,4 +924,8 @@
<string name="this_is_not_me"><u>This is not me</u></string>
<string name="welcome_back_msg">Welcome back %s</string>
<string name="configuration_process_api_failed">Unable to contact our servers at this time. Please try again and report an issue if it persists.</string>
<string name="recovery_failed_title">Recovery failed</string>
<string name="recovery_failed_message">Looks like you’ve forgotten your Backup Code, we’re creating a new account for you</string>
<string name="personalid_wrong_backup_message">You entered the wrong Backup Code, please try again. You will need to create a new account after %d more incorrect attempts.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,20 @@ public ConnectUserRecord() {
verifySecondaryPhoneByDate = new Date();
}

public ConnectUserRecord(String primaryPhone, String userId, String password, String name,
String alternatePhone) {
public ConnectUserRecord(String primaryPhone, String userId, String password, String name, String pin,
Date lastPinVerifyDate, String photo, boolean isDemo) {
this();
this.primaryPhone = primaryPhone;
this.alternatePhone = alternatePhone;
this.userId = userId;
this.password = password;
this.name = name;

this.pin = pin;
this.lastPasswordDate = lastPinVerifyDate;
this.photo = photo;
this.isDemo = isDemo;
connectTokenExpiration = new Date();
}

public static ConnectUserRecord getUserFromIntent(Intent intent) {
return new ConnectUserRecord(
intent.getStringExtra(ConnectConstants.PHONE),
intent.getStringExtra(ConnectConstants.USERNAME),
intent.getStringExtra(ConnectConstants.PASSWORD),
intent.getStringExtra(ConnectConstants.NAME),
intent.getStringExtra(ConnectConstants.ALT_PHONE));
}

public void putUserInIntent(Intent intent) {
intent.putExtra(ConnectConstants.PHONE, primaryPhone);
intent.putExtra(ConnectConstants.USERNAME, userId);
intent.putExtra(ConnectConstants.PASSWORD, password);
intent.putExtra(ConnectConstants.NAME, name);
intent.putExtra(ConnectConstants.ALT_PHONE, alternatePhone);
}

public String getUserId() {
return userId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ data class PersonalIdSessionData(
var sessionFailureSubcode: String? = null, // Sub Reason code to tell why user is not allowed to move forward with the flow
var accountExists: Boolean? = null, // Tells weather its new user or old
var photoBase64: String? = null, // photo of the user
var username: String? = null, // name os the user
var personalId: String? = null, // username given by server
var dbKey: String? = null, // DB Key
var oauthPassword: String? = null, // password to verify usser
var accountOrphaned: Boolean? = null // Nobody owns this account
var attemptsLeft: Int? = null, // number of attempts left before the account lock
var userName: String? = null, // name of the user
var phoneNumber: String? = null, //phone number of the user
var backupCode: String? = null, //recovery code of the user
) {

/**
Expand Down
4 changes: 4 additions & 0 deletions app/src/org/commcare/connect/ConnectConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ConnectConstants {
public static final String CONNECT_KEY_EXPIRES = "expires_in";
public static final String BEGIN_REGISTRATION = "BEGIN_REGISTRATION";
public static final String VERIFY_PHONE = "VERIFY_PHONE";
public static final String USER_PHOTO = "PHOTO";
public static final String IS_DEMO = "IS_DEMO";
public static final String PIN_LAST_VERIFIED_DATE = "PIN_LAST_VERIFIED_DATE";
public static final String CCC_DEST_OPPORTUNITY_SUMMARY_PAGE = "ccc_opportunity_summary_page";
public static final String CCC_DEST_LEARN_PROGRESS = "ccc_learn_progress";
public static final String CCC_DEST_DELIVERY_PROGRESS = "ccc_delivery_progress";
Expand Down Expand Up @@ -60,4 +63,5 @@ public class ConnectConstants {
public final static int CONNECT_JOB_INFO = ConnectConstants.PERSONAL_ID_TASK_ID_OFFSET + 14;
public final static int PERSONALID_RECOVERY_WRONG_PIN = ConnectConstants.PERSONAL_ID_TASK_ID_OFFSET + 15;
public final static int PERSONALID_DEVICE_CONFIGURATION_FAILED = ConnectConstants.PERSONAL_ID_TASK_ID_OFFSET + 16;
public final static int PERSONALID_RECOVERY_ACCOUNT_ORPHANED = ConnectConstants.PERSONAL_ID_TASK_ID_OFFSET + 17;
}
14 changes: 7 additions & 7 deletions app/src/org/commcare/connect/network/ApiPersonalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static void confirmBackupCode(Context context,
String tokenAuth = HttpUtils.getCredential(authInfo);

ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.confirmPin(tokenAuth, params);
Call<ResponseBody> call = apiService.confirmBackupCode(tokenAuth, params);
callApi(context, call, callback);
}

Expand Down Expand Up @@ -321,21 +321,21 @@ public static void updateUserProfile(Context context, String username,
callApi(context, call, callback);
}

public static void setPhotoAndCompleteProfile(Context context, String userId, String password, String userName,
String photoAsBase64, String backupCode, IApiCallback callback) {
public static void setPhotoAndCompleteProfile(Context context, String userName,
String photoAsBase64, String backupCode, String token, IApiCallback callback) {
Objects.requireNonNull(photoAsBase64);
Objects.requireNonNull(userName);
AuthInfo authInfo = new AuthInfo.ProvidedAuth(userId, password, false);
String token = HttpUtils.getCredential(authInfo);
Objects.requireNonNull(token);
AuthInfo authInfo = new AuthInfo.TokenAuth(token);
String tokenAuth = HttpUtils.getCredential(authInfo);
Objects.requireNonNull(tokenAuth);

HashMap<String, String> params = new HashMap<>();
params.put("photo", photoAsBase64);
params.put("name", userName);
params.put("recovery_pin", backupCode);

ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.completeProfile(token, params);
Call<ResponseBody> call = apiService.completeProfile(tokenAuth, params);
callApi(context, call, callback);
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/org/commcare/connect/network/PersonalIdApiHandler.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.commcare.connect.network;

import android.app.Activity;
import android.content.Context;

import org.commcare.android.database.connect.models.PersonalIdSessionData;
import org.commcare.connect.network.parser.AddOrVerifyNameParser;
import org.commcare.connect.network.parser.CompleteProfileResponseParser;
import org.commcare.connect.network.parser.ConfirmBackupCodeResponseParser;
import org.commcare.connect.network.parser.PersonalIdApiResponseParser;
import org.commcare.connect.network.parser.StartConfigurationResponseParser;
Expand Down Expand Up @@ -100,6 +102,14 @@ public void confirmBackupCode(Activity activity, String backupCode, PersonalIdSe
PersonalIdApiErrorCodes.INVALID_RESPONSE_ERROR));
}

public void completeProfile(Context context, String userName,
String photoAsBase64, String backupCode, String token,PersonalIdSessionData sessionData) {
ApiPersonalId.setPhotoAndCompleteProfile(context, userName, photoAsBase64, backupCode, token,
createCallback(sessionData,
new CompleteProfileResponseParser(),
PersonalIdApiErrorCodes.INVALID_RESPONSE_ERROR));
}


protected abstract void onSuccess(PersonalIdSessionData sessionData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ApiEndPoints {
public static final String recoverSecondary = "/users/recover/secondary";
public static final String confirmOTP = "/users/confirm_otp";
public static final String setBackupCode = "/users/set_recovery_pin";
public static final String confirmPIN = "/users/recover/confirm_pin";
public static final String confirmBackupCode = "/users/recover/confirm_backup_code";
public static final String resetPassword = "/users/recover/reset_password";
public static final String changePassword = "/users/change_password";
public static final String confirmPassword = "/users/recover/confirm_password";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Call<ResponseBody> completeProfile(@Header("Authorization") String token,
Call<ResponseBody> confirmOTP(@Header("Authorization") String token,
@Body Map<String, String> confirmOTPRequest);

@POST(ApiEndPoints.confirmPIN)
Call<ResponseBody> confirmPin(@Header("Authorization") String token,
@Body Map<String, String> confirmBackupCodeRequest);
@POST(ApiEndPoints.confirmBackupCode)
Call<ResponseBody> confirmBackupCode(@Header("Authorization") String token,
@Body Map<String, String> confirmBackupCodeRequest);

@POST(ApiEndPoints.setBackupCode)
Call<ResponseBody> setBackupCode(@Header("Authorization") String token,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.commcare.connect.network.parser;

import org.commcare.android.database.connect.models.PersonalIdSessionData;
import org.commcare.utils.JsonExtensions;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Parses a JSON response from the complete profile API call
* and populates a PersonalIdSessionData instance.
*/
public class CompleteProfileResponseParser implements PersonalIdApiResponseParser {
/**
* Parses and sets values on the given PersonalIdSessionData instance.
*
* @param sessionData the instance to populate
* @throws JSONException if a parsing error occurs
*/
@Override
public void parse(JSONObject json, PersonalIdSessionData sessionData) throws JSONException {
sessionData.setPersonalId(Objects.requireNonNull(JsonExtensions.optStringSafe(json, "username", null)));
sessionData.setDbKey(Objects.requireNonNull(JsonExtensions.optStringSafe(json, "db_key", null)));
sessionData.setOauthPassword(Objects.requireNonNull(JsonExtensions.optStringSafe(json, "password", null)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public class ConfirmBackupCodeResponseParser implements PersonalIdApiResponsePar
*/
@Override
public void parse(JSONObject json, PersonalIdSessionData sessionData) throws JSONException {
sessionData.setUsername(JsonExtensions.optStringSafe(json, "username", null));
sessionData.setPersonalId(JsonExtensions.optStringSafe(json, "username", null));
sessionData.setDbKey(JsonExtensions.optStringSafe(json, "db_key", null));
sessionData.setAccountOrphaned(json.optBoolean("account_orphaned", false));
if (json.has("attempts_left")) {
sessionData.setAttemptsLeft(json.getInt("attempts_left"));
}
sessionData.setOauthPassword(JsonExtensions.optStringSafe(json, "password", null));
}
}
Loading
Loading