reset account blocked flag #13

Merged
lash merged 2 commits from reset-account-blocked-flag into master 2025-01-21 07:47:33 +01:00
3 changed files with 40 additions and 2 deletions

View File

@ -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)
Review

why is the check for incorrect pin attempts needed here? Why not just put it as part of the incorrect pin reset? Wouldn't that reduce the need for one read operation?

why is the check for incorrect pin attempts needed here? Why not just put it as part of the incorrect pin reset? Wouldn't that reduce the need for one read operation?
Review

The check exists to reset the flag once the user access the menu.

Having the operation as part of the PIN reset increased complexity as we need to access the state of the user, reset the account blocked flag and save the state

The check exists to reset the flag once the user access the menu. Having the operation as part of the PIN reset increased complexity as we need to access the state of the user, reset the account blocked flag and save the state
Review

Hmm. Ok. It's not entirely clear to me why it is like this, as any point where the pin is reset would simply enable to set the flag as reset? There would be no need to read the flag?

Hmm. Ok. It's not entirely clear to me why it is like this, as any point where the pin is reset would simply enable to set the flag as reset? There would be no need to read the flag?
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
@ -467,7 +496,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

View File

@ -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)

View File

@ -1,3 +1,5 @@
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