Compare commits
5 Commits
master
...
data-migra
Author | SHA1 | Date | |
---|---|---|---|
cf27479fcf | |||
799d1a51fa | |||
1376c7b8dd | |||
b70d6b54d1 | |||
46544b723b |
@ -22,8 +22,9 @@ import (
|
|||||||
|
|
||||||
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
|
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||||
|
|
||||||
|
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -120,8 +121,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountService := services.New(ctx, menuStorageService, connData)
|
accountService := &httpremote.HTTPAccountService{}
|
||||||
|
|
||||||
hl, err := lhs.GetHandler(accountService)
|
hl, err := lhs.GetHandler(accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err)
|
fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err)
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||||
)
|
)
|
||||||
@ -125,8 +125,7 @@ func main() {
|
|||||||
|
|
||||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||||
lhs.SetDataStore(&userdataStore)
|
lhs.SetDataStore(&userdataStore)
|
||||||
|
accountService := &httpremote.HTTPAccountService{}
|
||||||
accountService := services.New(ctx, menuStorageService, connData)
|
|
||||||
|
|
||||||
hl, err := lhs.GetHandler(accountService)
|
hl, err := lhs.GetHandler(accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||||
)
|
)
|
||||||
@ -116,8 +116,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountService := services.New(ctx, menuStorageService, connData)
|
accountService := &httpremote.HTTPAccountService{}
|
||||||
|
|
||||||
hl, err := lhs.GetHandler(accountService)
|
hl, err := lhs.GetHandler(accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
@ -131,8 +130,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer stateStore.Close()
|
defer stateStore.Close()
|
||||||
|
|
||||||
//accountService := services.New(ctx, menuStorageService, connData)
|
|
||||||
|
|
||||||
rp := &httprequest.DefaultRequestParser{}
|
rp := &httprequest.DefaultRequestParser{}
|
||||||
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||||
sh := httprequest.NewHTTPRequestHandler(bsh)
|
sh := httprequest.NewHTTPRequestHandler(bsh)
|
||||||
|
@ -86,7 +86,7 @@ func main() {
|
|||||||
cfg := engine.Config{
|
cfg := engine.Config{
|
||||||
Root: "root",
|
Root: "root",
|
||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(128),
|
FlagCount: uint32(16),
|
||||||
}
|
}
|
||||||
if stateDebug {
|
if stateDebug {
|
||||||
cfg.StateDebug = true
|
cfg.StateDebug = true
|
||||||
|
@ -18,17 +18,17 @@ import (
|
|||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/identity"
|
||||||
|
commonlang "git.grassecon.net/grassrootseconomics/common/lang"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/person"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/phone"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/pin"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/profile"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/profile"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
|
||||||
commonlang "git.grassecon.net/grassrootseconomics/common/lang"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/pin"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/person"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/phone"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/identity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -99,7 +99,7 @@ func NewMenuHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithPersister sets persister instance to the handlers.
|
// WithPersister sets persister instance to the handlers.
|
||||||
//func (h *MenuHandlers) WithPersister(pe *persist.Persister) *MenuHandlers {
|
// func (h *MenuHandlers) WithPersister(pe *persist.Persister) *MenuHandlers {
|
||||||
func (h *MenuHandlers) SetPersister(pe *persist.Persister) {
|
func (h *MenuHandlers) SetPersister(pe *persist.Persister) {
|
||||||
if h.pe != nil {
|
if h.pe != nil {
|
||||||
panic("persister already set")
|
panic("persister already set")
|
||||||
@ -108,7 +108,6 @@ func (h *MenuHandlers) SetPersister(pe *persist.Persister) {
|
|||||||
//return h
|
//return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Init initializes the handler for a new session.
|
// Init initializes the handler for a new session.
|
||||||
func (h *MenuHandlers) Init(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) Init(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var r resource.Result
|
var r resource.Result
|
||||||
@ -156,6 +155,77 @@ func (h *MenuHandlers) Exit() {
|
|||||||
h.pe = nil
|
h.pe = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAccountFlags queries the storage to check if the data exits
|
||||||
|
// it then sets the required flags to prevent a registered user from registering afresh
|
||||||
|
func (h *MenuHandlers) SetAccountFlags(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
|
||||||
|
flag_language_set, _ := h.flagManager.GetFlag("flag_language_set")
|
||||||
|
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
||||||
|
flag_account_blocked, _ := h.flagManager.GetFlag("flag_account_blocked")
|
||||||
|
flag_pin_set, _ := h.flagManager.GetFlag("flag_pin_set")
|
||||||
|
|
||||||
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("missing session")
|
||||||
|
}
|
||||||
|
|
||||||
|
store := h.userdataStore
|
||||||
|
|
||||||
|
// check account creation status
|
||||||
|
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_account_created)
|
||||||
|
|
||||||
|
// check language status
|
||||||
|
code, err := store.ReadEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read language code entry with", "key", storedb.DATA_INITIAL_LANGUAGE_CODE, "error", err)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
codeStr := string(code)
|
||||||
|
|
||||||
|
// fallback for unsupported languages
|
||||||
|
if codeStr != "eng" && codeStr != "swa" {
|
||||||
|
codeStr = "swa"
|
||||||
|
}
|
||||||
|
|
||||||
|
res.Content = codeStr
|
||||||
|
|
||||||
|
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_language_set)
|
||||||
|
|
||||||
|
// check if the account is guarded by a PIN
|
||||||
|
_, err = store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read account PIN entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_pin_set)
|
||||||
|
|
||||||
|
// check PIN attempts
|
||||||
|
currentWrongPinAttempts, err := store.ReadEntry(ctx, sessionId, storedb.DATA_INCORRECT_PIN_ATTEMPTS)
|
||||||
|
if err != nil {
|
||||||
|
if !db.IsNotFound(err) {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pinAttemptsValue, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64)
|
||||||
|
remainingPINAttempts := pin.AllowedPINAttempts - uint8(pinAttemptsValue)
|
||||||
|
if remainingPINAttempts == 0 {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_account_blocked)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetLanguage sets the language across the menu.
|
// SetLanguage sets the language across the menu.
|
||||||
func (h *MenuHandlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
@ -75,6 +75,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
|||||||
}
|
}
|
||||||
//appHandlers = appHandlers.WithPersister(ls.Pe)
|
//appHandlers = appHandlers.WithPersister(ls.Pe)
|
||||||
appHandlers.SetPersister(ls.Pe)
|
appHandlers.SetPersister(ls.Pe)
|
||||||
|
ls.DbRs.AddLocalFunc("set_account_flags", appHandlers.SetAccountFlags)
|
||||||
ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage)
|
ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage)
|
||||||
ls.DbRs.AddLocalFunc("create_account", appHandlers.CreateAccount)
|
ls.DbRs.AddLocalFunc("create_account", appHandlers.CreateAccount)
|
||||||
ls.DbRs.AddLocalFunc("save_temporary_pin", appHandlers.SaveTemporaryPin)
|
ls.DbRs.AddLocalFunc("save_temporary_pin", appHandlers.SaveTemporaryPin)
|
||||||
|
@ -1 +1 @@
|
|||||||
Your account is still being created. For more help, please call: 0757628885
|
Your account is still being created.
|
@ -1 +1 @@
|
|||||||
Akaunti yako bado inatengenezwa. Kwa usaidizi zaidi, piga: 0757628885
|
Akaunti yako bado inatengenezwa
|
@ -1,9 +1,10 @@
|
|||||||
|
LOAD set_account_flags 8
|
||||||
CATCH blocked_account flag_account_blocked 1
|
CATCH blocked_account flag_account_blocked 1
|
||||||
CATCH select_language flag_language_set 0
|
CATCH select_language flag_language_set 0
|
||||||
CATCH terms flag_account_created 0
|
CATCH terms flag_account_created 0
|
||||||
LOAD check_account_status 0
|
LOAD check_account_status 0
|
||||||
RELOAD check_account_status
|
RELOAD check_account_status
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
CATCH account_pending flag_account_pending 1
|
CATCH account_pending flag_account_pending 1
|
||||||
CATCH create_pin flag_pin_set 0
|
CATCH create_pin flag_pin_set 0
|
||||||
CATCH main flag_account_success 1
|
CATCH main flag_account_success 1
|
||||||
|
@ -44,8 +44,6 @@ func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId strin
|
|||||||
return fmt.Errorf("Failed to parse public key: %v", err)
|
return fmt.Errorf("Failed to parse public key: %v", err)
|
||||||
}
|
}
|
||||||
k := append([]byte{0x01}, pubKey.Marshal()...)
|
k := append([]byte{0x01}, pubKey.Marshal()...)
|
||||||
s.store.SetLanguage(nil)
|
|
||||||
s.store.SetSession("")
|
|
||||||
s.store.SetPrefix(storage.DATATYPE_EXTEND)
|
s.store.SetPrefix(storage.DATATYPE_EXTEND)
|
||||||
logg.Infof("Added key", "sessionId", sessionId, "public key", string(publicBytes))
|
logg.Infof("Added key", "sessionId", sessionId, "public key", string(publicBytes))
|
||||||
return s.store.Put(ctx, k, []byte(sessionId))
|
return s.store.Put(ctx, k, []byte(sessionId))
|
||||||
@ -53,7 +51,6 @@ func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId strin
|
|||||||
|
|
||||||
func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, error) {
|
func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, error) {
|
||||||
s.store.SetLanguage(nil)
|
s.store.SetLanguage(nil)
|
||||||
s.store.SetSession("")
|
|
||||||
s.store.SetPrefix(storage.DATATYPE_EXTEND)
|
s.store.SetPrefix(storage.DATATYPE_EXTEND)
|
||||||
k := append([]byte{0x01}, pubKey.Marshal()...)
|
k := append([]byte{0x01}, pubKey.Marshal()...)
|
||||||
v, err := s.store.Get(ctx, k)
|
v, err := s.store.Get(ctx, k)
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -180,8 +180,7 @@ func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clear up why pointer here and by-value other cmds
|
// TODO: clear up why pointer here and by-value other cmds
|
||||||
accountService := services.New(ctx, menuStorageService, s.Conn)
|
accountService := &httpremote.HTTPAccountService{}
|
||||||
|
|
||||||
hl, err := lhs.GetHandler(accountService)
|
hl, err := lhs.GetHandler(accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user