package v1 import ( "context" "git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers" "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts" ctrl "sigs.k8s.io/controller-runtime" ) func NewAccountRPCImpl(contoller ctrl.Manager) *AccountsServer { return &AccountsServer{ Controller: contoller, } } type AccountsServer struct { accounts.UnimplementedAccountsServer Controller ctrl.Manager } func (a *AccountsServer) SignUp(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) { data := controllers.AccountData{ Username: in.Data.GetName(), Password: in.AccountPassword.GetPassword(), Email: in.Data.GetEmail(), } acc := controllers.Account{ Controller: a.Controller, Data: &data, } if err := acc.Create(ctx); err != nil { return nil, err } return &accounts.AccountFullWithToken{ Id: &accounts.AccountId{ Id: acc.Data.UUID, }, Data: &accounts.AccountData{ Name: acc.Data.Username, Email: acc.Data.Email, }, Token: acc.Kubeconfig, }, nil } func (a *AccountsServer) SignIn(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) { data := controllers.AccountData{ Username: in.Data.GetName(), Password: in.AccountPassword.GetPassword(), Email: in.Data.GetEmail(), } acc := controllers.Account{ Controller: a.Controller, Data: &data, } if err := acc.Login(ctx); err != nil { return nil, err } return &accounts.AccountFullWithToken{ Id: &accounts.AccountId{ Id: acc.Data.UUID, }, Data: &accounts.AccountData{ Name: acc.Data.Username, Email: acc.Data.Email, }, Token: acc.Kubeconfig, }, nil }