Save the actual PIN and verify it

This commit is contained in:
Alfred Kamanda 2024-09-05 19:50:02 +03:00
parent db3ec1991d
commit 17804e7641
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
2 changed files with 25 additions and 25 deletions

View File

@ -74,14 +74,6 @@ func (fm *FlagManager) GetFlag(label string) (uint32, error) {
return fm.parser.GetFlag(label) return fm.parser.GetFlag(label)
} }
// type Handlers struct {
// fs *FSData
// db *gdbm.Database
// flagManager *FlagManager
// accountFileHandler utils.AccountFileHandlerInterface
// accountService server.AccountServiceInterface
// }
type Handlers struct { type Handlers struct {
st *state.State st *state.State
ca cache.Memory ca cache.Memory
@ -187,6 +179,10 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
// SavePin persists the user's PIN choice into the filesystem // SavePin persists the user's PIN choice into the filesystem
func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
sessionId, ok := ctx.Value("SessionId").(string)
if !ok {
return res, fmt.Errorf("missing session")
}
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin") flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
@ -199,10 +195,11 @@ func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resou
res.FlagReset = append(res.FlagReset, flag_incorrect_pin) res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
// key := []byte(AccountPin) err := utils.WriteEntry(ctx, h.userdataStore, sessionId, utils.DATA_ACCOUNT_PIN, []byte(accountPIN))
// value := []byte(accountPIN) if err != nil {
return res, nil
}
//h.db.Store(key, value, true)
return res, nil return res, nil
} }
@ -241,11 +238,13 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch") flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
flag_pin_set, _ := h.flagManager.GetFlag("flag_pin_set") flag_pin_set, _ := h.flagManager.GetFlag("flag_pin_set")
// AccountPin, err := h.db.Fetch([]byte(AccountPin)) sessionId, ok := ctx.Value("SessionId").(string)
// if err != nil { if !ok {
// return res, err return res, fmt.Errorf("missing session")
// } }
AccountPin := []byte("2768")
AccountPin, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_ACCOUNT_PIN)
if bytes.Equal(input, AccountPin) { if bytes.Equal(input, AccountPin) {
res.FlagSet = []uint32{flag_valid_pin} res.FlagSet = []uint32{flag_valid_pin}
res.FlagReset = []uint32{flag_pin_mismatch} res.FlagReset = []uint32{flag_pin_mismatch}
@ -441,10 +440,9 @@ func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []b
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
trackingId, err := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_TRACKING_ID) trackingId, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_TRACKING_ID)
fmt.Println("Checking status with tracking id:", string(trackingId))
status, err := h.accountService.CheckAccountStatus(string("1234")) status, err := h.accountService.CheckAccountStatus(string(trackingId))
if err != nil { if err != nil {
fmt.Println("Error checking account status:", err) fmt.Println("Error checking account status:", err)
@ -524,13 +522,15 @@ func (h *Handlers) ResetIncorrectYob(ctx context.Context, sym string, input []by
// the balance as the result content // the balance as the result content
func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
// publicKey, err := h.db.Fetch([]byte(PublicKeyKey))
// if err != nil { sessionId, ok := ctx.Value("SessionId").(string)
// return res, err if !ok {
// } return res, fmt.Errorf("missing session")
}
balance, err := h.accountService.CheckBalance(string("publicKey")) publicKey, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_PUBLIC_KEY)
balance, err := h.accountService.CheckBalance(string(publicKey))
if err != nil { if err != nil {
return res, nil return res, nil
} }

View File

@ -15,6 +15,7 @@ const (
DATA_TRACKING_ID DATA_TRACKING_ID
DATA_PUBLIC_KEY DATA_PUBLIC_KEY
DATA_CUSTODIAL_ID DATA_CUSTODIAL_ID
DATA_ACCOUNT_PIN
) )
func typToBytes(typ DataTyp) []byte { func typToBytes(typ DataTyp) []byte {
@ -37,7 +38,6 @@ func ReadEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp)
return nil, err return nil, err
} }
return b, nil return b, nil
} }
func WriteEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp, value []byte) error { func WriteEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp, value []byte) error {