Compare commits
3 Commits
075355980a
...
f50be01b89
Author | SHA1 | Date | |
---|---|---|---|
f50be01b89 | |||
9aedc5d48f | |||
32ba22c043 |
110
cmd/main.go
110
cmd/main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
@ -27,6 +28,11 @@ const (
|
|||||||
USERFLAG_INVALID_RECIPIENT
|
USERFLAG_INVALID_RECIPIENT
|
||||||
USERFLAG_INVALID_RECIPIENT_WITH_INVITE
|
USERFLAG_INVALID_RECIPIENT_WITH_INVITE
|
||||||
USERFLAG_INCORRECTPIN
|
USERFLAG_INCORRECTPIN
|
||||||
|
USERFLAG_UNLOCKFORUPDATE
|
||||||
|
USERFLAG_INVALID_AMOUNT
|
||||||
|
USERFLAG_QUERYPIN
|
||||||
|
USERFLAG_VALIDPIN
|
||||||
|
USERFLAG_INVALIDPIN
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -385,6 +391,39 @@ func (fsd *fsData) transaction_reset(ctx context.Context, sym string, input []by
|
|||||||
return res, nil
|
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) {
|
func (fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
res := resource.Result{}
|
res := resource.Result{}
|
||||||
|
|
||||||
@ -411,9 +450,10 @@ func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// mimic invalid amount check
|
if amount != "0" {
|
||||||
if amount == "0" {
|
// mimic invalid amount
|
||||||
// res.FlagSet = []uint32{invalidAmount}
|
if amount == "00" {
|
||||||
|
res.FlagSet = append(res.FlagSet, USERFLAG_INVALID_AMOUNT)
|
||||||
res.Content = amount
|
res.Content = amount
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
@ -436,6 +476,9 @@ func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
res := resource.Result{}
|
res := resource.Result{}
|
||||||
fp := fsd.path + "_data"
|
fp := fsd.path + "_data"
|
||||||
@ -512,6 +555,62 @@ func (fsd *fsData) quitWithBalance(ctx context.Context, sym string, input []byte
|
|||||||
return res, nil
|
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 (
|
var (
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
)
|
)
|
||||||
@ -529,7 +628,7 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
|
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
st := state.NewState(9)
|
st := state.NewState(15)
|
||||||
st.UseDebug()
|
st.UseDebug()
|
||||||
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
|
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
|
||||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED")
|
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED")
|
||||||
@ -573,6 +672,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
rfs.AddLocalFunc("select_language", fs.SetLanguageSelected)
|
rfs.AddLocalFunc("select_language", fs.SetLanguageSelected)
|
||||||
rfs.AddLocalFunc("create_account", fs.create_account)
|
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_identifier", fs.checkIdentifier)
|
||||||
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
||||||
rfs.AddLocalFunc("unlock_account", fs.unLock)
|
rfs.AddLocalFunc("unlock_account", fs.unLock)
|
||||||
@ -582,6 +683,7 @@ func main() {
|
|||||||
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
|
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
|
||||||
rfs.AddLocalFunc("max_amount", fs.max_amount)
|
rfs.AddLocalFunc("max_amount", fs.max_amount)
|
||||||
rfs.AddLocalFunc("validate_amount", fs.validate_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_recipient", fs.get_recipient)
|
||||||
rfs.AddLocalFunc("get_sender", fs.get_sender)
|
rfs.AddLocalFunc("get_sender", fs.get_sender)
|
||||||
rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin)
|
rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
LOAD create_account 0
|
RELOAD verify_pin
|
||||||
|
CATCH create_pin_mismatch 20 1
|
||||||
LOAD quit 0
|
LOAD quit 0
|
||||||
HALT
|
HALT
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
LOAD reset_transaction_amount 0
|
||||||
RELOAD validate_recipient
|
RELOAD validate_recipient
|
||||||
CATCH invalid_recipient 13 1
|
CATCH invalid_recipient 13 1
|
||||||
LOAD max_amount 10
|
LOAD max_amount 10
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
Kiwango cha juu: {{.max_amount}}
|
||||||
|
Weka kiwango:
|
1
services/registration/confirm_create_pin
Normal file
1
services/registration/confirm_create_pin
Normal file
@ -0,0 +1 @@
|
|||||||
|
Enter your four number PIN again:
|
4
services/registration/confirm_create_pin.vis
Normal file
4
services/registration/confirm_create_pin.vis
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
LOAD save_pin 0
|
||||||
|
HALT
|
||||||
|
LOAD verify_pin 8
|
||||||
|
INCMP account_creation *
|
1
services/registration/confirm_create_pin_swa
Normal file
1
services/registration/confirm_create_pin_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Weka PIN yako tena:
|
1
services/registration/create_pin
Normal file
1
services/registration/create_pin
Normal file
@ -0,0 +1 @@
|
|||||||
|
Please enter a new four number PIN for your account:
|
5
services/registration/create_pin.vis
Normal file
5
services/registration/create_pin.vis
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
LOAD create_account 0
|
||||||
|
MOUT exit 0
|
||||||
|
HALT
|
||||||
|
LOAD save_pin 0
|
||||||
|
INCMP confirm_create_pin *
|
1
services/registration/create_pin_mismatch
Normal file
1
services/registration/create_pin_mismatch
Normal file
@ -0,0 +1 @@
|
|||||||
|
The PIN is not a match. Try again
|
5
services/registration/create_pin_mismatch.vis
Normal file
5
services/registration/create_pin_mismatch.vis
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MOUT retry 1
|
||||||
|
MOUT quit 9
|
||||||
|
HALT
|
||||||
|
INCMP confirm_create_pin 1
|
||||||
|
INCMP quit 9
|
1
services/registration/create_pin_mismatch_swa
Normal file
1
services/registration/create_pin_mismatch_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
PIN uliyoweka haifanani. Jaribu tena
|
1
services/registration/create_pin_swa
Normal file
1
services/registration/create_pin_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Tafadhali weka PIN mpya yenye nambari nne kwa akaunti yako:
|
1
services/registration/exit_menu
Normal file
1
services/registration/exit_menu
Normal file
@ -0,0 +1 @@
|
|||||||
|
Exit
|
1
services/registration/exit_menu_swa
Normal file
1
services/registration/exit_menu_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Ondoka
|
1
services/registration/invalid_amount
Normal file
1
services/registration/invalid_amount
Normal file
@ -0,0 +1 @@
|
|||||||
|
Amount {{.validate_amount}} is invalid, please try again:
|
7
services/registration/invalid_amount.vis
Normal file
7
services/registration/invalid_amount.vis
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
MAP validate_amount
|
||||||
|
RELOAD reset_transaction_amount
|
||||||
|
MOUT retry 1
|
||||||
|
MOUT quit 9
|
||||||
|
HALT
|
||||||
|
INCMP amount 1
|
||||||
|
INCMP quit 9
|
1
services/registration/invalid_amount_swa
Normal file
1
services/registration/invalid_amount_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Kiwango {{.validate_amount}} sio sahihi, tafadhali weka tena:
|
@ -3,5 +3,5 @@ RELOAD select_language
|
|||||||
MOUT yes 0
|
MOUT yes 0
|
||||||
MOUT no 1
|
MOUT no 1
|
||||||
HALT
|
HALT
|
||||||
INCMP account_creation 0
|
INCMP create_pin 0
|
||||||
INCMP _ *
|
INCMP _ *
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
RELOAD validate_amount
|
RELOAD validate_amount
|
||||||
MAP validate_amount
|
MAP validate_amount
|
||||||
|
CATCH invalid_amount 17 1
|
||||||
RELOAD get_recipient
|
RELOAD get_recipient
|
||||||
MAP get_recipient
|
MAP get_recipient
|
||||||
RELOAD get_sender
|
RELOAD get_sender
|
||||||
|
Loading…
Reference in New Issue
Block a user