From 32ba22c0439f3be6a65ced29e48999ffd316b5b1 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 22 Aug 2024 15:01:30 +0300 Subject: [PATCH 1/4] added validation for amount --- services/registration/amount.vis | 1 + services/registration/amount_swa | 2 ++ services/registration/invalid_amount | 1 + services/registration/invalid_amount.vis | 7 +++++++ services/registration/invalid_amount_swa | 1 + services/registration/transaction_pin.vis | 1 + 6 files changed, 13 insertions(+) create mode 100644 services/registration/invalid_amount create mode 100644 services/registration/invalid_amount.vis create mode 100644 services/registration/invalid_amount_swa diff --git a/services/registration/amount.vis b/services/registration/amount.vis index ef1dd76..07bbbd9 100644 --- a/services/registration/amount.vis +++ b/services/registration/amount.vis @@ -1,3 +1,4 @@ +LOAD reset_transaction_amount 0 RELOAD validate_recipient CATCH invalid_recipient 13 1 LOAD max_amount 10 diff --git a/services/registration/amount_swa b/services/registration/amount_swa index e69de29..0c8cf01 100644 --- a/services/registration/amount_swa +++ b/services/registration/amount_swa @@ -0,0 +1,2 @@ +Kiwango cha juu: {{.max_amount}} +Weka kiwango: \ No newline at end of file diff --git a/services/registration/invalid_amount b/services/registration/invalid_amount new file mode 100644 index 0000000..c4bbe3f --- /dev/null +++ b/services/registration/invalid_amount @@ -0,0 +1 @@ +Amount {{.validate_amount}} is invalid, please try again: \ No newline at end of file diff --git a/services/registration/invalid_amount.vis b/services/registration/invalid_amount.vis new file mode 100644 index 0000000..833e81c --- /dev/null +++ b/services/registration/invalid_amount.vis @@ -0,0 +1,7 @@ +MAP validate_amount +RELOAD reset_transaction_amount +MOUT retry 1 +MOUT quit 9 +HALT +INCMP amount 1 +INCMP quit 9 diff --git a/services/registration/invalid_amount_swa b/services/registration/invalid_amount_swa new file mode 100644 index 0000000..836d7b2 --- /dev/null +++ b/services/registration/invalid_amount_swa @@ -0,0 +1 @@ +Kiwango {{.validate_amount}} sio sahihi, tafadhali weka tena: \ No newline at end of file diff --git a/services/registration/transaction_pin.vis b/services/registration/transaction_pin.vis index c63c2d8..983e4c6 100644 --- a/services/registration/transaction_pin.vis +++ b/services/registration/transaction_pin.vis @@ -1,5 +1,6 @@ RELOAD validate_amount MAP validate_amount +CATCH invalid_amount 17 1 RELOAD get_recipient MAP get_recipient RELOAD get_sender From 9aedc5d48f930e9ed388dbc95e63571524eb710f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 22 Aug 2024 15:44:28 +0300 Subject: [PATCH 2/4] added amount validation flag and logic --- cmd/main.go | 76 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 5944e71..186c0e4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -27,6 +27,8 @@ const ( USERFLAG_INVALID_RECIPIENT USERFLAG_INVALID_RECIPIENT_WITH_INVITE USERFLAG_INCORRECTPIN + USERFLAG_UNLOCKFORUPDATE + USERFLAG_INVALID_AMOUNT ) const ( @@ -385,6 +387,39 @@ func (fsd *fsData) transaction_reset(ctx context.Context, sym string, input []by return res, nil } +func (fsd *fsData) reset_transaction_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + fp := fsd.path + "_data" + + jsonData, err := os.ReadFile(fp) + if err != nil { + return res, err + } + + var accountData map[string]string + err = json.Unmarshal(jsonData, &accountData) + if err != nil { + return res, err + } + + // reset the amount + accountData["Amount"] = "" + + updatedJsonData, err := json.Marshal(accountData) + if err != nil { + return res, err + } + + err = os.WriteFile(fp, updatedJsonData, 0644) + if err != nil { + return res, err + } + + res.FlagReset = append(res.FlagReset, USERFLAG_INVALID_AMOUNT) + + return res, nil +} + func (fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) { res := resource.Result{} @@ -411,28 +446,32 @@ func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte return res, err } - // mimic invalid amount check - if amount == "0" { - // res.FlagSet = []uint32{invalidAmount} + if amount != "0" { + // mimic invalid amount + if amount == "00" { + res.FlagSet = append(res.FlagSet, USERFLAG_INVALID_AMOUNT) + res.Content = amount + + return res, nil + } + res.Content = amount + accountData["Amount"] = amount + + updatedJsonData, err := json.Marshal(accountData) + if err != nil { + return res, err + } + + err = os.WriteFile(fp, updatedJsonData, 0644) + if err != nil { + return res, err + } + return res, nil } - res.Content = amount - - accountData["Amount"] = amount - - updatedJsonData, err := json.Marshal(accountData) - if err != nil { - return res, err - } - - err = os.WriteFile(fp, updatedJsonData, 0644) - if err != nil { - return res, err - } - return res, nil } @@ -529,7 +568,7 @@ func main() { fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir) ctx := context.Background() - st := state.NewState(9) + st := state.NewState(15) st.UseDebug() state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE") state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED") @@ -582,6 +621,7 @@ func main() { rfs.AddLocalFunc("transaction_reset", fs.transaction_reset) rfs.AddLocalFunc("max_amount", fs.max_amount) rfs.AddLocalFunc("validate_amount", fs.validate_amount) + rfs.AddLocalFunc("reset_transaction_amount", fs.reset_transaction_amount) rfs.AddLocalFunc("get_recipient", fs.get_recipient) rfs.AddLocalFunc("get_sender", fs.get_sender) rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin) From f50be01b8949b4a0814c75f868b74115bbe59fc4 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 22 Aug 2024 19:48:34 +0300 Subject: [PATCH 3/4] create a PIN during registration --- cmd/main.go | 62 +++++++++++++++++++ services/registration/account_creation.vis | 4 +- services/registration/confirm_create_pin | 1 + services/registration/confirm_create_pin.vis | 4 ++ services/registration/confirm_create_pin_swa | 1 + services/registration/create_pin | 1 + services/registration/create_pin.vis | 5 ++ services/registration/create_pin_mismatch | 1 + services/registration/create_pin_mismatch.vis | 5 ++ services/registration/create_pin_mismatch_swa | 1 + services/registration/create_pin_swa | 1 + services/registration/exit_menu | 1 + services/registration/exit_menu_swa | 1 + services/registration/terms.vis | 2 +- 14 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 services/registration/confirm_create_pin create mode 100644 services/registration/confirm_create_pin.vis create mode 100644 services/registration/confirm_create_pin_swa create mode 100644 services/registration/create_pin create mode 100644 services/registration/create_pin.vis create mode 100644 services/registration/create_pin_mismatch create mode 100644 services/registration/create_pin_mismatch.vis create mode 100644 services/registration/create_pin_mismatch_swa create mode 100644 services/registration/create_pin_swa create mode 100644 services/registration/exit_menu create mode 100644 services/registration/exit_menu_swa diff --git a/cmd/main.go b/cmd/main.go index 186c0e4..694eebb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "context" "encoding/json" "flag" @@ -29,6 +30,9 @@ const ( USERFLAG_INCORRECTPIN USERFLAG_UNLOCKFORUPDATE USERFLAG_INVALID_AMOUNT + USERFLAG_QUERYPIN + USERFLAG_VALIDPIN + USERFLAG_INVALIDPIN ) const ( @@ -551,6 +555,62 @@ func (fsd *fsData) quitWithBalance(ctx context.Context, sym string, input []byte return res, nil } +func (fsd *fsData) save_pin(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + accountPIN := string(input) + fp := fsd.path + "_data" + + jsonData, err := os.ReadFile(fp) + if err != nil { + return res, err + } + + var accountData map[string]string + err = json.Unmarshal(jsonData, &accountData) + if err != nil { + return res, err + } + + accountData["AccountPIN"] = accountPIN + + updatedJsonData, err := json.Marshal(accountData) + if err != nil { + return res, err + } + + err = os.WriteFile(fp, updatedJsonData, 0644) + if err != nil { + return res, err + } + + return res, nil +} + +func (fsd *fsData) verify_pin(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + fp := fsd.path + "_data" + + jsonData, err := os.ReadFile(fp) + if err != nil { + return res, err + } + + var accountData map[string]string + err = json.Unmarshal(jsonData, &accountData) + if err != nil { + return res, err + } + + if bytes.Equal(input, []byte(accountData["AccountPIN"])) { + res.FlagSet = []uint32{USERFLAG_VALIDPIN} + res.FlagReset = []uint32{USERFLAG_INVALIDPIN} + } else { + res.FlagSet = []uint32{USERFLAG_INVALIDPIN} + } + + return res, nil +} + var ( scriptDir = path.Join("services", "registration") ) @@ -612,6 +672,8 @@ func main() { } rfs.AddLocalFunc("select_language", fs.SetLanguageSelected) rfs.AddLocalFunc("create_account", fs.create_account) + rfs.AddLocalFunc("save_pin", fs.save_pin) + rfs.AddLocalFunc("verify_pin", fs.verify_pin) rfs.AddLocalFunc("check_identifier", fs.checkIdentifier) rfs.AddLocalFunc("check_account_status", fs.check_account_status) rfs.AddLocalFunc("unlock_account", fs.unLock) diff --git a/services/registration/account_creation.vis b/services/registration/account_creation.vis index b810e1a..e3ecebb 100644 --- a/services/registration/account_creation.vis +++ b/services/registration/account_creation.vis @@ -1,4 +1,4 @@ -LOAD create_account 0 +RELOAD verify_pin +CATCH create_pin_mismatch 20 1 LOAD quit 0 HALT - diff --git a/services/registration/confirm_create_pin b/services/registration/confirm_create_pin new file mode 100644 index 0000000..e4632ad --- /dev/null +++ b/services/registration/confirm_create_pin @@ -0,0 +1 @@ +Enter your four number PIN again: \ No newline at end of file diff --git a/services/registration/confirm_create_pin.vis b/services/registration/confirm_create_pin.vis new file mode 100644 index 0000000..1235916 --- /dev/null +++ b/services/registration/confirm_create_pin.vis @@ -0,0 +1,4 @@ +LOAD save_pin 0 +HALT +LOAD verify_pin 8 +INCMP account_creation * diff --git a/services/registration/confirm_create_pin_swa b/services/registration/confirm_create_pin_swa new file mode 100644 index 0000000..f697854 --- /dev/null +++ b/services/registration/confirm_create_pin_swa @@ -0,0 +1 @@ +Weka PIN yako tena: \ No newline at end of file diff --git a/services/registration/create_pin b/services/registration/create_pin new file mode 100644 index 0000000..f8836f5 --- /dev/null +++ b/services/registration/create_pin @@ -0,0 +1 @@ +Please enter a new four number PIN for your account: \ No newline at end of file diff --git a/services/registration/create_pin.vis b/services/registration/create_pin.vis new file mode 100644 index 0000000..852bf47 --- /dev/null +++ b/services/registration/create_pin.vis @@ -0,0 +1,5 @@ +LOAD create_account 0 +MOUT exit 0 +HALT +LOAD save_pin 0 +INCMP confirm_create_pin * diff --git a/services/registration/create_pin_mismatch b/services/registration/create_pin_mismatch new file mode 100644 index 0000000..e75068c --- /dev/null +++ b/services/registration/create_pin_mismatch @@ -0,0 +1 @@ +The PIN is not a match. Try again \ No newline at end of file diff --git a/services/registration/create_pin_mismatch.vis b/services/registration/create_pin_mismatch.vis new file mode 100644 index 0000000..91793b5 --- /dev/null +++ b/services/registration/create_pin_mismatch.vis @@ -0,0 +1,5 @@ +MOUT retry 1 +MOUT quit 9 +HALT +INCMP confirm_create_pin 1 +INCMP quit 9 diff --git a/services/registration/create_pin_mismatch_swa b/services/registration/create_pin_mismatch_swa new file mode 100644 index 0000000..a1d7b6d --- /dev/null +++ b/services/registration/create_pin_mismatch_swa @@ -0,0 +1 @@ +PIN uliyoweka haifanani. Jaribu tena \ No newline at end of file diff --git a/services/registration/create_pin_swa b/services/registration/create_pin_swa new file mode 100644 index 0000000..1fdd972 --- /dev/null +++ b/services/registration/create_pin_swa @@ -0,0 +1 @@ +Tafadhali weka PIN mpya yenye nambari nne kwa akaunti yako: \ No newline at end of file diff --git a/services/registration/exit_menu b/services/registration/exit_menu new file mode 100644 index 0000000..1105a55 --- /dev/null +++ b/services/registration/exit_menu @@ -0,0 +1 @@ +Exit \ No newline at end of file diff --git a/services/registration/exit_menu_swa b/services/registration/exit_menu_swa new file mode 100644 index 0000000..474f1ff --- /dev/null +++ b/services/registration/exit_menu_swa @@ -0,0 +1 @@ +Ondoka \ No newline at end of file diff --git a/services/registration/terms.vis b/services/registration/terms.vis index 5375925..768efa3 100644 --- a/services/registration/terms.vis +++ b/services/registration/terms.vis @@ -3,5 +3,5 @@ RELOAD select_language MOUT yes 0 MOUT no 1 HALT -INCMP account_creation 0 +INCMP create_pin 0 INCMP _ * From 9cc75185b3fcdf99f626d7d1f79dff0a4e076e69 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 23 Aug 2024 01:05:14 +0300 Subject: [PATCH 4/4] creuse a universal quit message --- cmd/main.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 694eebb..17eb906 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,6 +14,7 @@ import ( "git.defalsify.org/vise.git/cache" "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/lang" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/state" @@ -76,6 +77,16 @@ type fsData struct { st *state.State } +func codeFromCtx(ctx context.Context) string { + var code string + engine.Logg.DebugCtxf(ctx, "in msg", "ctx", ctx, "val", code) + if ctx.Value("Language") != nil { + lang := ctx.Value("Language").(lang.Language) + code = lang.Code + } + return code +} + func (fsd *fsData) SetLanguageSelected(ctx context.Context, sym string, input []byte) (resource.Result, error) { inputStr := string(input) res := resource.Result{} @@ -269,8 +280,12 @@ func checkAccountStatus(trackingId string) (string, error) { } func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resource.Result, error) { - res := resource.Result{ - Content: "Your account is being created", + res := resource.Result{} + switch codeFromCtx(ctx) { + case "swa": + res.Content = "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" + default: + res.Content = "Thank you for using Sarafu. Goodbye!" } res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED) return res, nil