wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
Showing only changes of commit 730c92c284 - Show all commits

View File

@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"regexp"
"time" "time"
"git.defalsify.org/vise.git/cache" "git.defalsify.org/vise.git/cache"
@ -34,6 +35,7 @@ const (
USERFLAG_QUERYPIN USERFLAG_QUERYPIN
USERFLAG_VALIDPIN USERFLAG_VALIDPIN
USERFLAG_INVALIDPIN USERFLAG_INVALIDPIN
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

please rename this flag to USERFLAG_PINMISMATCH to avoid ambiguity.

please rename this flag to USERFLAG_PINMISMATCH to avoid ambiguity.
Outdated
Review

priority

**priority**
USERFLAG_INCORRECTDATEFORMAT
) )
const ( const (
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

Please can we have all the http stuff in a separate package?

  • urls
  • responses
  • gets
Please can we have all the http stuff in a separate package? * urls * responses * gets
@ -87,7 +89,7 @@ func codeFromCtx(ctx context.Context) string {
return code return code
} }
func (fsd *fsData) saveFirstName(cxt context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_firstname(cxt context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -118,7 +120,7 @@ func (fsd *fsData) saveFirstName(cxt context.Context, sym string, input []byte)
return res, nil return res, nil
} }
func (fsd *fsData) saveFamilyName(cxt context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_familyname(cxt context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -149,7 +151,7 @@ func (fsd *fsData) saveFamilyName(cxt context.Context, sym string, input []byte)
return res, nil return res, nil
} }
func (fsd *fsData) saveYOB(cxt context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_yob(cxt context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
jsonData, err := os.ReadFile(fp) jsonData, err := os.ReadFile(fp)
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

This code is repeated many times. Could we please abstract the json fs part of the get and set to a module implementing an interface with Get and Put?

This code is repeated many times. Could we please abstract the json fs part of the get and set to a module implementing an interface with `Get` and `Put`?
@ -178,7 +180,7 @@ func (fsd *fsData) saveYOB(cxt context.Context, sym string, input []byte) (resou
return res, nil return res, nil
} }
func (fsd *fsData) saveLocation(cxt context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_location(cxt context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
jsonData, err := os.ReadFile(fp) jsonData, err := os.ReadFile(fp)
@ -208,7 +210,7 @@ func (fsd *fsData) saveLocation(cxt context.Context, sym string, input []byte) (
return res, nil return res, nil
} }
func (fsd *fsData) saveGender(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_gender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
jsonData, err := os.ReadFile(fp) jsonData, err := os.ReadFile(fp)
@ -231,7 +233,6 @@ func (fsd *fsData) saveGender(ctx context.Context, sym string, input []byte) (re
case "3": case "3":
gender = "Other" gender = "Other"
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

is this a choice in the current ussd?

is this a choice in the current ussd?

Yes, the current USSD has the option of updating the gender, and the options are Male, Female and Other

Yes, the current USSD has the option of updating the gender, and the options are Male, Female and Other
} }
fmt.Println("gender", gender)
accountData["Gender"] = gender accountData["Gender"] = gender
updatedJsonData, err := json.Marshal(accountData) updatedJsonData, err := json.Marshal(accountData)
if err != nil { if err != nil {
@ -246,7 +247,7 @@ func (fsd *fsData) saveGender(ctx context.Context, sym string, input []byte) (re
return res, nil return res, nil
} }
func (fsd *fsData) saveOfferings(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) save_offerings(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
jsonData, err := os.ReadFile(fp) jsonData, err := os.ReadFile(fp)
@ -273,7 +274,7 @@ func (fsd *fsData) saveOfferings(ctx context.Context, sym string, input []byte)
return res, nil return res, nil
} }
func (fsd *fsData) SetLanguageSelected(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) set_language(ctx context.Context, sym string, input []byte) (resource.Result, error) {
inputStr := string(input) inputStr := string(input)
res := resource.Result{} res := resource.Result{}
switch inputStr { switch inputStr {
@ -327,19 +328,19 @@ func (fsd *fsData) create_account(ctx context.Context, sym string, input []byte)
return res, err return res, err
} }
func (fsd *fsData) resetUnlockForUpdate(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) reset_unlock_for_update(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
res.FlagReset = append(res.FlagReset, USERFLAG_UNLOCKFORUPDATE) res.FlagReset = append(res.FlagReset, USERFLAG_UNLOCKFORUPDATE)
return res, nil return res, nil
} }
func (fsd *fsData) resetAccountUnlocked(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) reset_account_unlocked(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED) res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
return res, nil return res, nil
} }
func (fsd *fsData) checkIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) check_identifier(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -359,7 +360,7 @@ func (fsd *fsData) checkIdentifier(ctx context.Context, sym string, input []byte
return res, nil return res, nil
} }
func (fsd *fsData) unLock(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) unlock(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
pin := string(input) pin := string(input)
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -382,6 +383,8 @@ func (fsd *fsData) unLock(ctx context.Context, sym string, input []byte) (resour
return res, nil return res, nil
} }
if fsd.st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED, false) { if fsd.st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED, false) {
res.FlagReset = append(res.FlagReset, USERFLAG_INCORRECTPIN)
res.FlagSet = append(res.FlagSet, USERFLAG_UNLOCKFORUPDATE)
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_UNLOCKED) res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_UNLOCKED)
} else { } else {
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED) res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
@ -390,7 +393,7 @@ func (fsd *fsData) unLock(ctx context.Context, sym string, input []byte) (resour
return res, nil return res, nil
} }
func (fsd *fsData) ResetIncorrectPin(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) reset_incorrect_pin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
isIncorrectPinSet := fsd.st.MatchFlag(USERFLAG_INCORRECTPIN, true) isIncorrectPinSet := fsd.st.MatchFlag(USERFLAG_INCORRECTPIN, true)
if isIncorrectPinSet { if isIncorrectPinSet {
@ -401,10 +404,7 @@ func (fsd *fsData) ResetIncorrectPin(ctx context.Context, sym string, input []by
return res, nil return res, nil
} }
func (fsd *fsData) ShowUpdateSuccess(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
return res, nil
}
func (fsd *fsData) check_account_status(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) check_account_status(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
@ -507,7 +507,28 @@ func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resource
return res, nil return res, nil
} }
func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) verify_yob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
date := string(input)
dateRegex := regexp.MustCompile(`^\d{2}/\d{2}/\d{4}$`)
isCorrectFormat := dateRegex.MatchString(date)
if !isCorrectFormat {
res.FlagSet = append(res.FlagSet, USERFLAG_INCORRECTDATEFORMAT)
} else {
res.FlagReset = append(res.FlagReset, USERFLAG_INCORRECTDATEFORMAT)
}
return res, nil
}
func (fsd *fsData) reser_incorrect_yob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
res.FlagReset = append(res.FlagReset, USERFLAG_INCORRECTDATEFORMAT)
return res, nil
}
func (fsd *fsData) check_balance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -730,7 +751,7 @@ func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte)
return res, nil return res, nil
} }
func (fsd *fsData) getProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) get_profile_info(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -775,7 +796,7 @@ func (fsd *fsData) get_sender(ctx context.Context, sym string, input []byte) (re
return res, nil return res, nil
} }
func (fsd *fsData) quitWithBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) quit_with_balance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -926,15 +947,15 @@ func main() {
path: fp, path: fp,
st: &st, st: &st,
} }
rfs.AddLocalFunc("select_language", fs.SetLanguageSelected) rfs.AddLocalFunc("select_language", fs.set_language)
rfs.AddLocalFunc("create_account", fs.create_account) rfs.AddLocalFunc("create_account", fs.create_account)
rfs.AddLocalFunc("save_pin", fs.save_pin) rfs.AddLocalFunc("save_pin", fs.save_pin)
rfs.AddLocalFunc("verify_pin", fs.verify_pin) rfs.AddLocalFunc("verify_pin", fs.verify_pin)
rfs.AddLocalFunc("check_identifier", fs.checkIdentifier) rfs.AddLocalFunc("check_identifier", fs.check_identifier)
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)
rfs.AddLocalFunc("quit", fs.quit) rfs.AddLocalFunc("quit", fs.quit)
rfs.AddLocalFunc("check_balance", fs.checkBalance) rfs.AddLocalFunc("check_balance", fs.check_balance)
rfs.AddLocalFunc("validate_recipient", fs.validate_recipient) rfs.AddLocalFunc("validate_recipient", fs.validate_recipient)
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)
@ -942,18 +963,19 @@ func main() {
rfs.AddLocalFunc("reset_transaction_amount", fs.reset_transaction_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.reset_incorrect_pin)
rfs.AddLocalFunc("save_firstname", fs.saveFirstName) rfs.AddLocalFunc("save_firstname", fs.save_firstname)
rfs.AddLocalFunc("save_familyname", fs.saveFamilyName) rfs.AddLocalFunc("save_familyname", fs.save_familyname)
rfs.AddLocalFunc("save_gender", fs.saveGender) rfs.AddLocalFunc("save_gender", fs.save_gender)
rfs.AddLocalFunc("save_location", fs.saveLocation) rfs.AddLocalFunc("save_location", fs.save_location)
rfs.AddLocalFunc("save_yob", fs.saveYOB) rfs.AddLocalFunc("save_yob", fs.save_yob)
rfs.AddLocalFunc("save_offerings", fs.saveOfferings) rfs.AddLocalFunc("save_offerings", fs.save_offerings)
rfs.AddLocalFunc("quit_with_balance", fs.quitWithBalance) rfs.AddLocalFunc("quit_with_balance", fs.quit_with_balance)
rfs.AddLocalFunc("show_update_success", fs.ShowUpdateSuccess) rfs.AddLocalFunc("reset_unlocked", fs.reset_account_unlocked)
rfs.AddLocalFunc("reset_unlocked", fs.resetAccountUnlocked) rfs.AddLocalFunc("reset_unlock_for_update", fs.reset_unlock_for_update)
rfs.AddLocalFunc("reset_unlock_for_update", fs.resetUnlockForUpdate) rfs.AddLocalFunc("get_profile_info", fs.get_profile_info)
rfs.AddLocalFunc("get_profile_info", fs.getProfileInfo) rfs.AddLocalFunc("verify_yob", fs.verify_yob)
rfs.AddLocalFunc("reset_incorrect_date_format", fs.reser_incorrect_yob)
cont, err := en.Init(ctx) cont, err := en.Init(ctx)
en.SetDebugger(engine.NewSimpleDebug(nil)) en.SetDebugger(engine.NewSimpleDebug(nil))