wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
14 changed files with 87 additions and 3 deletions
Showing only changes of commit f50be01b89 - Show all commits

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"flag" "flag"
@ -29,6 +30,9 @@ const (
USERFLAG_INCORRECTPIN USERFLAG_INCORRECTPIN
USERFLAG_UNLOCKFORUPDATE USERFLAG_UNLOCKFORUPDATE
USERFLAG_INVALID_AMOUNT USERFLAG_INVALID_AMOUNT
USERFLAG_QUERYPIN
USERFLAG_VALIDPIN
USERFLAG_INVALIDPIN
) )
const ( const (
@ -551,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")
) )
@ -612,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)

View File

@ -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

View File

@ -0,0 +1 @@
Enter your four number PIN again:

View File

@ -0,0 +1,4 @@
LOAD save_pin 0
HALT
LOAD verify_pin 8
INCMP account_creation *

View File

@ -0,0 +1 @@
Weka PIN yako tena:

View File

@ -0,0 +1 @@
Please enter a new four number PIN for your account:

View File

@ -0,0 +1,5 @@
LOAD create_account 0
MOUT exit 0
HALT
LOAD save_pin 0
INCMP confirm_create_pin *

View File

@ -0,0 +1 @@
The PIN is not a match. Try again

View File

@ -0,0 +1,5 @@
MOUT retry 1
MOUT quit 9
HALT
INCMP confirm_create_pin 1
INCMP quit 9
Alfred-mk marked this conversation as resolved
Review

if quit is chosen, next time the vm is started, the pin creation is never resumed, it just goes directly to main menu. It should prompt for setting pin again.

if quit is chosen, next time the vm is started, the pin creation is never resumed, it just goes directly to main menu. It should prompt for setting pin again.

View File

@ -0,0 +1 @@
PIN uliyoweka haifanani. Jaribu tena

View File

@ -0,0 +1 @@
Tafadhali weka PIN mpya yenye nambari nne kwa akaunti yako:

View File

@ -0,0 +1 @@
Exit

View File

@ -0,0 +1 @@
Ondoka

View File

@ -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 _ *