2023-12-22 16:30:25 +00:00
|
|
|
package Users
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
name string
|
|
|
|
surname string
|
|
|
|
login string
|
|
|
|
password string
|
|
|
|
ownerHash interop.Hash160
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewUser(name string, surname string, login string, password string, owner interop.Hash160) {
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
|
|
|
existing_login := storage.Get(ctx, login)
|
|
|
|
if existing_login != nil {
|
|
|
|
panic("this login is taken by someone else")
|
|
|
|
}
|
|
|
|
|
|
|
|
user := User{
|
|
|
|
name: name,
|
|
|
|
surname: surname,
|
|
|
|
login: login,
|
|
|
|
password: password,
|
|
|
|
ownerHash: owner,
|
|
|
|
}
|
|
|
|
|
|
|
|
saveUser(ctx, login, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUser(ctx storage.Context, login string) User {
|
|
|
|
data := storage.Get(ctx, login)
|
|
|
|
|
|
|
|
if data == nil {
|
|
|
|
panic("User does not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
return std.Deserialize(data.([]byte)).(User)
|
|
|
|
}
|
|
|
|
|
|
|
|
func saveUser(ctx storage.Context, userLogin string, user User) {
|
2024-01-02 12:28:51 +00:00
|
|
|
storage.Put(ctx, user.ownerHash, std.Serialize(user))
|
|
|
|
storage.Put(ctx, string(user.ownerHash)+"LastPost", -1)
|
|
|
|
storage.Put(ctx, string(user.ownerHash)+"LastCom", -1)
|
2023-12-22 16:30:25 +00:00
|
|
|
}
|