Заимплементил Set в интеграции #4
1 changed files with 35 additions and 16 deletions
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := storage.contract.UpdateUser(clt.GetID(), password)
|
||||||
|
if err != nil {
|
||||||
|
_, _, err = storage.contract.CreateUser(clt.GetID(), password)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Something went wrong")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage BlockchainStorage) Delete(id string) (err error) {
|
func (storage BlockchainStorage) Delete(id string) error {
|
||||||
// how to use hash and ValidUntilBlock?
|
// should we use hash and ValidUntilBlock?
|
||||||
_, _, err = storage.contract.DeleteUser(id)
|
_, _, res := storage.contract.DeleteUser(id)
|
||||||
return err
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (bool, error) {
|
func (storage BlockchainStorage) CheckPassword(id string, secret string) (bool, error) {
|
||||||
_, err := storage.contract.CheckUser(id, secret)
|
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 {
|
||||||
|
|
Loading…
Reference in a new issue