From 948a9d3a93e8a29f81744f62ad38ab31106752a5 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 13:24:03 +0300 Subject: [PATCH] allow one to go back during the change PIN --- internal/handlers/ussd/menuhandler.go | 29 +++++++++++++++------------ services/registration/new_pin.vis | 11 ++++------ services/registration/old_pin.vis | 6 ++++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index e998bd5..0e40cb5 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -241,21 +241,24 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt accountPIN := string(input) - // Validate that the PIN is a 4-digit number - if !isValidPIN(accountPIN) { - res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + if accountPIN != "0" { // for the 0:Back case + // 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 } - 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) GetVoucherList(ctx context.Context,sym string,input []byte) (resource.Result,error){ +func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result vouchers := []string{ "SRF", @@ -286,9 +289,9 @@ func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) ( for i, voucher := range vouchers { numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher)) } - res.Content = strings.Join(numberedVouchers,"\n") + res.Content = strings.Join(numberedVouchers, "\n") - return res,nil + return res, nil } func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { @@ -577,7 +580,7 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res if err != nil { return res, err } - if len(input) == 4 { + if len(input) > 1 { if bytes.Equal(input, AccountPin) { if h.st.MatchFlag(flag_account_authorized, false) { res.FlagReset = append(res.FlagReset, flag_incorrect_pin) diff --git a/services/registration/new_pin.vis b/services/registration/new_pin.vis index 29013a9..ddcb7cc 100644 --- a/services/registration/new_pin.vis +++ b/services/registration/new_pin.vis @@ -1,13 +1,10 @@ -LOAD authorize_account 12 -RELOAD authorize_account -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH old_pin flag_allow_update 0 +CATCH _ flag_allow_update 0 MOUT back 0 HALT INCMP _ 0 LOAD save_temporary_pin 6 -LOAD verify_new_pin 0 RELOAD save_temporary_pin +LOAD verify_new_pin 8 RELOAD verify_new_pin -INCMP * confirm_pin_change - +CATCH incorrect_pin flag_incorrect_pin 1 +INCMP confirm_pin_change * diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis index 1e99f4f..52379eb 100644 --- a/services/registration/old_pin.vis +++ b/services/registration/old_pin.vis @@ -1,7 +1,9 @@ LOAD reset_allow_update 0 +RELOAD reset_allow_update MOUT back 0 HALT -RELOAD reset_allow_update +LOAD authorize_account 12 +RELOAD authorize_account +CATCH incorrect_pin flag_incorrect_pin 1 INCMP _ 0 INCMP new_pin * -