From 660f8b7aa201c43da8db23e0b84c6f0ccb3776c3 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 14:30:47 +0300 Subject: [PATCH 1/6] add pin reset nodes --- services/registration/confirm_pin_change | 1 + services/registration/confirm_pin_change.vis | 7 +++++++ services/registration/invalid_pin | 1 + services/registration/invalid_pin.vis | 3 +++ services/registration/new_pin | 1 + services/registration/new_pin.vis | 13 +++++++++++++ services/registration/old_pin | 1 + services/registration/old_pin.vis | 7 +++++++ services/registration/pin_management.vis | 2 ++ services/registration/pin_reset_mismatch | 1 + services/registration/pin_reset_mismatch.vis | 6 ++++++ services/registration/pin_reset_success | 1 + services/registration/pin_reset_success.vis | 10 ++++++++++ 13 files changed, 54 insertions(+) create mode 100644 services/registration/confirm_pin_change create mode 100644 services/registration/confirm_pin_change.vis create mode 100644 services/registration/invalid_pin create mode 100644 services/registration/invalid_pin.vis create mode 100644 services/registration/new_pin create mode 100644 services/registration/new_pin.vis create mode 100644 services/registration/old_pin create mode 100644 services/registration/old_pin.vis create mode 100644 services/registration/pin_reset_mismatch create mode 100644 services/registration/pin_reset_mismatch.vis create mode 100644 services/registration/pin_reset_success create mode 100644 services/registration/pin_reset_success.vis diff --git a/services/registration/confirm_pin_change b/services/registration/confirm_pin_change new file mode 100644 index 0000000..398a827 --- /dev/null +++ b/services/registration/confirm_pin_change @@ -0,0 +1 @@ +Confirm your new PIN: diff --git a/services/registration/confirm_pin_change.vis b/services/registration/confirm_pin_change.vis new file mode 100644 index 0000000..7691e01 --- /dev/null +++ b/services/registration/confirm_pin_change.vis @@ -0,0 +1,7 @@ +CATCH invalid_pin flag_valid_pin 0 +MOUT back 0 +HALT +INCMP _ 0 +INCMP * pin_reset_success + + diff --git a/services/registration/invalid_pin b/services/registration/invalid_pin new file mode 100644 index 0000000..dd984ea --- /dev/null +++ b/services/registration/invalid_pin @@ -0,0 +1 @@ +The PIN you entered is invalid.The PIN must be different from your current PIN.For help call +254757628885 \ No newline at end of file diff --git a/services/registration/invalid_pin.vis b/services/registration/invalid_pin.vis new file mode 100644 index 0000000..3790a08 --- /dev/null +++ b/services/registration/invalid_pin.vis @@ -0,0 +1,3 @@ +MOUT back 0 +HALT +INCMP _ 0 diff --git a/services/registration/new_pin b/services/registration/new_pin new file mode 100644 index 0000000..bae2814 --- /dev/null +++ b/services/registration/new_pin @@ -0,0 +1 @@ +Enter a new four number pin diff --git a/services/registration/new_pin.vis b/services/registration/new_pin.vis new file mode 100644 index 0000000..939f2d9 --- /dev/null +++ b/services/registration/new_pin.vis @@ -0,0 +1,13 @@ +LOAD authorize_account 12 +LOAD save_temporary_pin 6 +LOAD verify_new_pin 0 +RELOAD authorize_account +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH old_pin flag_allow_update 0 +MOUT back 0 +HALT +INCMP _ 0 +RELOAD save_temporary_pin +RELOAD verify_new_pin +INCMP * confirm_pin_change + diff --git a/services/registration/old_pin b/services/registration/old_pin new file mode 100644 index 0000000..2c64d42 --- /dev/null +++ b/services/registration/old_pin @@ -0,0 +1 @@ +Enter your old PIN diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis new file mode 100644 index 0000000..1e99f4f --- /dev/null +++ b/services/registration/old_pin.vis @@ -0,0 +1,7 @@ +LOAD reset_allow_update 0 +MOUT back 0 +HALT +RELOAD reset_allow_update +INCMP _ 0 +INCMP new_pin * + diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index ecd5a8c..3b33dad 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -4,3 +4,5 @@ MOUT guard_pin 3 MOUT back 0 HALT INCMP _ 0 +INCMP old_pin 1 + diff --git a/services/registration/pin_reset_mismatch b/services/registration/pin_reset_mismatch new file mode 100644 index 0000000..dc0236b --- /dev/null +++ b/services/registration/pin_reset_mismatch @@ -0,0 +1 @@ +The PIN is not a match. Try again diff --git a/services/registration/pin_reset_mismatch.vis b/services/registration/pin_reset_mismatch.vis new file mode 100644 index 0000000..5dc7e7c --- /dev/null +++ b/services/registration/pin_reset_mismatch.vis @@ -0,0 +1,6 @@ +MOUT retry 1 +MOUT quit 9 +HALT +INCMP confirm_pin_change 1 +INCMP quit 9 + diff --git a/services/registration/pin_reset_success b/services/registration/pin_reset_success new file mode 100644 index 0000000..e9326ec --- /dev/null +++ b/services/registration/pin_reset_success @@ -0,0 +1 @@ +Your PIN change request has been successful diff --git a/services/registration/pin_reset_success.vis b/services/registration/pin_reset_success.vis new file mode 100644 index 0000000..9873736 --- /dev/null +++ b/services/registration/pin_reset_success.vis @@ -0,0 +1,10 @@ +LOAD confirm_pin_change 0 +RELOAD confirm_pin_change +CATCH pin_reset_mismatch flag_pin_mismatch 1 +MOUT back 0 +MOUT quit 9 +HALT +INCMP _ 0 +INCMP quit 9 + + From 3f3e98e637326cd9b7d504485b9dadc2009be375 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 14:39:01 +0300 Subject: [PATCH 2/6] add pin reset handlers --- cmd/main.go | 3 + internal/handlers/ussd/menuhandler.go | 95 ++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 17 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 9222c13..9e20ba6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -71,6 +71,9 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) + rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) + rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) return ussdHandlers, nil } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 89ced5a..df8d44e 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -216,6 +216,74 @@ func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resou return res, nil } +func (h *Handlers) VerifyNewPin(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + _, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin") + pinInput := string(input) + // Validate that the PIN is a 4-digit number + if isValidPIN(pinInput) { + res.FlagSet = append(res.FlagSet, flag_valid_pin) + } else { + res.FlagReset = append(res.FlagReset, flag_valid_pin) + } + + return res, nil +} + +func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + var err error + + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin") + + accountPIN := string(input) + + // Validate that the PIN is a 4-digit number + if !isValidPIN(accountPIN) { + res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + return res, nil + } + store := h.userdataStore + err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN)) + if err != nil { + return res, err + } + return res, nil +} + +func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch") + + store := h.userdataStore + temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN) + if err != nil { + return res, err + } + if bytes.Equal(temporaryPin, input) { + res.FlagReset = append(res.FlagReset, flag_pin_mismatch) + } else { + res.FlagSet = append(res.FlagSet, flag_pin_mismatch) + } + err = store.WriteEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(temporaryPin)) + if err != nil { + return res, err + } + return res, nil +} + // SetResetSingleEdit sets and resets flags to allow gradual editing of profile information. func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result @@ -322,9 +390,6 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte) if err != nil { return res, err } - if err != nil { - return res, nil - } } else { return res, fmt.Errorf("a family name cannot be less than one character") } @@ -481,27 +546,23 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res if err != nil { return res, err } - - if err == nil { - if len(input) == 4 { - if bytes.Equal(input, AccountPin) { - if h.st.MatchFlag(flag_account_authorized, false) { - res.FlagReset = append(res.FlagReset, flag_incorrect_pin) - res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized) - } else { - res.FlagSet = append(res.FlagSet, flag_allow_update) - res.FlagReset = append(res.FlagReset, flag_account_authorized) - } + if len(input) == 4 { + if bytes.Equal(input, AccountPin) { + if h.st.MatchFlag(flag_account_authorized, false) { + res.FlagReset = append(res.FlagReset, flag_incorrect_pin) + res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized) } else { - res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + res.FlagSet = append(res.FlagSet, flag_allow_update) res.FlagReset = append(res.FlagReset, flag_account_authorized) - return res, nil } + } else { + res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + res.FlagReset = append(res.FlagReset, flag_account_authorized) + return res, nil } } else { return res, nil } - return res, nil } From a3f410875a18ac5a0b57764775a3e126a2d6bdc3 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 14:39:42 +0300 Subject: [PATCH 3/6] define temporary key value --- internal/utils/db.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/utils/db.go b/internal/utils/db.go index 5479f27..410da68 100644 --- a/internal/utils/db.go +++ b/internal/utils/db.go @@ -22,6 +22,7 @@ const ( DATA_OFFERINGS DATA_RECIPIENT DATA_AMOUNT + DATA_TEMPORARY_PIN ) func typToBytes(typ DataTyp) []byte { From 04edd90c21ea5e30b427809d31b54ca3b940c48a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 14:58:56 +0300 Subject: [PATCH 4/6] fix sink issue onback option --- services/registration/new_pin.vis | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/registration/new_pin.vis b/services/registration/new_pin.vis index 939f2d9..29013a9 100644 --- a/services/registration/new_pin.vis +++ b/services/registration/new_pin.vis @@ -1,12 +1,12 @@ LOAD authorize_account 12 -LOAD save_temporary_pin 6 -LOAD verify_new_pin 0 RELOAD authorize_account CATCH incorrect_pin flag_incorrect_pin 1 CATCH old_pin flag_allow_update 0 MOUT back 0 HALT INCMP _ 0 +LOAD save_temporary_pin 6 +LOAD verify_new_pin 0 RELOAD save_temporary_pin RELOAD verify_new_pin INCMP * confirm_pin_change From 09f970db9bd97b7251663e4baaf93f0e3e8b4e84 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 14:59:26 +0300 Subject: [PATCH 5/6] navigate to main menu after successful pin reset --- services/registration/pin_reset_success.vis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/pin_reset_success.vis b/services/registration/pin_reset_success.vis index 9873736..c942519 100644 --- a/services/registration/pin_reset_success.vis +++ b/services/registration/pin_reset_success.vis @@ -4,7 +4,7 @@ CATCH pin_reset_mismatch flag_pin_mismatch 1 MOUT back 0 MOUT quit 9 HALT -INCMP _ 0 +INCMP main 0 INCMP quit 9 From a3f2b231283773ae5cd5f2765240c84e40ea572d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 16 Sep 2024 15:17:15 +0300 Subject: [PATCH 6/6] add pin reset templates for swahili --- services/registration/confirm_pin_change_swa | 1 + services/registration/invalid_pin_swa | 1 + services/registration/new_pin_swa | 2 ++ services/registration/old_pin_swa | 1 + services/registration/pin_reset_success_swa | 1 + 5 files changed, 6 insertions(+) create mode 100644 services/registration/confirm_pin_change_swa create mode 100644 services/registration/invalid_pin_swa create mode 100644 services/registration/new_pin_swa create mode 100644 services/registration/old_pin_swa create mode 100644 services/registration/pin_reset_success_swa diff --git a/services/registration/confirm_pin_change_swa b/services/registration/confirm_pin_change_swa new file mode 100644 index 0000000..c7af4ea --- /dev/null +++ b/services/registration/confirm_pin_change_swa @@ -0,0 +1 @@ +Thibitisha PIN yako mpya: diff --git a/services/registration/invalid_pin_swa b/services/registration/invalid_pin_swa new file mode 100644 index 0000000..1817570 --- /dev/null +++ b/services/registration/invalid_pin_swa @@ -0,0 +1 @@ +PIN mpya na udhibitisho wa pin mpya hazilingani.Tafadhali jaribu tena.Kwa usaidizi piga simu +254757628885. diff --git a/services/registration/new_pin_swa b/services/registration/new_pin_swa new file mode 100644 index 0000000..1ec32d9 --- /dev/null +++ b/services/registration/new_pin_swa @@ -0,0 +1,2 @@ +Weka PIN mpya ya nne nambari: + diff --git a/services/registration/old_pin_swa b/services/registration/old_pin_swa new file mode 100644 index 0000000..312b597 --- /dev/null +++ b/services/registration/old_pin_swa @@ -0,0 +1 @@ +Weka PIN yako ya zamani: diff --git a/services/registration/pin_reset_success_swa b/services/registration/pin_reset_success_swa new file mode 100644 index 0000000..af69b9f --- /dev/null +++ b/services/registration/pin_reset_success_swa @@ -0,0 +1 @@ +Ombi lako la kubadili PIN limefanikiwa