diff --git a/.gitignore b/.gitignore index 54ad3ff..ddccccf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ go.work* **/*/*.bin **/*/.state/ cmd/.state/ +id_* +*.gdbm diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index b733efe..3dffe16 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -88,7 +88,6 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo) ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob) ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) - ls.DbRs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index e998bd5..5ebdaa5 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -117,17 +117,14 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result - sym, _ = h.st.Where() + symbol, _ := h.st.Where() + code := strings.Split(symbol, "_")[1] - switch sym { - case "set_default": - res.FlagSet = append(res.FlagSet, state.FLAG_LANG) - res.Content = "eng" - case "set_swa": - res.FlagSet = append(res.FlagSet, state.FLAG_LANG) - res.Content = "swa" - default: + if !utils.IsValidISO639(code) { + return res, nil } + res.FlagSet = append(res.FlagSet, state.FLAG_LANG) + res.Content = code languageSetFlag, err := h.flagManager.GetFlag("flag_language_set") if err != nil { @@ -316,32 +313,6 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt return res, nil } -// SetResetSingleEdit sets and resets flags to allow gradual editing of profile information. -func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) { - var res resource.Result - - menuOption := string(input) - - flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") - flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit") - - switch menuOption { - case "2": - res.FlagReset = append(res.FlagReset, flag_allow_update) - res.FlagSet = append(res.FlagSet, flag_single_edit) - case "3": - res.FlagReset = append(res.FlagReset, flag_allow_update) - res.FlagSet = append(res.FlagSet, flag_single_edit) - case "4": - res.FlagReset = append(res.FlagReset, flag_allow_update) - res.FlagSet = append(res.FlagSet, flag_single_edit) - default: - res.FlagReset = append(res.FlagReset, flag_single_edit) - } - - return res, nil -} - // VerifyPin checks whether the confirmation PIN is similar to the account PIN // If similar, it sets the USERFLAG_PIN_SET flag allowing the user // to access the main menu @@ -472,6 +443,7 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) ( // SaveGender updates the gender in the gdbm with the provided input. func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (resource.Result, error) { + symbol, _ := h.st.Where() var res resource.Result var err error sessionId, ok := ctx.Value("SessionId").(string) @@ -479,21 +451,11 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re return res, fmt.Errorf("missing session") } - if len(input) > 0 { - gender := string(input) - switch gender { - case "1": - gender = "Male" - case "2": - gender = "Female" - case "3": - gender = "Unspecified" - } - store := h.userdataStore - err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender)) - if err != nil { - return res, nil - } + gender := strings.Split(symbol, "_")[1] + store := h.userdataStore + err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender)) + if err != nil { + return res, nil } return res, nil diff --git a/internal/utils/isocode.go b/internal/utils/isocode.go new file mode 100644 index 0000000..3bdfbeb --- /dev/null +++ b/internal/utils/isocode.go @@ -0,0 +1,11 @@ +package utils + +var isoCodes = map[string]bool{ + "eng": true, // English + "swa": true, // Swahili + +} + +func IsValidISO639(code string) bool { + return isoCodes[code] +} diff --git a/services/registration/_catch b/services/registration/_catch new file mode 100644 index 0000000..e81b8e9 --- /dev/null +++ b/services/registration/_catch @@ -0,0 +1 @@ +Something went wrong.Please try again \ No newline at end of file diff --git a/services/registration/_catch.vis b/services/registration/_catch.vis new file mode 100644 index 0000000..72e55ad --- /dev/null +++ b/services/registration/_catch.vis @@ -0,0 +1 @@ +HALT diff --git a/services/registration/edit_profile.vis b/services/registration/edit_profile.vis index 6c1986f..9d45ec9 100644 --- a/services/registration/edit_profile.vis +++ b/services/registration/edit_profile.vis @@ -11,8 +11,6 @@ MOUT view 7 MOUT back 0 HALT INCMP my_account 0 -LOAD set_reset_single_edit 0 -RELOAD set_reset_single_edit INCMP enter_name 1 INCMP enter_familyname 2 INCMP select_gender 3 diff --git a/services/registration/select_gender.vis b/services/registration/select_gender.vis index 25e53d3..1082cef 100644 --- a/services/registration/select_gender.vis +++ b/services/registration/select_gender.vis @@ -1,13 +1,15 @@ CATCH incorrect_pin flag_incorrect_pin 1 CATCH profile_update_success flag_allow_update 1 -LOAD save_gender 0 MOUT male 1 MOUT female 2 MOUT unspecified 3 MOUT back 0 HALT -RELOAD save_gender INCMP _ 0 -INCMP pin_entry * +INCMP set_male 1 +INCMP set_female 2 +INCMP set_unspecified 3 + + diff --git a/services/registration/select_language.vis b/services/registration/select_language.vis index aa83e0c..54f08e9 100644 --- a/services/registration/select_language.vis +++ b/services/registration/select_language.vis @@ -1,6 +1,6 @@ MOUT english 0 MOUT kiswahili 1 HALT -INCMP set_default 0 +INCMP set_eng 0 INCMP set_swa 1 INCMP . * diff --git a/services/registration/set_default.vis b/services/registration/set_eng.vis similarity index 100% rename from services/registration/set_default.vis rename to services/registration/set_eng.vis diff --git a/services/registration/set_female.vis b/services/registration/set_female.vis new file mode 100644 index 0000000..723b080 --- /dev/null +++ b/services/registration/set_female.vis @@ -0,0 +1,4 @@ +LOAD save_gender 0 +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH profile_update_success flag_allow_update 1 +MOVE pin_entry diff --git a/services/registration/set_male.vis b/services/registration/set_male.vis new file mode 100644 index 0000000..723b080 --- /dev/null +++ b/services/registration/set_male.vis @@ -0,0 +1,4 @@ +LOAD save_gender 0 +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH profile_update_success flag_allow_update 1 +MOVE pin_entry diff --git a/services/registration/set_unspecified.vis b/services/registration/set_unspecified.vis new file mode 100644 index 0000000..723b080 --- /dev/null +++ b/services/registration/set_unspecified.vis @@ -0,0 +1,4 @@ +LOAD save_gender 0 +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH profile_update_success flag_allow_update 1 +MOVE pin_entry