69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
|
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/email"
|
|
"gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func NewAccountRPCImpl(db *sql.DB, hashCost int16, email *email.EmailConf, devMode bool) *AccountsServer {
|
|
return &AccountsServer{
|
|
Params: &controllers.AccountParams{
|
|
HashCost: hashCost,
|
|
},
|
|
SQLDriver: db,
|
|
emailConfig: *email,
|
|
devMode: devMode,
|
|
}
|
|
}
|
|
|
|
type AccountsServer struct {
|
|
accounts.UnimplementedAccountsServer
|
|
Params *controllers.AccountParams
|
|
SQLDriver *sql.DB
|
|
emailConfig email.EmailConf
|
|
// When dev mode is enabled, email won't be sent, instead the code will be returned in metadata
|
|
devMode bool
|
|
}
|
|
|
|
func (a *AccountsServer) SignUp(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) {
|
|
accountCtrl := controllers.AccountController{
|
|
Params: controllers.AccountParams{
|
|
HashCost: a.Params.HashCost,
|
|
},
|
|
DB: a.SQLDriver,
|
|
DevMode: a.devMode,
|
|
}
|
|
|
|
if err := accountCtrl.Create(ctx, &controllers.AccountData{
|
|
Username: in.Data.GetName(),
|
|
Password: in.Password.GetPassword(),
|
|
Email: in.Data.GetEmail(),
|
|
}); err != nil {
|
|
return nil, status.Error(codes.Aborted, "Couldn't create a user")
|
|
}
|
|
return &accounts.AccountFullWithToken{
|
|
Id: &accounts.AccountId{},
|
|
Data: &accounts.AccountData{},
|
|
Token: "",
|
|
}, nil
|
|
}
|
|
|
|
func (a *AccountsServer) SignIn(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) {
|
|
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
|
}
|
|
|
|
func (a *AccountsServer) ResetPassword(ctx context.Context, in *accounts.AccountData) (*empty.Empty, error) {
|
|
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
|
}
|
|
|
|
func (acc *AccountsServer) NewPassword(ctx context.Context, in *accounts.AccountWithPasswordAndCode) (*empty.Empty, error) {
|
|
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
|
}
|