wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
2 changed files with 30 additions and 16 deletions
Showing only changes of commit 54d777de04 - Show all commits

View File

@ -59,6 +59,24 @@ func NewHandlers(path string, st *state.State) *Handlers {
} }
} }
// Define the regex pattern as a constant
const pinPattern = `^\d{4}$`
// isValidPIN checks whether the given input is a 4 digit number
func isValidPIN(pin string) bool {
match, _ := regexp.MatchString(pinPattern, pin)
return match
}
// Define the regex pattern as a constant
const pinPattern = `^\d{4}$`
// isValidPIN checks whether the given input is a 4 digit number
func isValidPIN(pin string) bool {
match, _ := regexp.MatchString(pinPattern, pin)
return match
}
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

should not be necessary to set the flag when it already has been set and persisted. That will reduce one file access call each run.

should not be necessary to set the flag when it already has been set and persisted. That will reduce one file access call each run.
// SetLanguage sets the language across the menu // SetLanguage sets the language across the menu
func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
inputStr := string(input) inputStr := string(input)
@ -89,10 +107,9 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
return res, err return res, err
} }
// if an account exists, set the flag and return // if an account exists, return to prevent duplicate account creation
existingAccountData, err := h.accountFileHandler.ReadAccountData() existingAccountData, err := h.accountFileHandler.ReadAccountData()
if existingAccountData != nil { if existingAccountData != nil {
res.FlagSet = append(res.FlagSet, models.USERFLAG_ACCOUNT_CREATED)
return res, err return res, err
} }
@ -193,13 +210,7 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res
return res, nil return res, nil
} }
// isValidPIN checks whether the given input is a 4 digit number //codeFromCtx retrieves language codes from the context that can be used for handling translations
func isValidPIN(pin string) bool {
match, _ := regexp.MatchString(`^\d{4}$`, pin)
return match
}
// codeFromCtx retrieves language codes from the context that can be used for handling translations
func codeFromCtx(ctx context.Context) string { func codeFromCtx(ctx context.Context) string {
var code string var code string
engine.Logg.DebugCtxf(ctx, "in msg", "ctx", ctx, "val", code) engine.Logg.DebugCtxf(ctx, "in msg", "ctx", ctx, "val", code)
@ -450,13 +461,13 @@ func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []b
// Quit displays the Thank you message and exits the menu // Quit displays the Thank you message and exits the menu
func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
switch codeFromCtx(ctx) {
case "swa": code := codeFromCtx(ctx)
res.Content = "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" l := gotext.NewLocale(translationDir, code)
default: l.AddDomain("default")
res.Content = "Thank you for using Sarafu. Goodbye!"
} res.Content = l.Get("Thank you for using Sarafu. Goodbye!")
res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_AUTHORIZED) res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED)
return res, nil return res, nil
} }

View File

@ -3,3 +3,6 @@ msgstr "Salio lako ni %s"
msgid "Your request has been sent. %s will receive %s from %s." msgid "Your request has been sent. %s will receive %s from %s."
msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s." msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
msgid "Thank you for using Sarafu. Goodbye!"
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"