From 4fb3474b51757c3c4d637e81df68d25565a06a49 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 21 Jan 2025 02:28:19 +0300 Subject: [PATCH 1/2] reset the incorrect PIN attempts to 0 when the PIN is reset --- handlers/application/menuhandler.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 751573e..a4e1fed 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -467,7 +467,13 @@ func (h *MenuHandlers) ResetOthersPin(ctx context.Context, sym string, input []b err = store.WriteEntry(ctx, string(blockedPhonenumber), storedb.DATA_ACCOUNT_PIN, []byte(hashedTmporaryPin)) if err != nil { - return res, nil + return res, err + } + + err = store.WriteEntry(ctx, string(blockedPhonenumber), storedb.DATA_INCORRECT_PIN_ATTEMPTS, []byte(string("0"))) + if err != nil { + logg.ErrorCtxf(ctx, "failed to reset incorrect PIN attempts", "key", storedb.DATA_INCORRECT_PIN_ATTEMPTS, "error", err) + return res, err } return res, nil From fbee26da0872bab449a687e59975220496c14e9f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 21 Jan 2025 02:29:59 +0300 Subject: [PATCH 2/2] added CheckBlockedStatus to reset the flag_account_blocked if the incorrect PIN attempt has been reset --- handlers/application/menuhandler.go | 29 +++++++++++++++++++++++++++++ handlers/local.go | 1 + services/registration/root.vis | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index a4e1fed..d59d927 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -253,6 +253,35 @@ func (h *MenuHandlers) ResetValidPin(ctx context.Context, sym string, input []by return res, nil } +// CheckBlockedStatus resets the account blocked flag if the PIN attempts have been reset by an admin. +func (h *MenuHandlers) CheckBlockedStatus(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + store := h.userdataStore + + flag_account_blocked, _ := h.flagManager.GetFlag("flag_account_blocked") + + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + + currentWrongPinAttempts, err := store.ReadEntry(ctx, sessionId, storedb.DATA_INCORRECT_PIN_ATTEMPTS) + if err != nil { + if !db.IsNotFound(err) { + return res, nil + } + } + + pinAttemptsValue, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64) + + if pinAttemptsValue == 0 { + res.FlagReset = append(res.FlagReset, flag_account_blocked) + return res, nil + } + + return res, nil +} + // ResetIncorrectPin resets the incorrect pin flag after a new PIN attempt. func (h *MenuHandlers) ResetIncorrectPin(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result diff --git a/handlers/local.go b/handlers/local.go index 325fe89..77e3980 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -62,6 +62,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) } //appHandlers = appHandlers.WithPersister(ls.Pe) appHandlers.SetPersister(ls.Pe) + ls.DbRs.AddLocalFunc("check_blocked_status", appHandlers.CheckBlockedStatus) ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage) ls.DbRs.AddLocalFunc("create_account", appHandlers.CreateAccount) ls.DbRs.AddLocalFunc("save_temporary_pin", appHandlers.SaveTemporaryPin) diff --git a/services/registration/root.vis b/services/registration/root.vis index 102e6e5..3c78bea 100644 --- a/services/registration/root.vis +++ b/services/registration/root.vis @@ -1,9 +1,11 @@ +LOAD check_blocked_status 1 +RELOAD check_blocked_status CATCH blocked_account flag_account_blocked 1 CATCH select_language flag_language_set 0 CATCH terms flag_account_created 0 LOAD check_account_status 0 RELOAD check_account_status -CATCH api_failure flag_api_call_error 1 +CATCH api_failure flag_api_call_error 1 CATCH account_pending flag_account_pending 1 CATCH create_pin flag_pin_set 0 CATCH main flag_account_success 1