Заимплементил Set в интеграции #4

Merged
glebus merged 2 commits from integration-3 into master 2024-01-14 15:56:59 +00:00

View file

@ -23,9 +23,9 @@ import (
type IBlockchainStorage interface { type IBlockchainStorage interface {
GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) // read GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) // read
Set(id string, cli oauth2.ClientInfo) (err error) // create and update Set(clt oauth2.ClientInfo) error // create and update
Delete(id string) (err error) // delete Delete(id string) error // delete
CheckPassword(id string, secret util.Uint256) (bool, error) // CheckUser CheckPassword(id string, secret string) (bool, error) // CheckUser
} }
type BlockchainStorage struct { type BlockchainStorage struct {
@ -33,8 +33,8 @@ type BlockchainStorage struct {
} }
type StorageClientInfo struct { type StorageClientInfo struct {
login string id string
password util.Uint256 secret string
} }
func NewBlockchainStorage(actor Actor, hash util.Uint160) *BlockchainStorage { func NewBlockchainStorage(actor Actor, hash util.Uint160) *BlockchainStorage {
@ -47,21 +47,40 @@ func (storage BlockchainStorage) GetByID(ctx context.Context, id string) (oauth2
return nil, err return nil, err
} }
return &StorageClientInfo{login: id, password: password}, nil return &StorageClientInfo{id: id, secret: password.StringLE()}, nil
} }
func (storage BlockchainStorage) Set(id string, cli oauth2.ClientInfo) (err error) { func (storage BlockchainStorage) Set(clt oauth2.ClientInfo) error {
// how to check whether user exists? (util.Uint256 conversion) password, decodeErr := util.Uint256DecodeStringLE(clt.GetSecret())
if decodeErr != nil {
return decodeErr
} }
func (storage BlockchainStorage) Delete(id string) (err error) { _, _, err := storage.contract.UpdateUser(clt.GetID(), password)
// how to use hash and ValidUntilBlock? if err != nil {
_, _, err = storage.contract.DeleteUser(id) _, _, err = storage.contract.CreateUser(clt.GetID(), password)
return err
if err != nil {
return errors.New("Something went wrong")
}
} }
func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (bool, error) { return nil
_, err := storage.contract.CheckUser(id, secret) }
func (storage BlockchainStorage) Delete(id string) error {
// should we use hash and ValidUntilBlock?
_, _, res := storage.contract.DeleteUser(id)
return res
}
func (storage BlockchainStorage) CheckPassword(id string, secret string) (bool, error) {
password, decodeErr := util.Uint256DecodeStringLE(secret)
if decodeErr != nil {
return false, decodeErr
}
_, err := storage.contract.CheckUser(id, password)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -70,11 +89,11 @@ func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (
} }
func (model StorageClientInfo) GetID() string { func (model StorageClientInfo) GetID() string {
return model.login return model.id
} }
func (model StorageClientInfo) GetSecret() string { func (model StorageClientInfo) GetSecret() string {
return model.password.String() return model.secret
} }
func (model StorageClientInfo) GetDomain() string { func (model StorageClientInfo) GetDomain() string {