From 1d578209fc774a33076afcf1d827f1af753748fe Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 27 Aug 2024 15:41:53 +0300 Subject: [PATCH] Ensure that the user sets a PIN before proceeding to main --- cmd/main.go | 2 +- internal/handlers/ussd/menuhandler.go | 8 ++++++++ internal/models/flags.go | 2 +- services/registration/create_pin.vis | 1 + services/registration/root.vis | 1 + services/registration/terms.vis | 2 +- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 295e371..d53dfe9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -43,7 +43,7 @@ func main() { state.FlagDebugger.Register(models.USERFLAG_INCORRECTDATEFORMAT,"INVALIDDATEFORMAT") state.FlagDebugger.Register(models.USERFLAG_INVALID_RECIPIENT,"INVALIDRECIPIENT") state.FlagDebugger.Register(models.USERFLAG_PINMISMATCH,"PINMISMATCH") - state.FlagDebugger.Register(models.USERFLAG_QUERYPIN,"QUERYPIN") + state.FlagDebugger.Register(models.USERFLAG_PIN_SET,"PIN_SET") state.FlagDebugger.Register(models.USERFLAG_INVALID_RECIPIENT_WITH_INVITE,"INVALIDRECIPIENT_WITH_INVITE") state.FlagDebugger.Register(models.USERFLAG_INVALID_AMOUNT,"INVALIDAMOUNT") state.FlagDebugger.Register(models.USERFLAG_UNLOCKFORUPDATE,"UNLOCKFORUPDATE") diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 5414dd2..897fff6 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -61,6 +61,13 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte) return res, err } + // if an account exists, set the flag and return + existingAccountData, err := h.accountFileHandler.ReadAccountData() + if existingAccountData != nil { + res.FlagSet = append(res.FlagSet, models.USERFLAG_ACCOUNT_CREATED) + return res, err + } + accountResp, err := server.CreateAccount() if err != nil { res.FlagSet = append(res.FlagSet, models.USERFLAG_ACCOUNT_CREATION_FAILED) @@ -119,6 +126,7 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res if bytes.Equal(input, []byte(accountData["AccountPIN"])) { res.FlagSet = []uint32{models.USERFLAG_VALIDPIN} res.FlagReset = []uint32{models.USERFLAG_PINMISMATCH} + res.FlagSet = append(res.FlagSet, models.USERFLAG_PIN_SET) } else { res.FlagSet = []uint32{models.USERFLAG_PINMISMATCH} } diff --git a/internal/models/flags.go b/internal/models/flags.go index ad0fd15..5ac1107 100644 --- a/internal/models/flags.go +++ b/internal/models/flags.go @@ -13,7 +13,7 @@ const ( USERFLAG_INCORRECTPIN USERFLAG_UNLOCKFORUPDATE USERFLAG_INVALID_AMOUNT - USERFLAG_QUERYPIN + USERFLAG_PIN_SET USERFLAG_VALIDPIN USERFLAG_PINMISMATCH USERFLAG_INCORRECTDATEFORMAT diff --git a/services/registration/create_pin.vis b/services/registration/create_pin.vis index cc6ecfe..3ecc474 100644 --- a/services/registration/create_pin.vis +++ b/services/registration/create_pin.vis @@ -3,4 +3,5 @@ CATCH account_creation_failed 22 1 MOUT exit 0 HALT LOAD save_pin 0 +INCMP quit 0 INCMP confirm_create_pin * diff --git a/services/registration/root.vis b/services/registration/root.vis index f3e6216..14b77f8 100644 --- a/services/registration/root.vis +++ b/services/registration/root.vis @@ -2,5 +2,6 @@ CATCH select_language 8 0 CATCH terms 9 0 LOAD check_account_status 0 CATCH account_pending 10 1 +CATCH create_pin 18 0 CATCH main 11 1 HALT diff --git a/services/registration/terms.vis b/services/registration/terms.vis index 768efa3..dea6797 100644 --- a/services/registration/terms.vis +++ b/services/registration/terms.vis @@ -4,4 +4,4 @@ MOUT yes 0 MOUT no 1 HALT INCMP create_pin 0 -INCMP _ * +INCMP quit *