Compare commits
15 Commits
2c5eaf9db3
...
2ed9f083bb
Author | SHA1 | Date | |
---|---|---|---|
2ed9f083bb | |||
e323ffa078 | |||
68de83af97 | |||
a3f2b23128 | |||
09f970db9b | |||
04edd90c21 | |||
a3f410875a | |||
3f3e98e637 | |||
660f8b7aa2 | |||
|
8ae3372c36 | ||
3a7c3ffc67 | |||
78c033e61c | |||
b5ef483f34 | |||
006eef0a28 | |||
e99a788c60 |
@ -71,6 +71,9 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
|
||||
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
||||
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
||||
|
||||
return ussdHandlers, nil
|
||||
|
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.22.6
|
||||
require (
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f
|
||||
github.com/alecthomas/assert/v2 v2.2.2
|
||||
github.com/peteole/testdata-loader v0.3.0
|
||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
||||
)
|
||||
|
||||
|
@ -74,9 +74,9 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, erro
|
||||
Db: userdataStore,
|
||||
}
|
||||
h := &Handlers{
|
||||
userdataStore: userDb,
|
||||
flagManager: appFlags,
|
||||
accountService: &server.AccountService{},
|
||||
userdataStore: userDb,
|
||||
flagManager: appFlags,
|
||||
accountService: &server.AccountService{},
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
@ -216,6 +216,74 @@ func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resou
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *Handlers) VerifyNewPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
_, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin")
|
||||
pinInput := string(input)
|
||||
// Validate that the PIN is a 4-digit number
|
||||
if isValidPIN(pinInput) {
|
||||
res.FlagSet = append(res.FlagSet, flag_valid_pin)
|
||||
} else {
|
||||
res.FlagReset = append(res.FlagReset, flag_valid_pin)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
||||
|
||||
accountPIN := string(input)
|
||||
|
||||
// Validate that the PIN is a 4-digit number
|
||||
if !isValidPIN(accountPIN) {
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||
return res, nil
|
||||
}
|
||||
store := h.userdataStore
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
|
||||
|
||||
store := h.userdataStore
|
||||
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if bytes.Equal(temporaryPin, input) {
|
||||
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_pin_mismatch)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(temporaryPin))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
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
|
||||
@ -322,9 +390,6 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
} else {
|
||||
return res, fmt.Errorf("a family name cannot be less than one character")
|
||||
}
|
||||
@ -481,27 +546,23 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if len(input) == 4 {
|
||||
if bytes.Equal(input, AccountPin) {
|
||||
if h.st.MatchFlag(flag_account_authorized, false) {
|
||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
||||
res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized)
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_allow_update)
|
||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||
}
|
||||
if len(input) == 4 {
|
||||
if bytes.Equal(input, AccountPin) {
|
||||
if h.st.MatchFlag(flag_account_authorized, false) {
|
||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
||||
res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized)
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||
res.FlagSet = append(res.FlagSet, flag_allow_update)
|
||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||
return res, nil
|
||||
}
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||
return res, nil
|
||||
}
|
||||
} else {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -764,7 +825,8 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
|
||||
|
||||
flag_invalid_amount, _ := h.flagManager.GetFlag("flag_invalid_amount")
|
||||
|
||||
publicKey, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_PUBLIC_KEY)
|
||||
store := h.userdataStore
|
||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||
|
||||
amountStr := string(input)
|
||||
|
||||
@ -808,7 +870,6 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
|
||||
}
|
||||
|
||||
res.Content = fmt.Sprintf("%.3f", inputAmount) // Format to 3 decimal places
|
||||
store := h.userdataStore
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_AMOUNT, []byte(amountStr))
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
)
|
||||
|
||||
type DataTyp uint16
|
||||
@ -25,6 +22,7 @@ const (
|
||||
DATA_OFFERINGS
|
||||
DATA_RECIPIENT
|
||||
DATA_AMOUNT
|
||||
DATA_TEMPORARY_PIN
|
||||
)
|
||||
|
||||
func typToBytes(typ DataTyp) []byte {
|
||||
@ -37,21 +35,3 @@ func PackKey(typ DataTyp, data []byte) []byte {
|
||||
v := typToBytes(typ)
|
||||
return append(v, data...)
|
||||
}
|
||||
|
||||
func ReadEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp) ([]byte, error) {
|
||||
store.SetPrefix(db.DATATYPE_USERDATA)
|
||||
store.SetSession(sessionId)
|
||||
k := PackKey(typ, []byte(sessionId))
|
||||
b, err := store.Get(ctx, k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func WriteEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp, value []byte) error {
|
||||
store.SetPrefix(db.DATATYPE_USERDATA)
|
||||
store.SetSession(sessionId)
|
||||
k := PackKey(typ, []byte(sessionId))
|
||||
return store.Put(ctx, k, value)
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
# Variables to match files in the current directory
|
||||
INPUTS = $(wildcard ./*.vis)
|
||||
TXTS = $(wildcard ./*.txt.orig)
|
||||
VISE_PATH := ../../go-vise
|
||||
|
||||
# Rule to build .bin files from .vis files
|
||||
%.vis:
|
||||
go run ../../go-vise/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
go run $(VISE_PATH)/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
@echo "Built $(basename $@).bin from $(basename $@).vis"
|
||||
|
||||
# Rule to copy .orig files to .txt
|
||||
|
1
services/registration/confirm_pin_change
Normal file
1
services/registration/confirm_pin_change
Normal file
@ -0,0 +1 @@
|
||||
Confirm your new PIN:
|
7
services/registration/confirm_pin_change.vis
Normal file
7
services/registration/confirm_pin_change.vis
Normal file
@ -0,0 +1,7 @@
|
||||
CATCH invalid_pin flag_valid_pin 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
INCMP * pin_reset_success
|
||||
|
||||
|
1
services/registration/confirm_pin_change_swa
Normal file
1
services/registration/confirm_pin_change_swa
Normal file
@ -0,0 +1 @@
|
||||
Thibitisha PIN yako mpya:
|
1
services/registration/invalid_pin
Normal file
1
services/registration/invalid_pin
Normal file
@ -0,0 +1 @@
|
||||
The PIN you entered is invalid.The PIN must be different from your current PIN.For help call +254757628885
|
3
services/registration/invalid_pin.vis
Normal file
3
services/registration/invalid_pin.vis
Normal file
@ -0,0 +1,3 @@
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
1
services/registration/invalid_pin_swa
Normal file
1
services/registration/invalid_pin_swa
Normal file
@ -0,0 +1 @@
|
||||
PIN mpya na udhibitisho wa pin mpya hazilingani.Tafadhali jaribu tena.Kwa usaidizi piga simu +254757628885.
|
1
services/registration/new_pin
Normal file
1
services/registration/new_pin
Normal file
@ -0,0 +1 @@
|
||||
Enter a new four number pin
|
13
services/registration/new_pin.vis
Normal file
13
services/registration/new_pin.vis
Normal file
@ -0,0 +1,13 @@
|
||||
LOAD authorize_account 12
|
||||
RELOAD authorize_account
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
CATCH old_pin flag_allow_update 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
LOAD save_temporary_pin 6
|
||||
LOAD verify_new_pin 0
|
||||
RELOAD save_temporary_pin
|
||||
RELOAD verify_new_pin
|
||||
INCMP * confirm_pin_change
|
||||
|
2
services/registration/new_pin_swa
Normal file
2
services/registration/new_pin_swa
Normal file
@ -0,0 +1,2 @@
|
||||
Weka PIN mpya ya nne nambari:
|
||||
|
1
services/registration/old_pin
Normal file
1
services/registration/old_pin
Normal file
@ -0,0 +1 @@
|
||||
Enter your old PIN
|
7
services/registration/old_pin.vis
Normal file
7
services/registration/old_pin.vis
Normal file
@ -0,0 +1,7 @@
|
||||
LOAD reset_allow_update 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
RELOAD reset_allow_update
|
||||
INCMP _ 0
|
||||
INCMP new_pin *
|
||||
|
1
services/registration/old_pin_swa
Normal file
1
services/registration/old_pin_swa
Normal file
@ -0,0 +1 @@
|
||||
Weka PIN yako ya zamani:
|
@ -4,3 +4,5 @@ MOUT guard_pin 3
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
INCMP old_pin 1
|
||||
|
||||
|
1
services/registration/pin_reset_mismatch
Normal file
1
services/registration/pin_reset_mismatch
Normal file
@ -0,0 +1 @@
|
||||
The PIN is not a match. Try again
|
6
services/registration/pin_reset_mismatch.vis
Normal file
6
services/registration/pin_reset_mismatch.vis
Normal file
@ -0,0 +1,6 @@
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP confirm_pin_change 1
|
||||
INCMP quit 9
|
||||
|
1
services/registration/pin_reset_success
Normal file
1
services/registration/pin_reset_success
Normal file
@ -0,0 +1 @@
|
||||
Your PIN change request has been successful
|
10
services/registration/pin_reset_success.vis
Normal file
10
services/registration/pin_reset_success.vis
Normal file
@ -0,0 +1,10 @@
|
||||
LOAD confirm_pin_change 0
|
||||
RELOAD confirm_pin_change
|
||||
CATCH pin_reset_mismatch flag_pin_mismatch 1
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP main 0
|
||||
INCMP quit 9
|
||||
|
||||
|
1
services/registration/pin_reset_success_swa
Normal file
1
services/registration/pin_reset_success_swa
Normal file
@ -0,0 +1 @@
|
||||
Ombi lako la kubadili PIN limefanikiwa
|
Loading…
Reference in New Issue
Block a user