reset flags on back navigation,process only numeric pin entries

This commit is contained in:
Carlosokumu 2025-02-04 08:41:06 +03:00
parent cad18c9e64
commit 5722d4f8dd
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -326,12 +326,16 @@ func (h *MenuHandlers) VerifyNewPin(ctx context.Context, sym string, input []byt
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin") flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin")
pinInput := string(input) if !h.st.Back() {
// Validate that the PIN is a 4-digit number. pinInput := string(input)
if pin.IsValidPIN(pinInput) { // Validate that the PIN is a 4-digit number.
res.FlagSet = append(res.FlagSet, flag_valid_pin) if pin.IsValidPIN(pinInput) {
res.FlagSet = append(res.FlagSet, flag_valid_pin)
} else {
res.FlagReset = append(res.FlagReset, flag_valid_pin)
}
} else { } else {
res.FlagReset = append(res.FlagReset, flag_valid_pin) res.FlagSet = append(res.FlagSet, flag_valid_pin)
} }
return res, nil return res, nil
@ -420,6 +424,11 @@ func (h *MenuHandlers) CheckBlockedNumPinMisMatch(ctx context.Context, sym strin
if !ok { if !ok {
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
if h.st.Back() {
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
return res, nil
}
// Get blocked number from storage. // Get blocked number from storage.
store := h.userdataStore store := h.userdataStore
blockedNumber, err := store.ReadEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER) blockedNumber, err := store.ReadEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER)
@ -450,6 +459,11 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [
} }
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch") flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
if h.st.Back() {
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
return res, nil
}
store := h.userdataStore store := h.userdataStore
hashedTemporaryPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) hashedTemporaryPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
if err != nil { if err != nil {
@ -581,6 +595,11 @@ func (h *MenuHandlers) ValidateBlockedNumber(ctx context.Context, sym string, in
if !ok { if !ok {
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
if h.st.Back() {
res.FlagReset = append(res.FlagReset, flag_unregistered_number)
return res, nil
}
blockedNumber := string(input) blockedNumber := string(input)
_, err = store.ReadEntry(ctx, blockedNumber, storedb.DATA_PUBLIC_KEY) _, err = store.ReadEntry(ctx, blockedNumber, storedb.DATA_PUBLIC_KEY)
if !phone.IsValidPhoneNumber(blockedNumber) { if !phone.IsValidPhoneNumber(blockedNumber) {
@ -1219,7 +1238,9 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
logg.ErrorCtxf(ctx, "failed to read AccountPin entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err) logg.ErrorCtxf(ctx, "failed to read AccountPin entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err)
return res, err return res, err
} }
if len(input) == 4 { str := string(input)
_, err = strconv.Atoi(str)
if len(input) == 4 && err == nil {
if pin.VerifyPIN(string(AccountPin), string(input)) { if pin.VerifyPIN(string(AccountPin), string(input)) {
if h.st.MatchFlag(flag_account_authorized, false) { if h.st.MatchFlag(flag_account_authorized, false) {
res.FlagReset = append(res.FlagReset, flag_incorrect_pin) res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
@ -1237,7 +1258,7 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
} }
} }
} else { } else {
err := h.incrementIncorrectPINAttempts(ctx, sessionId) err = h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil { if err != nil {
return res, err return res, err
} }
@ -1254,11 +1275,13 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
// Setback sets the flag_back_set flag when the navigation is back. // Setback sets the flag_back_set flag when the navigation is back.
func (h *MenuHandlers) SetBack(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *MenuHandlers) SetBack(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
//TODO: //TODO:
//Add check if the navigation is lateral nav instead of checking the input. //Add check if the navigation is lateral nav instead of checking the input.
if string(input) == "0" { if string(input) == "0" {
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
res.FlagSet = append(res.FlagSet, flag_back_set) res.FlagSet = append(res.FlagSet, flag_back_set)
} else {
res.FlagReset = append(res.FlagReset, flag_back_set)
} }
return res, nil return res, nil
} }